huggingface/transformers · error · ValueError

Loading this model requires you to execute custom code conta

Error message

Loading this model requires you to execute custom code contained in the model repository on your local machine. Please set the option `trust_remote_code=True` to permit loading of this model.

What it means

When a model needs remote code and trust_remote_code is not set, transformers prompts interactively with a 15-second SIGALRM timeout. If you do not answer in time, the signal handler raises this ValueError — functionally 'permission denied by timeout'. It is also invoked directly when the CI sets the timeout to 0, guaranteeing non-interactive environments fail deterministically.

Source

Thrown at src/transformers/dynamic_module_utils.py:703

    result = []
    # Copy module file to the output folder.
    object_file = sys.modules[obj.__module__].__file__
    dest_file = Path(folder) / (Path(object_file).name)
    shutil.copyfile(object_file, dest_file)
    result.append(dest_file)

    # Gather all relative imports recursively and make sure they are copied as well.
    for needed_file in get_relative_import_files(object_file):
        dest_file = Path(folder) / (Path(needed_file).name)
        shutil.copyfile(needed_file, dest_file)
        result.append(dest_file)

    return result


def _raise_timeout_error(signum, frame):
    raise ValueError(
        "Loading this model requires you to execute custom code contained in the model repository on your local "
        "machine. Please set the option `trust_remote_code=True` to permit loading of this model."
    )


TIME_OUT_REMOTE_CODE = 15


def resolve_trust_remote_code(
    trust_remote_code, model_name, has_local_code, has_remote_code, error_message=None, upstream_repo=None
):
    """
    Resolves the `trust_remote_code` argument. If there is remote code to be loaded, the user must opt-in to loading
    it.

    Args:
        trust_remote_code (`bool` or `None`):
            User-defined `trust_remote_code` value.

View on GitHub (pinned to a597f97485)

Solutions

  1. Pass trust_remote_code=True explicitly to from_pretrained (after reviewing the repo code at hf.co/<model>).
  2. For batch jobs, make trust decisions at config level, not interactively.
  3. If you did want the prompt, ensure stdin is a TTY and watch for it within 15 seconds.

Example fix

# before
AutoModel.from_pretrained("org/custom-model")  # prompt times out after 15s

# after
AutoModel.from_pretrained("org/custom-model", trust_remote_code=True)
Defensive patterns

Strategy: validation

Validate before calling

# Non-interactive scripts: never rely on the 15s prompt.
model = AutoModel.from_pretrained(repo_id, trust_remote_code=True)  # decide up front, after reviewing the repo

Try / catch

try:
    AutoModel.from_pretrained(repo_id)
except ValueError as e:
    if "trust_remote_code=True" in str(e):
        raise SystemExit(f"Non-interactive run: set trust_remote_code explicitly for {repo_id}")
    raise

Prevention

When it happens

Trigger: Loading a remote-code model without trust_remote_code in a terminal where the [y/N] prompt is not answered within TIME_OUT_REMOTE_CODE (15 s), or in CI where the timeout is 0.

Common situations: Unattended scripts/cron jobs hitting the prompt; output buried under logs so the user never sees the question; notebooks where the prompt never displays.

Related errors


AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14). Data as JSON: /api/errors/91044f78bd64b0f9. Report an issue: GitHub.