{"record":{"id":"b736621e14c31054","repo":"huggingface/transformers","slug":"generation-mode-name-replace-title-r","errorCode":null,"errorMessage":"{generation_mode.name.replace('_', ' ').title()} requires `trust_remote_code=True` in your `generate` call, since it loads https://hf.co/{repo}.","messagePattern":"(.+?) requires `trust_remote_code=True` in your `generate` call, since it loads https://hf\\.co/(.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/generation/utils.py","lineNumber":2221,"sourceCode":"    def _get_deprecated_gen_repo(\n        self,\n        generation_mode: GenerationMode,\n        trust_remote_code: bool,\n        custom_generate: str | None = None,\n    ) -> str | None:\n        \"\"\"\n        Returns the Hub repo for a deprecated generation mode, if any.\n        \"\"\"\n        if custom_generate is not None or \"/\" not in (repo := GENERATION_MODES_MAPPING[generation_mode]):\n            return None\n\n        logger.warning_once(\n            f\"{generation_mode.name.replace('_', ' ').title()} was moved to a `custom_generate` repo: https://hf.co/{repo}. \"\n            f\"To prevent loss of backward compatibility, add `custom_generate='{repo}'` \"\n            \"to your `generate` call before v4.62.0.\"\n        )\n        if not trust_remote_code:\n            raise ValueError(\n                f\"{generation_mode.name.replace('_', ' ').title()} requires `trust_remote_code=True` in your `generate` call, \"\n                f\"since it loads https://hf.co/{repo}.\"\n            )\n        return repo\n\n    def _extract_generation_mode_kwargs(\n        self,\n        custom_generate,\n        kwargs,\n        synced_gpus,\n        assistant_model,\n        streamer,\n    ) -> dict[str, Any]:\n        \"\"\"\n        Extracts and returns the generation mode related keyword arguments from the provided kwargs.\n        \"\"\"\n        generation_mode_kwargs = {\n            \"tokenizer\": kwargs.pop(\"tokenizer\", None),","sourceCodeStart":2203,"sourceCodeEnd":2239,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/generation/utils.py#L2203-L2239","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nout = model.generate(**inputs, penalty_alpha=0.6, top_k=4)  # moved mode, no consent -> ValueError\n\n# after\nout = model.generate(**inputs, penalty_alpha=0.6, top_k=4, trust_remote_code=True)\n# or explicitly:\nout = model.generate(**inputs, custom_generate='<repo-from-warning>', trust_remote_code=True)","handlingStrategy":"validation","validationCode":"# opt in deliberately before calling a moved mode\nrequired_repo = GENERATION_MODES_MAPPING.get(resolved_mode)\nif required_repo and \"/\" in required_repo:\n    assert kwargs.get(\"trust_remote_code\") is True or kwargs.get(\"custom_generate\") == required_repo","typeGuard":null,"tryCatchPattern":"try:\n    out = model.generate(**inputs, **kwargs)\nexcept ValueError as e:\n    if \"requires `trust_remote_code=True`\" in str(e):\n        out = model.generate(**inputs, **kwargs, trust_remote_code=True)\n    else:\n        raise","preventionTips":["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."],"tags":["generation","trust-remote-code","custom-generate","deprecation","security"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}