huggingface config_error ai_generated true

值错误:加载此模型需要trust_remote_code=True。请参阅https://huggingface.co/docs/hub/security

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

ID: huggingface/trust-remote-code-required

其他格式: JSON · Markdown 中文 · English
93%修复率
90%置信度
1证据数
2023-06-01首次发现

版本兼容性

版本状态引入弃用备注
transformers>=4.30.0 active

根因分析

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

English

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

官方文档

https://huggingface.co/docs/hub/security#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.

无效尝试

常见但无效的做法:

  1. 98% 失败

    This parameter does not address the remote code execution requirement.

  2. 85% 失败

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