huggingface/transformers · error · ValueError
`early_stopping` must be a boolean or 'never', but is {}.
Error message
`early_stopping` must be a boolean or 'never', but is {}. What it means
GenerationConfig.validate() enforces that early_stopping is one of None, True, False, or the string 'never' (the 'never' mode never stops early even if all beams are finished). Any other value — e.g. the string 'true', 1, or 'always' — is rejected because beam-search logic cannot interpret it.
Source
Thrown at src/transformers/generation/configuration_utils.py:668
of parameterization that can be detected as incorrect from the configuration instance alone.
Note that some parameters not validated here are best validated at generate runtime, as they may depend on
other inputs and/or the model, such as parameters related to the generation length.
Args:
strict (bool): If True, raise an exception for any issues found. If False, only log issues.
user_set_attributes (set[str], *optional*): Names of attributes the caller explicitly provided. When
supplied, "minor issue" warnings about conflicting flag combinations (e.g. sampling-only flags set
while `do_sample=False`) only fire if the conflicting flag is in this set -- avoiding noisy warnings
when the value was inherited from a model's default `generation_config.json`. When `None`, all set
attributes are considered user-set (backward-compatible behavior for direct `validate()` calls).
"""
minor_issues = {} # format: {attribute_name: issue_description}
# 1. Validation of individual attributes
# 1.1. Decoding attributes
if self.early_stopping not in {None, True, False, "never"}:
raise ValueError(f"`early_stopping` must be a boolean or 'never', but is {self.early_stopping}.")
if self.max_new_tokens is not None and self.max_new_tokens <= 0:
raise ValueError(f"`max_new_tokens` must be greater than 0, but is {self.max_new_tokens}.")
if self.assistant_ensemble_weight is not None and not (0.0 < self.assistant_ensemble_weight < 1.0):
raise ValueError(
f"`assistant_ensemble_weight` must be in the open interval `(0.0, 1.0)`, "
f"but is {self.assistant_ensemble_weight}. Use `None` for standard (lossless) speculative decoding."
)
if self.pad_token_id is not None and self.pad_token_id < 0:
minor_issues["pad_token_id"] = (
f"`pad_token_id` should be positive but got {self.pad_token_id}. This will cause errors when batch "
"generating, if there is padding. Please set `pad_token_id` explicitly as "
"`model.generation_config.pad_token_id=PAD_TOKEN_ID` to avoid errors in generation"
)
# 1.2. Cache attributes
# "paged" re-routes to continuous batching and so it is a valid cache implementation. But we do not want to test
# it with the `generate` as the other would be, so we we cannot add it to ALL_CACHE_IMPLEMENTATIONS
valid_cache_implementations = ALL_CACHE_IMPLEMENTATIONS + ("paged",)
if self.cache_implementation is not None and self.cache_implementation not in valid_cache_implementations:View on GitHub (pinned to a597f97485)
Solutions
- Set early_stopping to True, False, None, or exactly 'never'
- Fix generation_config.json files where true/false were quoted as strings
- If loading configs from external sources, normalize known boolean fields before validate()
Example fix
# before cfg = GenerationConfig(early_stopping="true") # after cfg = GenerationConfig(early_stopping=True)
Defensive patterns
Strategy: validation
Validate before calling
def valid_early_stopping(v) -> bool:
return v in (None, True, False, "never") Type guard
from typing import Union
def is_valid_early_stopping(v) -> bool:
return v is None or isinstance(v, bool) or v == "never" Prevention
- Normalize booleans in generation_config.json (unquoted true/false)
- Run GenerationConfig.validate() right after construction to fail before long setups
When it happens
Trigger: GenerationConfig(early_stopping='yes'), model.generation_config.early_stopping = 1, or a generation_config.json containing a non-boolean early_stopping; validate() runs at generation start.
Common situations: Hand-edited generation_config.json where booleans became strings; configs round-tripped through YAML/JSON tooling that coerces types; copy-pasting from docs that show 'never' and assuming other strings work.
Related errors
- `max_new_tokens` must be greater than 0, but is {}.
- Invalid `cache_implementation` ({}). Choose one of: {}
- Invalid max_matching_ngram_size or num_output_tokens
- `assistant_ensemble_weight` must be in the open interval `(0
- You provided `compile_config` as an instance of {}, but it m
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/b8d3b08750e8ecd2.
Report an issue: GitHub.