You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure ML Studio运行falcon-7b-instruct时trust_remote_code=True仍报错

解决falcon-7b-instruct加载时的trust_remote_code报错问题

可行解决方法:

1. 给AutoTokenizer也添加trust_remote_code参数

你当前仅在transformers.pipeline中设置了trust_remote_code=True,但加载tokenizer时同样需要允许远程代码执行。修改代码如下:

from transformers import AutoTokenizer
import transformers
import torch

model = "tiiuae/falcon-7b-instruct"

# 给tokenizer加载也添加trust_remote_code=True
tokenizer = AutoTokenizer.from_pretrained(model, trust_remote_code=True)
pipeline = transformers.pipeline(
    "text-generation",
    model=model,
    tokenizer=tokenizer,
    torch_dtype=torch.bfloat16,
    device_map="auto",
    trust_remote_code=True
)

2. 设置全局环境变量

如果不想在每个加载方法中重复添加参数,可以设置环境变量TRANSFORMERS_TRUST_REMOTE_CODE为1,让transformers全局信任远程代码。在Azure ML Notebook中可通过以下方式设置:

import os
os.environ["TRANSFORMERS_TRUST_REMOTE_CODE"] = "1"

或在Notebook终端执行:

export TRANSFORMERS_TRUST_REMOTE_CODE=1

3. 确保transformers版本达标

falcon系列模型需要较新版本的transformers支持,建议升级到4.28.0及以上:

!pip install --upgrade transformers

补充说明

报错核心原因是falcon模型的配置文件包含自定义代码,不仅模型加载时需要信任远程代码,tokenizer加载过程中也会触发远程代码执行检查,因此需在两处都设置参数,或通过环境变量全局配置。

内容的提问来源于stack exchange,提问作者J Heschl

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.18 04:00:29