{"record":{"id":"5fba067f915406dc","repo":"huggingface/transformers","slug":"argument-is-not-a-valid-argument-of-generati","errorCode":null,"errorMessage":"Argument `{}` is not a valid argument of `GenerationConfig`. It should be passed to `generate()` (or a pipeline) directly.","messagePattern":"Argument `(.+?)` is not a valid argument of `GenerationConfig`\\. It should be passed to `generate\\(\\)` \\(or a pipeline\\) directly\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/generation/configuration_utils.py","lineNumber":843,"sourceCode":"                    minor_issues[extra_output_flag] = (\n                        f\"`return_dict_in_generate` is NOT set to `True`, but `{extra_output_flag}` is. When \"\n                        f\"`return_dict_in_generate` is not `True`, `{extra_output_flag}` is ignored.\"\n                    )\n\n        # 3. Check common issue: passing `generate` arguments inside the generation config\n        generate_arguments = (\n            \"logits_processor\",\n            \"stopping_criteria\",\n            \"prefix_allowed_tokens_fn\",\n            \"synced_gpus\",\n            \"assistant_model\",\n            \"streamer\",\n            \"negative_prompt_ids\",\n            \"negative_prompt_attention_mask\",\n        )\n        for arg in generate_arguments:\n            if hasattr(self, arg):\n                raise ValueError(\n                    f\"Argument `{arg}` is not a valid argument of `GenerationConfig`. It should be passed to \"\n                    \"`generate()` (or a pipeline) directly.\"\n                )\n\n        # Finally, handle caught minor issues. With default parameterization, we will throw a minimal warning.\n        if len(minor_issues) > 0:\n            # Full list of issues with potential fixes\n            info_message = []\n            for attribute_name, issue_description in minor_issues.items():\n                info_message.append(f\"- `{attribute_name}`: {issue_description}\")\n            info_message = \"\\n\".join(info_message)\n            info_message += (\n                \"\\nIf you're using a pretrained model, note that some of these attributes may be set through the \"\n                \"model's `generation_config.json` file.\"\n            )\n\n            if strict:\n                raise ValueError(\"GenerationConfig is invalid: \\n\" + info_message)","sourceCodeStart":825,"sourceCodeEnd":861,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/configuration_utils.py#L825-L861","documentation":"Raised by GenerationConfig.validate() when a GenerationConfig instance carries one of the generate()-only arguments: logits_processor, stopping_criteria, prefix_allowed_tokens_fn, synced_gpus, assistant_model, streamer, negative_prompt_ids, negative_prompt_attention_mask. These are runtime objects (callables, models, generators) that do not belong in a serializable config, so their presence is treated as API misuse.","triggerScenarios":"GenerationConfig(streamer=...) or generation_config.stopping_criteria = [...] ; passing generate()-scoped kwargs through a pipeline that forwards them into the config; setting attributes on model.generation_config that are generate() parameters.","commonSituations":"Building 'one config object with everything' for generate(); a wrapper class that dumps **generate_kwargs into GenerationConfig(**kwargs); older tutorials that set synced_gpus on the config.","solutions":["Remove the argument from the GenerationConfig constructor and pass it directly to model.generate(...)","If it was set as an attribute, delete it: delattr(model.generation_config, 'streamer') or set it to None before validation","Audit wrapper code that forwards **kwargs to both GenerationConfig and generate(); split the kwargs into config kwargs vs generate kwargs"],"exampleFix":"# before\ncfg = GenerationConfig(synced_gpus=True)\nmodel.generate(**inputs, generation_config=cfg)\n# after\nout = model.generate(**inputs, synced_gpus=True)","handlingStrategy":"validation","validationCode":"GENERATE_ONLY = {'logits_processor','stopping_criteria','prefix_allowed_tokens_fn','synced_gpus','assistant_model','streamer','negative_prompt_ids','negative_prompt_attention_mask'}\nbad = GENERATE_ONLY & set(generation_kwargs)\nif bad:\n    raise TypeError(f'Pass {bad} to generate(), not GenerationConfig')","typeGuard":"def split_kwargs(kwargs):\n    gen_only = {'logits_processor','stopping_criteria','prefix_allowed_tokens_fn','synced_gpus','assistant_model','streamer','negative_prompt_ids','negative_prompt_attention_mask'}\n    return {k:v for k,v in kwargs.items() if k not in gen_only}, {k:v for k,v in kwargs.items() if k in gen_only}","tryCatchPattern":null,"preventionTips":["Never forward **kwargs blindly into GenerationConfig; keep separate dicts for config kwargs and generate() kwargs","Remember only runtime objects (streamer, assistant_model, processors) belong to generate()"],"tags":["generation-config","api-misuse","validation"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}