{"record":{"id":"3cba91d1e123fcda","repo":"huggingface/transformers","slug":"fix-these-issues-to-save-the-configuration","errorCode":null,"errorMessage":"{}\n\nFix these issues to save the configuration.","messagePattern":"(.+?)\n\nFix these issues to save the configuration\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/generation/configuration_utils.py","lineNumber":902,"sourceCode":"            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            config_file_name (`str` or `os.PathLike`, *optional*, defaults to `\"generation_config.json\"`):\n                Name of the generation configuration JSON file to be saved in `save_directory`.\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\n        # At save time, validate the instance enforcing strictness -- if any warning/exception would be thrown, we\n        # refuse to save the instance.\n        # This strictness is enforced to prevent bad configurations from being saved and re-used.\n        try:\n            self.validate(strict=True)\n        except ValueError as exc:\n            raise ValueError(str(exc) + \"\\n\\nFix these issues to save the configuration.\")\n\n        config_file_name = config_file_name if config_file_name is not None else GENERATION_CONFIG_NAME\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        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\", str(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        output_config_file = os.path.join(save_directory, config_file_name)\n\n        self.to_json_file(output_config_file, use_diff=True, keys_to_pop=[\"compile_config\"])\n        logger.info(f\"Configuration saved in {output_config_file}\")","sourceCodeStart":884,"sourceCodeEnd":920,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/configuration_utils.py#L884-L920","documentation":"Wrapping error from GenerationConfig.save_pretrained(): the strict validate(strict=True) call raised (same conditions as 'GenerationConfig is invalid'), and the ValueError is re-raised with an appended 'Fix these issues to save the configuration.' so the user knows saving was blocked, not just validation. The strictness exists to stop bad configurations from being persisted and later reloaded.","triggerScenarios":"model.generation_config.save_pretrained('/dir') or model.save_pretrained() (which saves generation_config.json) while the config has minor issues such as sampling flags without do_sample=True.","commonSituations":"Fine-tuning then saving a model whose inherited generation_config.json has contradictory flags; scripting model export where the failure surfaces only at save time.","solutions":["Fix the underlying issues listed in the wrapped message (see the 'GenerationConfig is invalid' entry)","As a quick cleanup, reset the config to defaults and re-apply only intended flags before saving","Run generation_config.validate() manually before saving to get the same diagnostics without the save attempt"],"exampleFix":"# before\nmodel.generation_config.temperature = 0.9  # do_sample still False\nmodel.save_pretrained('./model')\n# after\nmodel.generation_config.do_sample = True\nmodel.save_pretrained('./model')","handlingStrategy":"validation","validationCode":"model.generation_config.validate(strict=True)  # run before save; fix reported issues","typeGuard":null,"tryCatchPattern":"try:\n    model.generation_config.save_pretrained(out_dir)\nexcept ValueError as e:\n    if 'Fix these issues' in str(e):\n        model.generation_config = GenerationConfig.from_dict(\n            {k: v for k, v in model.generation_config.to_dict().items() if k in GenerationConfig().to_dict()})\n        model.generation_config.save_pretrained(out_dir)\n    else:\n        raise","preventionTips":["Validate strict before saving in your export scripts","Treat save-time failures as config bugs, not save bugs — fix the listed attributes"],"tags":["generation-config","save","validation"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}