huggingface/transformers · error · ValueError

{error_message} You can inspect the repository content at ht

Error message

{error_message} You can inspect the repository content at https://hf.co/{model_name}.
Please pass the argument `trust_remote_code=True` to allow custom code to be run.

What it means

This ValueError is raised inside the except branch of the trust_remote_code prompt flow: the platform does not support signal.SIGALRM (notably Windows), so the timed interactive prompt cannot be set up at all. Instead of hanging on input(), transformers raises with the standard instruction to pass trust_remote_code explicitly.

Source

Thrown at src/transformers/dynamic_module_utils.py:776

        elif has_remote_code and TIME_OUT_REMOTE_CODE > 0:
            prev_sig_handler = None
            try:
                prev_sig_handler = signal.signal(signal.SIGALRM, _raise_timeout_error)
                signal.alarm(TIME_OUT_REMOTE_CODE)
                while trust_remote_code is None:
                    answer = input(
                        f"{error_message} You can inspect the repository content at https://hf.co/{model_name}.\n"
                        f"You can avoid this prompt in future by passing the argument `trust_remote_code=True`.\n\n"
                        f"Do you wish to run the custom code? [y/N] "
                    )
                    if answer.lower() in ["yes", "y", "1"]:
                        trust_remote_code = True
                    elif answer.lower() in ["no", "n", "0", ""]:
                        trust_remote_code = False
                signal.alarm(0)
            except Exception:
                # OS which does not support signal.SIGALRM
                raise ValueError(
                    f"{error_message} You can inspect the repository content at https://hf.co/{model_name}.\n"
                    f"Please pass the argument `trust_remote_code=True` to allow custom code to be run."
                )
            finally:
                if prev_sig_handler is not None:
                    signal.signal(signal.SIGALRM, prev_sig_handler)
                    signal.alarm(0)
        elif has_remote_code:
            # For the CI which puts the timeout at 0
            _raise_timeout_error(None, None)

    if has_remote_code and not has_local_code and not trust_remote_code:
        raise ValueError(
            f"{error_message} You can inspect the repository content at https://hf.co/{model_name}.\n"
            f"Please pass the argument `trust_remote_code=True` to allow custom code to be run."
        )

    return trust_remote_code

View on GitHub (pinned to a597f97485)

Solutions

  1. Pass trust_remote_code=True (after reviewing the repository code linked in the message).
  2. Or set HF_HUB settings / environment defaults your framework provides for non-interactive trust decisions.
  3. On POSIX systems this branch is not hit; if you see it there, an exception during prompt setup occurred — check for wrapped causes.

Example fix

# before (Windows)
AutoModel.from_pretrained("org/custom-model")  # ValueError from SIGALRM fallback

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

Strategy: validation

Validate before calling

# On platforms without SIGALRM (Windows), pass the flag explicitly:
model = AutoModel.from_pretrained(repo_id, trust_remote_code=True)

Try / catch

try:
    AutoModel.from_pretrained(repo_id)
except ValueError as e:
    if "trust_remote_code=True" in str(e):
        AutoModel.from_pretrained(repo_id, trust_remote_code=True)
    else:
        raise

Prevention

When it happens

Trigger: Loading a remote-code model without trust_remote_code=True on Windows (or any OS where signal.setitimer/SIGALRM is unavailable) while has_local_code is true, triggering the interactive-confirm branch.

Common situations: Windows workstations; some non-POSIX container environments. The same fix applies as the timeout variant: make the trust decision explicitly.

Related errors


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