huggingface/transformers · error · ValueError

GenerationConfig is invalid: {}

Error message

GenerationConfig is invalid: 
{}

What it means

Raised by GenerationConfig.validate(strict=True) when 'minor issues' accumulated during validation (e.g. sampling flags like temperature/top_p set while do_sample is False, or beam-only flags with num_beams=1) exist. In non-strict mode these only warn and the flags are ignored; strict mode (used by save_pretrained) turns them into a hard ValueError to prevent persisting a bad configuration.

Source

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

                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)
            else:
                attributes_with_issues = list(minor_issues.keys())
                warning_message = (
                    f"The following generation flags are not valid and may be ignored: {attributes_with_issues}."
                )
                if logging.get_verbosity() >= logging.WARNING:
                    warning_message += " Set `TRANSFORMERS_VERBOSITY=info` for more details."
                logger.warning_once(warning_message)
                logger.info_once(info_message)

    def save_pretrained(
        self,
        save_directory: str | os.PathLike,
        config_file_name: str | os.PathLike | None = None,
        push_to_hub: bool = False,
        **kwargs,
    ):
        r"""

View on GitHub (pinned to a597f97485)

Solutions

  1. Read the listed per-attribute issues in the message and either remove the stale flags or set the enabling flag (e.g. do_sample=True for temperature/top_p, num_beams>1 for length_penalty)
  2. Reset to clean defaults: model.generation_config = GenerationConfig() then set only the flags you need
  3. If you intentionally want the flags ignored, remove them before saving — do not save a config that only works with warnings suppressed

Example fix

# before
cfg = GenerationConfig(do_sample=False, temperature=0.8)
cfg.save_pretrained('./out')  # raises
# after
cfg = GenerationConfig(do_sample=True, temperature=0.8)
cfg.save_pretrained('./out')
Defensive patterns

Strategy: validation

Validate before calling

try:
    model.generation_config.validate(strict=True)
except ValueError as e:
    print(e)  # inspect and fix listed attributes before proceeding

Try / catch

try:
    cfg.validate()
except ValueError as e:
    if 'GenerationConfig is invalid' in str(e):
        # log and fall back to sanitized defaults
        cfg = GenerationConfig()

Prevention

When it happens

Trigger: generation_config.save_pretrained(dir) with temperature/top_p/top_k set but do_sample=False; validate(is_init=True) on GenerationConfig(**kwargs) with contradictory flags; validate(strict=True) called explicitly.

Common situations: Editing a generation_config.json by hand and leaving stale sampling parameters; models shipped with legacy configs that mix sampling and greedy flags; CI that saves tuned configs.

Related errors


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