huggingface/transformers · error · ValueError
{generation_mode.name.replace('_', ' ').title()} requires `t
Error message
{generation_mode.name.replace('_', ' ').title()} requires `trust_remote_code=True` in your `generate` call, since it loads https://hf.co/{repo}. What it means
Some generation modes were moved out of transformers into remote `custom_generate` repositories on the Hub. If the resolved mode maps to a Hub repo (contains '/'), generate warns that it moved and then requires `trust_remote_code=True` to authorize downloading and executing that repo's code; without it, it raises for safety.
Source
Thrown at src/transformers/generation/utils.py:2221
def _get_deprecated_gen_repo(
self,
generation_mode: GenerationMode,
trust_remote_code: bool,
custom_generate: str | None = None,
) -> str | None:
"""
Returns the Hub repo for a deprecated generation mode, if any.
"""
if custom_generate is not None or "/" not in (repo := GENERATION_MODES_MAPPING[generation_mode]):
return None
logger.warning_once(
f"{generation_mode.name.replace('_', ' ').title()} was moved to a `custom_generate` repo: https://hf.co/{repo}. "
f"To prevent loss of backward compatibility, add `custom_generate='{repo}'` "
"to your `generate` call before v4.62.0."
)
if not trust_remote_code:
raise ValueError(
f"{generation_mode.name.replace('_', ' ').title()} requires `trust_remote_code=True` in your `generate` call, "
f"since it loads https://hf.co/{repo}."
)
return repo
def _extract_generation_mode_kwargs(
self,
custom_generate,
kwargs,
synced_gpus,
assistant_model,
streamer,
) -> dict[str, Any]:
"""
Extracts and returns the generation mode related keyword arguments from the provided kwargs.
"""
generation_mode_kwargs = {
"tokenizer": kwargs.pop("tokenizer", None),View on GitHub (pinned to a597f97485)
Solutions
- Pin explicit consent: add `custom_generate='<repo>'` (the repo named in the warning) to your generate call before v4.62.0.
- Add `trust_remote_code=True` to the generate call to allow loading the remote repo.
- If remote code is unacceptable, switch to a supported built-in generation mode (e.g. greedy/sampling/beam) and re-tune parameters.
- Monitor the deprecation warning and migration docs so the transition to the required kwarg is deliberate.
Example fix
# before out = model.generate(**inputs, penalty_alpha=0.6, top_k=4) # moved mode, no consent -> ValueError # after out = model.generate(**inputs, penalty_alpha=0.6, top_k=4, trust_remote_code=True) # or explicitly: out = model.generate(**inputs, custom_generate='<repo-from-warning>', trust_remote_code=True)
Defensive patterns
Strategy: validation
Validate before calling
# opt in deliberately before calling a moved mode
required_repo = GENERATION_MODES_MAPPING.get(resolved_mode)
if required_repo and "/" in required_repo:
assert kwargs.get("trust_remote_code") is True or kwargs.get("custom_generate") == required_repo Try / catch
try:
out = model.generate(**inputs, **kwargs)
except ValueError as e:
if "requires `trust_remote_code=True`" in str(e):
out = model.generate(**inputs, **kwargs, trust_remote_code=True)
else:
raise Prevention
- Read deprecation warnings: they name the repo to pin via custom_generate before v4.62.0.
- Only enable trust_remote_code for repos you have audited — it executes remote code.
- Pin your transformers version in production so mode migrations don't surprise you.
When it happens
Trigger: Parameterizing `generate` to a deprecated/moved mode (e.g. contrastive search-style settings mapped in `GENERATION_MODES_MAPPING` to a repo like 'hf-internal-testing/...') without `trust_remote_code=True` and without an explicit `custom_generate='<repo>'` kwarg.
Common situations: Upgrading to transformers versions where the mode was extracted (with a deprecation window before v4.62.0); old scripts relying on the built-in mode; security-hardened environments where trust_remote_code is disabled by policy.
Related errors
- Loading this model requires you to execute custom code conta
- {error_message} You can inspect the repository content at ht
- `crop` was called, but the current layer does not track past
- Once the sliding window size has been reached, `DynamicSlidi
- `crop` was called, but the current layer does not track past
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/b736621e14c31054.
Report an issue: GitHub.