{"record":{"id":"95a9b722c1fdf744","repo":"huggingface/transformers","slug":"some-generation-parameters-are-set-in-the-model-co","errorCode":null,"errorMessage":"Some generation parameters are set in the model config. These should go into `model.generation_config`as opposed to `model.config`. \nGeneration parameters found: {str(generation_parameters)}","messagePattern":"Some generation parameters are set in the model config\\. These should go into `model\\.generation_config`as opposed to `model\\.config`\\. \nGeneration parameters found: (.+?)","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/configuration_utils.py","lineNumber":574,"sourceCode":"        Save a configuration object to the directory `save_directory`, so that it can be re-loaded using the\n        [`~PreTrainedConfig.from_pretrained`] class method.\n\n        Args:\n            save_directory (`str` or `os.PathLike`):\n                Directory where the configuration JSON file will be saved (will be created if it does not exist).\n            push_to_hub (`bool`, *optional*, defaults to `False`):\n                Whether or not to push your model to the Hugging Face model hub after saving it. You can specify the\n                repository you want to push to with `repo_id` (will default to the name of `save_directory` in your\n                namespace).\n            kwargs (`dict[str, Any]`, *optional*):\n                Additional key word arguments passed along to the [`~utils.PushToHubMixin.push_to_hub`] method.\n        \"\"\"\n        if os.path.isfile(save_directory):\n            raise AssertionError(f\"Provided path ({save_directory}) should be a directory, not a file\")\n\n        generation_parameters = self._get_generation_parameters()\n        if len(generation_parameters) > 0:\n            raise ValueError(\n                \"Some generation parameters are set in the model config. These should go into `model.generation_config`\"\n                f\"as opposed to `model.config`. \\nGeneration parameters found: {str(generation_parameters)}\",\n            )\n\n        os.makedirs(save_directory, exist_ok=True)\n\n        if push_to_hub:\n            commit_message = kwargs.pop(\"commit_message\", None)\n            repo_id = kwargs.pop(\"repo_id\", save_directory.split(os.path.sep)[-1])\n            repo_id = hf_api().create_repo(repo_id, exist_ok=True, **kwargs).repo_id\n            files_timestamps = self._get_files_timestamps(save_directory)\n\n        # This attribute is important to know on load, but should not be serialized on save.\n        if \"transformers_weights\" in self:\n            delattr(self, \"transformers_weights\")\n\n        # If we have a custom config, we copy the file defining it in the folder and set the attributes so it can be\n        # loaded from the Hub.","sourceCodeStart":556,"sourceCodeEnd":592,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/configuration_utils.py#L556-L592","documentation":"Raised by PreTrainedConfig.save_pretrained (and model save_pretrained which serializes the config) when generation-related attributes (e.g. temperature, top_k, max_length) are found on model.config. Since Transformers v5, generation parameters must live on model.generation_config; the config file itself is required to be free of them. The error lists exactly which parameters leaked into the config.","triggerScenarios":"Calling config.save_pretrained(...) or model.save_pretrained(...) / model.push_to_hub() on a config that has generation kwargs set, e.g. GPT2Config(temperature=0.7, top_k=50) or loading an old checkpoint whose config.json still contains generation keys and re-saving it.","commonSituations":"Migrating a repo or checkpoint from Transformers v4 to v5 where old config.json files carry generation fields; passing from_pretrained(..., temperature=...) style kwargs that end up on config; code that sets model.config.max_length directly.","solutions":["Move the offending parameters to model.generation_config (e.g. model.generation_config.temperature = 0.7) and delete them from config (delattr(config, 'temperature')).","When loading old checkpoints, set the generation params via AutoConfig/AutoModelForCausalLM.from_pretrained(..., generation_config=GenerationConfig(...)) instead of through config kwargs.","Regenerate the config.json of legacy checkpoints: load it, strip generation keys listed in the error message, and re-save."],"exampleFix":"// before\nconfig = GPT2Config(temperature=0.7, top_k=50)\nmodel.save_pretrained(\"out\")  # ValueError\n\n// after\nconfig = GPT2Config()\nmodel.save_pretrained(\"out\", generation_config=GenerationConfig(temperature=0.7, top_k=50))","handlingStrategy":"validation","validationCode":"from transformers import GenerationConfig\nGEN_PARAMS = {\"temperature\", \"top_k\", \"top_p\", \"max_length\", \"do_sample\", \"num_beams\"}\nleaked = [k for k in model.config.to_dict() if k in GenerationConfig().to_dict() and k not in (\"transformers_version\",)]\nif leaked:\n    for k in leaked:\n        setattr(model.generation_config, k, getattr(model.config, k))\n        delattr(model.config, k)","typeGuard":"def config_is_generation_clean(config) -> bool:\n    return len(config._get_generation_parameters()) == 0","tryCatchPattern":"try:\n    model.save_pretrained(out_dir)\nexcept ValueError as e:\n    if \"generation parameters\" in str(e).lower():\n        # move listed params to model.generation_config and retry\n        raise","preventionTips":["Never set generation kwargs through model config constructors; always pass generation_config to save_pretrained or assign to model.generation_config.","Add a CI check that loads and re-saves canonical checkpoints with the current Transformers major version."],"tags":["config","generation","save","migration"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}