已合并
fix(benchmark): restrict remote model code execution #46981
fix(benchmark): restrict remote model code execution #46981
已合并
liuyutong创建于 8 天前
liuyutong
liuyutong成员
8 天前

【合入来源】

如有社区issue,请关联issue链接
请勿携带内部流程信息(需求链接、问题单、内部issue等)

关联 Issue:Fixes #5082
https://gitcode.com/Ascend/pytorch/issues/5082

【修改方案】

  1. 删除 Transformers 4.57.1 已原生支持模型的 trust_remote_code=True,避免默认执行模型仓自定义 Python 代码。
  2. Baichuan2 保留架构所需能力,但改为默认关闭的 --trust-remote-code 显式开关;远程仓启用时必须通过 --revision 固定完整 commit hash,本地模型目录不强制 revision。
  3. 删除 Mamba2 和 Qwen2VL 样例中的个人绝对模型路径,改为必填参数。
  4. 更新 Baichuan2/GLM4 README,说明远程代码风险、可信来源要求以及原生 GLM4 模型要求。
  5. 修复本次涉及文件的尾随空格和 EOF 换行问题。

【资料变更】

涉及。Baichuan2 README 新增远程代码执行风险声明与固定 revision 要求;GLM4 README 说明使用 Transformers 内置实现,不执行模型仓自定义代码。

【接口变更】

涉及命令行参数变更:

  • Baichuan2 新增 --trust-remote-code,默认关闭。
  • Baichuan2 新增 --revision;远程模型开启远程代码时必须提供完整的 40 位 commit hash。
  • Mamba2 的 --model_path 和 Qwen2VL 的 --model_name_or_path 改为必填参数。

【功能验证】

  • transformers==4.57.1 环境下完成 Mamba2、Qwen3、Qwen2VL、Llama3、GPT-OSS 原生配置/tokenizer/processor 加载 smoke 验证。
  • Baichuan2 参数默认值验证为 trust_remote_code=False;远程路径开启开关但未提供固定 revision 时,会在模型加载前拒绝执行。
  • 42 个分支相关 Python 文件通过 py_compile。
  • 6 个 Baichuan2 启动脚本通过 bash -n。
  • git diff --check、EOF 换行、尾随空格、Tab、120 字符行长及硬编码 trust_remote_code=True 扫描通过。
  • 未执行完整模型训练,待 PR 流水线进一步验证。

【CheckList】

PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 liuyutong 的贡献)
liuyutongliuyutong成员
8 天前 创建了 pull request,commit ecf39a09
atomgit-bot
atomgit-bot
8 天前 评论:

变更摘要

本 PR 主要围绕 LLM 示例代码中远程模型自定义代码执行的风险进行收敛:删除多个训练脚本中硬编码的 trust_remote_code=True,使 Transformers 已原生支持的模型默认不执行模型仓自定义 Python 代码;仅在 Baichuan2 中保留该能力并改为默认关闭的显式开关,同时引入 revision 约束以固定远程 commit。此外清理了样例中的个人绝对路径默认值,并修复相关文件的 EOF 换行与尾随空格问题。

主要改动

  • Baichuan2 训练脚本参数化远程代码控制:train_baichuan2_7B.py 中将 AutoTokenizer.from_pretrained 与 AutoModelForCausalLM.from_pretrained 的 trust_remote_code=True 替换为 revision=self.args.revision 与 trust_remote_code=self.args.trust_remote_code,由命令行参数决定是否执行模型仓自定义代码。
  • 新增 --trust-remote-code 与 --revision 命令行参数:build_argparser() 新增默认关闭的 --trust-remote-code(action="store_true")和默认 None 的 --revision;main() 中新增校验,当开启远程代码且 model_path 非本地目录时,revision 必须为 40 位十六进制完整 commit hash,否则通过 parser.error 拒绝执行。
  • 移除其他模型样例中的 trust_remote_code=True:train_glm4_9B.py、train_gpt_oss_20B.py、train_llama3.py、train_mamba2_7B.py、train_qwen2vl.py、train_qwen3_4B.py 中模型、tokenizer 或 processor 加载处的该参数均被删除,改为使用原生实现。
  • 将个人绝对模型路径默认值改为必填参数:train_mamba2_7B.py 的 --model_path 与 train_qwen2vl.py 的 --model_name_or_path 由硬编码默认路径改为 required=True。
  • 启动脚本与文件格式修正:run_baichuan2.sh 新增 "$@" 以透传外部参数,并对涉及文件补齐末尾换行、清理尾随空格。
likedislike
不准确?
atomgit-bot
atomgit-bot
8 天前 评论:

代码审查

✅ 未发现问题

likedislike
不准确?
ascend-robotascend-robot成员
8 天前 添加了label:ascend-cla/yes
ascend-robotascend-robot成员
8 天前 添加了label:needs-issue
ascend-robot
ascend-robot成员
8 天前 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here.
You can get sig-info at here.
You can self-configure the PR merge rules for this repository. For more details, please refer to Here.


PR Approval Progress

✅ Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
**/*.md ✅ chenrayray, li_jing_hw (2/2) ✅ li_jing_hw, chenrayray (2/1)
repo-Ascend/pytorch ✅ chenrayray, li_jing_hw (2/2) ✅ chenrayray, li_jing_hw (2/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

liuyutong_bury, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
ascend-robot
ascend-robot成员
8 天前 评论:

Linking Issue Notice

@liuyutong_bury , the pull request must be linked to at least one issue.
If an issue has already been linked, but the needs-issue label remains, you can remove the label by commenting /check-issue .

likedislike
ascend-robot
ascend-robot成员
8 天前 评论:

当前仓库存在以下 保护分支 :

Protected Branch Version Release
master
v2.10.0
v2.11.0
v2.12.0
v2.14.0-26.2.0
v2.13.0-26.2.0
v2.7.1-26.2.0
v2.7.1
v2.12.0-26.2.0
v2.10.0-26.2.0
v2.9.0-26.2.0
v2.11.0-26.2.0
v2.9.0
v2.7.1-26.1.0
v2.9.0-26.1.0
v2.11.0-26.1.0
v2.12.0-26.1.0
v2.10.0-26.1.0
ci-test
fix/te-rnumel-autoblockify-prea5

评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作

注意:

  1. /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
  2. 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭
likedislike
AtlasAccountAtlasAccount成员
8 天前 添加了label:ci-pipeline-running
ascend-robot
ascend-robot成员
8 天前 评论:

ascend docs pipeline is running...

likedislike
ascend-robotascend-robot成员
8 天前 添加了label:docs-ci-pipeline-running
liuyutongliuyutong成员
8 天前 修改标题为 “fix(benchmark): restrict remote model code execution”,原标题为“[v2.10.0] fix(llm): restrict remote model code execution”
ascend-robot
ascend-robot成员
8 天前 评论:

✅ 文档门禁通过!

检查项 检查结果 详情
markdownlint ✅ 已通过 查看详情
link-validity-check ✅ 已通过 查看详情
resource-existence-check ✅ 已通过 查看详情
tag-closed-check ✅ 已通过 查看详情
likedislike
ascend-robotascend-robot成员
8 天前 删除了label:docs-ci-pipeline-running
此处折叠了5条事件消息 查看更多
AtlasAccountAtlasAccount成员
8 天前 添加了label:ci-pipeline-passed
AtlasAccount
AtlasAccount成员
8 天前 评论:
流水线 PR-pipeline_pytorch#69713 [ commitID:513208d3 ] 已完成
>>>代码风格自动修复执行成功(无修复内容)
阶段 任务名 状态 详情
编译构建 Build_X86 ✅ COMPLETED >>>
Build_ARM ✅ COMPLETED >>>
Build_X86_torchair ⚪ IGNORED >>>
Build_ARM_torchair ⚪ IGNORED >>>
patch_test ⚪ IGNORED >>>
Build_X86_213 ⚪ IGNORED >>>
Build_ARM_213 ⚪ IGNORED >>>
恶意代码检查 Antipoison ✅ COMPLETED >>>
编码安全与规范检查 codecheck_pre-commit ✅ COMPLETED >>>
check_error ✅ COMPLETED >>>
lintrunner ✅ COMPLETED >>>
开源片段检查 SCA ✅ COMPLETED >>>
开发者测试 UT_ARM_A3_Part_01 ⚪ IGNORED >>>
UT_ARM_A3_Part_02 ⚪ IGNORED >>>
UT_ARM_A2_Part_01 ✅ COMPLETED >>>
UT_ARM_A2_Part_02 ✅ COMPLETED >>>
UT_ARM_A2_Part_03 ⚪ IGNORED >>>
UT_inductor_Part_01 ⚪ IGNORED >>>
UT_inductor_Part_02 ⚪ IGNORED >>>
UT_inductor_Part_03 ⚪ IGNORED >>>
UT_inductor_Part_04 ⚪ IGNORED >>>
UT_DIST_ARM_Part_01 ⚪ IGNORED >>>
UT_DIST_ARM_Part_02 ⚪ IGNORED >>>
UT_DIST_ARM_Part_03 ⚪ IGNORED >>>
UT_DIST_ARM_Part_04 ⚪ IGNORED >>>
UT_ARM_A2_Select_Part_01 ⚪ IGNORED >>>
UT_ARM_A2_Select_Part_02 ⚪ IGNORED >>>
UT_inductor_Part1_213 ⚪ IGNORED >>>
流水线 PR-pipeline_pytorch ✅ COMPLETED >>>
此流水线已支持下列评论快捷指令,仅PR创建者和白名单成员[wujinyuan1, huangjingwei, liangsongwei, yashi999, culechan, Dring, wuyouqi1, L1919_snow, qq_52711437, WhiteNight12, nomiz, xiu_21, ffmh, wanglijun55, hss-shuai, husichao, smallsilly, lanshaozuishuai, jimmyisme1, lzy0920232, alpha-junh, Sunshine_Youngster, wei_zhuoyi, zhangyihuiben, zyw-hw, zzzkeke, rmch, yangch0324, LucciC, AACAES, renyujin, wjlflyer, senzhen-town, pengjingyou, qsc97, limuan, yule100, xiaoqi-zhou, kuhn7, chenxingying, hanye02, zichun_ye, anyrenwei, kkjocker, wangzili121, Lu_G, yvjc, puddingfjz, HandsoemLemon, bigprestigee1, huawuyi, zhenyu10, dairenjie, du-jin-hang, zou-jieyu, adelaideliu, TrHan, wanlinan, Windwindzzz, pengqihw, kisnwang, yuheng_wang, honghao_wang, jizewei, zhangguoguang, sunyu-xuan, chenrayray, hbhu_bin, liujunzhu, c_34, LiNuoh, maoyuanpeng1, zzhongmin, zhaoyu65, bellatan, jiabaolin, zhuofanshen, wencaiwen, lu_zhuge, caoshuyang, molly12, lyx324521, LQ1206, gitcode-chenjiao, cai-weiwei1989, CHDong, ogqin, yuanlipingGit, xuqinglin1, lqz2, zouwei1, chaoluoa, paradox325, jackzhang1116, yaoyao, akh, yujiacheng, dengjie0116, Hubert11111, Shine_Ws, wslhj555, longqiand, OYtao666, JiaqingQiang, luyyyy, Kingbelial, zhanghaiyu0101, wenxp1018, yanliu-luoluo, ksun_sekiro, liyong328, wgzheng, tangky, vivi_is_coding, aoiaoisola, weixin_44494597, wangmengmengwang65667, hid57809721, qq_35468730, comeonup, C547032, gcw_m5OQChA4, yao_yao_ling_xian, cnnbwcy, szqfes_12, cora_19, cann_lilin, can, shawnylee233, fanglanyue0916, hhz0, LiNuohang, taohuoquan, Jesse, WSs_321, SCh_zx, lvjiangdong, TonyYA, shi-yufeng99, qiaoyaodan, stonexxx, jimmycao9929, zzll, qindong0, luqichao, xinyuzhuo, liujm2001, dezheng889, zhucehw, HinPeng, rain-666, lsy_0111, a_knight]评论有效
  • compile、compile_inductor、compile_torchair : 运行流水线
  • retry : 重试流水线所有失败子任务
  • retry <任务名> : 仅重试指定失败子任务
  • stop : 停止流水线
likedislike
chenrayray
chenrayray成员
8 天前 评论:

/approve

likedislike
ascend-robotascend-robot成员
8 天前 添加了label:approved
li_jing_hw成员
8 天前 评论:

/approve

likedislike
ascend-robotascend-robot成员
8 天前 添加了label:lgtm
ascend-robotascend-robot成员
8 天前 合入了pull request