Skip to content
Latchkey

Hugging Face transformers "trust_remote_code=True" required for a model in CI

The model defines a custom architecture whose code lives in the repo. transformers refuses to import and run that code unless you pass trust_remote_code=True, so a fresh CI load of such a model fails until you opt in.

What this error means

from_pretrained raises "ValueError: Loading <model> requires you to execute the configuration file in that repo ... you can inspect ... set the option trust_remote_code=True to remove this error."

transformers
ValueError: Loading org/custom-model requires you to execute the configuration file in that
repo on your local machine. Make sure you have read the code there to avoid malicious use, then
set the option `trust_remote_code=True` to remove this error.

Common causes

The model has a custom architecture with repo code

Models not in the transformers library define their classes in the repo; loading them runs that code, which is blocked by default.

The flag is not set in the CI call

Without trust_remote_code=True, the guard raises rather than importing the remote module.

How to fix it

Enable trust_remote_code and pin the revision

  1. Read the modeling and config code in the repo so you trust it.
  2. Pass trust_remote_code=True and a pinned revision.
  3. Re-run so transformers imports the custom classes.
python
from transformers import AutoModel
AutoModel.from_pretrained("org/custom-model", trust_remote_code=True, revision="abc123")

Prefer an in-library architecture

If a supported architecture covers your need, use it so no remote code executes in CI.

How to prevent it

  • Review and pin the model revision before enabling remote code.
  • Prefer architectures shipped in transformers where possible.
  • Set the flag in code so CI never needs a prompt.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →