{"record":{"id":"20c71a4910f1cf19","repo":"huggingface/transformers","slug":"generationconfig-is-invalid","errorCode":null,"errorMessage":"GenerationConfig is invalid: \n{}","messagePattern":"GenerationConfig is invalid: \n(.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/generation/configuration_utils.py","lineNumber":861,"sourceCode":"                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)\n            else:\n                attributes_with_issues = list(minor_issues.keys())\n                warning_message = (\n                    f\"The following generation flags are not valid and may be ignored: {attributes_with_issues}.\"\n                )\n                if logging.get_verbosity() >= logging.WARNING:\n                    warning_message += \" Set `TRANSFORMERS_VERBOSITY=info` for more details.\"\n                logger.warning_once(warning_message)\n                logger.info_once(info_message)\n\n    def save_pretrained(\n        self,\n        save_directory: str | os.PathLike,\n        config_file_name: str | os.PathLike | None = None,\n        push_to_hub: bool = False,\n        **kwargs,\n    ):\n        r\"\"\"","sourceCodeStart":843,"sourceCodeEnd":879,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/configuration_utils.py#L843-L879","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["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)","Reset to clean defaults: model.generation_config = GenerationConfig() then set only the flags you need","If you intentionally want the flags ignored, remove them before saving — do not save a config that only works with warnings suppressed"],"exampleFix":"# before\ncfg = GenerationConfig(do_sample=False, temperature=0.8)\ncfg.save_pretrained('./out')  # raises\n# after\ncfg = GenerationConfig(do_sample=True, temperature=0.8)\ncfg.save_pretrained('./out')","handlingStrategy":"validation","validationCode":"try:\n    model.generation_config.validate(strict=True)\nexcept ValueError as e:\n    print(e)  # inspect and fix listed attributes before proceeding","typeGuard":null,"tryCatchPattern":"try:\n    cfg.validate()\nexcept ValueError as e:\n    if 'GenerationConfig is invalid' in str(e):\n        # log and fall back to sanitized defaults\n        cfg = GenerationConfig()","preventionTips":["Start from GenerationConfig() defaults and add only flags you actively use","Run cfg.validate(strict=True) in CI before shipping configs","When toggling do_sample or num_beams, clear unrelated flags (temperature, top_k, length_penalty)"],"tags":["generation-config","validation","save","strict-mode"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}