{"record":{"id":"079d2342ee38a899","repo":"huggingface/transformers","slug":"the-following-model-kwargs-are-not-used-by-the-m","errorCode":null,"errorMessage":"The following `model_kwargs` are not used by the model: {unused_model_args} (note: typos in the generate arguments will also show up in this list)","messagePattern":"The following `model_kwargs` are not used by the model: (.+?) \\(note: typos in the generate arguments will also show up in this list\\)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/generation/utils.py","lineNumber":1664,"sourceCode":"            if decoder is None and base_model is not None:\n                decoder = getattr(base_model, \"decoder\", None)\n\n            if decoder is not None:\n                decoder_model_args = set(inspect.signature(decoder.forward).parameters)\n                model_args |= {f\"decoder_{x}\" for x in decoder_model_args}\n\n        # TransformersKwargs are model-agnostic attention and generation arguments such as 'output_attentions'\n        for key, value in model_kwargs.items():\n            if (\n                value is not None\n                and key not in model_args\n                and key not in TransformersKwargs.__optional_keys__\n                and key != \"debug_io\"\n            ):\n                unused_model_args.append(key)\n\n        if unused_model_args:\n            raise ValueError(\n                f\"The following `model_kwargs` are not used by the model: {unused_model_args} (note: typos in the\"\n                \" generate arguments will also show up in this list)\"\n            )\n\n    def _validate_generated_length(\n        self: \"GenerativePreTrainedModel\", generation_config, input_ids_length, has_default_max_length\n    ):\n        \"\"\"Performs validation related to the resulting generated length\"\"\"\n        # 1. Max length warnings related to poor parameterization\n        if has_default_max_length and generation_config.max_new_tokens is None:\n            # 20 is the default max_length of the generation config\n            warnings.warn(\n                f\"Using the model-agnostic default `max_length` (={generation_config.max_length}) to control the \"\n                \"generation length. We recommend setting `max_new_tokens` to control the maximum length of the \"\n                \"generation.\",\n                UserWarning,\n            )\n        if input_ids_length >= generation_config.max_length:","sourceCodeStart":1646,"sourceCodeEnd":1682,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/utils.py#L1646-L1682","documentation":"After `generate` strips arguments it handles itself, every remaining kwarg must be consumed by the model's `prepare_inputs_for_generation` signature or be a known model-agnostic `TransformersKwargs` key (with a non-None value). Anything left over is reported as unused — this is the main typo/misspelling detector for generate arguments.","triggerScenarios":"`model.generate(**inputs, max_new_token=50)` (missing 's'), `temprature=0.7`, passing a model-specific argument (e.g. `pixel_values`-adjacent keys or `attention_mask=attention` typos) to a model whose `prepare_inputs_for_generation` does not accept it, or passing `'output_scores'`-style keys not in the allowed set.","commonSituations":"Typos in long generate call lists; passing decoder-only arguments to encoder-decoder models (or vice versa) whose signatures differ; kwargs meant for the tokenizer accidentally forwarded to generate; custom models with narrow `prepare_inputs_for_generation` signatures.","solutions":["Read the listed names and fix typos against the `generate` documentation (e.g. `max_new_token` -> `max_new_tokens`).","If the kwarg is model-specific, confirm this model's `prepare_inputs_for_generation` accepts it; otherwise remove it.","Split kwargs: keep generation options in the generate call and tokenizer outputs in `model_inputs`; don't splat one dict into both.","For custom models, add the parameter to `prepare_inputs_for_generation` (and to its forward path) or unset it (None values are ignored)."],"exampleFix":"# before\nout = model.generate(**inputs, max_new_token=64, temprature=0.7)\n# ValueError: `model_kwargs` not used: ['max_new_token', 'temprature']\n\n# after\nout = model.generate(**inputs, max_new_tokens=64, temperature=0.7)","handlingStrategy":"validation","validationCode":"import inspect\nvalid = set(inspect.signature(model.prepare_inputs_for_generation).parameters) | {\n    \"max_new_tokens\", \"min_new_tokens\", \"do_sample\", \"temperature\", \"top_k\", \"top_p\",\n    \"num_beams\", \"num_return_sequences\", \"repetition_penalty\", \"eos_token_id\",\n    \"pad_token_id\", \"max_length\", \"stopping_criteria\", \"output_scores\", \"return_dict_in_generate\",\n}\ntypos = [k for k in user_kwargs if k not in valid]\nif typos:\n    raise ValueError(f\"Possible typos in generate kwargs: {typos}\")","typeGuard":null,"tryCatchPattern":"try:\n    out = model.generate(**inputs, **gen_kwargs)\nexcept ValueError as e:\n    if \"not used by the model\" in str(e):\n        import re\n        unused = re.search(r\"\\[([^\\]]+)\\]\", str(e))\n        for k in [u.strip().strip(\"'\") for u in unused.group(1).split(\",\")]:\n            gen_kwargs.pop(k, None)\n        out = model.generate(**inputs, **gen_kwargs)\n    else:\n        raise","preventionTips":["Type generate kwargs explicitly or lint them against the documented argument list.","Don't splat tokenizer dicts and option dicts into one kwargs bag passed to everything.","Treat this error as a typo alarm: read the listed names first before assuming a model bug."],"tags":["generation","kwargs","typo","argument-validation"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}