huggingface/transformers · error · ValueError
{} Fix these issues to save the configuration.
Error message
{}
Fix these issues to save the configuration. What it means
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.
Source
Thrown at src/transformers/generation/configuration_utils.py:902
save_directory (`str` or `os.PathLike`):
Directory where the configuration JSON file will be saved (will be created if it does not exist).
config_file_name (`str` or `os.PathLike`, *optional*, defaults to `"generation_config.json"`):
Name of the generation configuration JSON file to be saved in `save_directory`.
push_to_hub (`bool`, *optional*, defaults to `False`):
Whether or not to push your model to the Hugging Face model hub after saving it. You can specify the
repository you want to push to with `repo_id` (will default to the name of `save_directory` in your
namespace).
kwargs (`dict[str, Any]`, *optional*):
Additional key word arguments passed along to the [`~utils.PushToHubMixin.push_to_hub`] method.
"""
# At save time, validate the instance enforcing strictness -- if any warning/exception would be thrown, we
# refuse to save the instance.
# This strictness is enforced to prevent bad configurations from being saved and re-used.
try:
self.validate(strict=True)
except ValueError as exc:
raise ValueError(str(exc) + "\n\nFix these issues to save the configuration.")
config_file_name = config_file_name if config_file_name is not None else GENERATION_CONFIG_NAME
if os.path.isfile(save_directory):
raise AssertionError(f"Provided path ({save_directory}) should be a directory, not a file")
os.makedirs(save_directory, exist_ok=True)
if push_to_hub:
commit_message = kwargs.pop("commit_message", None)
repo_id = kwargs.pop("repo_id", str(save_directory).split(os.path.sep)[-1])
repo_id = hf_api().create_repo(repo_id, exist_ok=True, **kwargs).repo_id
files_timestamps = self._get_files_timestamps(save_directory)
output_config_file = os.path.join(save_directory, config_file_name)
self.to_json_file(output_config_file, use_diff=True, keys_to_pop=["compile_config"])
logger.info(f"Configuration saved in {output_config_file}")View on GitHub (pinned to a597f97485)
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
Example fix
# before
model.generation_config.temperature = 0.9 # do_sample still False
model.save_pretrained('./model')
# after
model.generation_config.do_sample = True
model.save_pretrained('./model') Defensive patterns
Strategy: validation
Validate before calling
model.generation_config.validate(strict=True) # run before save; fix reported issues
Try / catch
try:
model.generation_config.save_pretrained(out_dir)
except ValueError as e:
if 'Fix these issues' in str(e):
model.generation_config = GenerationConfig.from_dict(
{k: v for k, v in model.generation_config.to_dict().items() if k in GenerationConfig().to_dict()})
model.generation_config.save_pretrained(out_dir)
else:
raise Prevention
- Validate strict before saving in your export scripts
- Treat save-time failures as config bugs, not save bugs — fix the listed attributes
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- GenerationConfig is invalid: {}
- `early_stopping` must be a boolean or 'never', but is {}.
- `max_new_tokens` must be greater than 0, but is {}.
- Invalid `cache_implementation` ({}). Choose one of: {}
- Greedy methods (do_sample != True) without beam search do no
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/3cba91d1e123fcda.
Report an issue: GitHub.