huggingface/transformers · error · ValueError

Argument `{}` is not a valid argument of `GenerationConfig`.

Error message

Argument `{}` is not a valid argument of `GenerationConfig`. It should be passed to `generate()` (or a pipeline) directly.

What it means

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.

Source

Thrown at src/transformers/generation/configuration_utils.py:843

                    minor_issues[extra_output_flag] = (
                        f"`return_dict_in_generate` is NOT set to `True`, but `{extra_output_flag}` is. When "
                        f"`return_dict_in_generate` is not `True`, `{extra_output_flag}` is ignored."
                    )

        # 3. Check common issue: passing `generate` arguments inside the generation config
        generate_arguments = (
            "logits_processor",
            "stopping_criteria",
            "prefix_allowed_tokens_fn",
            "synced_gpus",
            "assistant_model",
            "streamer",
            "negative_prompt_ids",
            "negative_prompt_attention_mask",
        )
        for arg in generate_arguments:
            if hasattr(self, arg):
                raise ValueError(
                    f"Argument `{arg}` is not a valid argument of `GenerationConfig`. It should be passed to "
                    "`generate()` (or a pipeline) directly."
                )

        # Finally, handle caught minor issues. With default parameterization, we will throw a minimal warning.
        if len(minor_issues) > 0:
            # Full list of issues with potential fixes
            info_message = []
            for attribute_name, issue_description in minor_issues.items():
                info_message.append(f"- `{attribute_name}`: {issue_description}")
            info_message = "\n".join(info_message)
            info_message += (
                "\nIf you're using a pretrained model, note that some of these attributes may be set through the "
                "model's `generation_config.json` file."
            )

            if strict:
                raise ValueError("GenerationConfig is invalid: \n" + info_message)

View on GitHub (pinned to a597f97485)

Solutions

  1. Remove the argument from the GenerationConfig constructor and pass it directly to model.generate(...)
  2. If it was set as an attribute, delete it: delattr(model.generation_config, 'streamer') or set it to None before validation
  3. Audit wrapper code that forwards **kwargs to both GenerationConfig and generate(); split the kwargs into config kwargs vs generate kwargs

Example fix

# before
cfg = GenerationConfig(synced_gpus=True)
model.generate(**inputs, generation_config=cfg)
# after
out = model.generate(**inputs, synced_gpus=True)
Defensive patterns

Strategy: validation

Validate before calling

GENERATE_ONLY = {'logits_processor','stopping_criteria','prefix_allowed_tokens_fn','synced_gpus','assistant_model','streamer','negative_prompt_ids','negative_prompt_attention_mask'}
bad = GENERATE_ONLY & set(generation_kwargs)
if bad:
    raise TypeError(f'Pass {bad} to generate(), not GenerationConfig')

Type guard

def split_kwargs(kwargs):
    gen_only = {'logits_processor','stopping_criteria','prefix_allowed_tokens_fn','synced_gpus','assistant_model','streamer','negative_prompt_ids','negative_prompt_attention_mask'}
    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}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14). Data as JSON: /api/errors/5fba067f915406dc. Report an issue: GitHub.