huggingface config_error ai_generated true

ValueError: Loading this model requires trust_remote_code=True. See https://huggingface.co/docs/hub/security

ID: huggingface/trust-remote-code-required

Also available as: JSON · Markdown · 中文
93%Fix Rate
90%Confidence
1Evidence
2023-06-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
transformers>=4.30.0 active

Root Cause

The model repository contains custom Python code (e.g., modeling file) that must be executed locally; trust_remote_code flag is not set for security reasons.

generic

中文

模型仓库包含必须本地执行的自定义Python代码(例如建模文件);出于安全原因未设置trust_remote_code标志。

Official Documentation

https://huggingface.co/docs/hub/security#trust-remote-code

Workarounds

  1. 95% success Set trust_remote_code=True in from_pretrained after reviewing the custom code.
    Set trust_remote_code=True in from_pretrained after reviewing the custom code.
  2. 90% success Download and inspect the custom code files, then load with trust_remote_code=True.
    Download and inspect the custom code files, then load with trust_remote_code=True.
  3. 85% success Use the transformers CLI to download the model and then load with trust_remote_code.
    Use the transformers CLI to download the model and then load with trust_remote_code.

中文步骤

  1. Set trust_remote_code=True in from_pretrained after reviewing the custom code.
  2. Download and inspect the custom code files, then load with trust_remote_code=True.
  3. Use the transformers CLI to download the model and then load with trust_remote_code.

Dead Ends

Common approaches that don't work:

  1. 98% fail

    This parameter does not address the remote code execution requirement.

  2. 85% fail

    Custom code is still required even from local files; trust_remote_code must be set.