已合并
fix: 修复dflow非0卡部署context校验失败并保证API层context透明 #4697
fix: 修复dflow非0卡部署context校验失败并保证API层context透明 #4697
已合并
lining23666创建于 9 天前
lining23666成员
9 天前

Pull Request

描述

修复 dflow 部署模型到非 0 卡时加载失败的问题,并保证 dflow API 对调用线程 runtime context 的透明性。包含两个配套修改:

1. SubmitEventSync 入口绑卡(dflow/deployer/common/data_flow/event/proxy_event_manager.cc)

根因:runtime context 是线程私有的,ProxyEventManager::SubmitEventSync 会在部署线程池工作线程(ge_dpl_ldlm 加载子模型线程等)中调用 rtEschedSubmitEventSync,而该线程从未执行过 aclrtSetDevice,报 EE1018: No valid context is bound to the current thread。部署 0 卡时命中 runtime 默认 context 侥幸通过,非 0 卡(如 numa_config 仅配置 2/3/4/5 卡)必现。

修复:SubmitEventSync 入口统一 aclrtSetDevice(device_id),单点覆盖全部 6 类远程内存组事件(CreateGroup/AddGroup/AllocCache/AllocMbuf/FreeMbuf/CopyQMbuf),与库内 DestroyQueue、UnloadSubmodels 既有做法一致。该路径仅在部署期和变量同步期调用,不在推理热路径。

2. dflow API 入口 context save/restore(dflow/runner/session/dflow_api.cc)

背景:内部路径(如 feed 的 io_helper)会在 API 调用线程上 SetDevice 并残留切换,污染调用方(如 torch_npu 用户主线程)的 context。

修复:API 层新增 RtCtxGuard(RAII),入口记录调用线程 context,出口恢复,使内部设备/context 切换对调用方透明:

  • 无 context 或未变化时零动作(避免恢复已销毁 context 失败的场景,如 Finalize 内部 aclrtResetDevice 后)
  • 构造/析构均容忍失败,restore 失败仅打警告
  • 覆盖全部 16 个 API 入口

两个修改配合形成完整方案:内部各依赖 context 的调用点用前自行绑卡(可自由切换),API 层对调用方上下文透明。

变更类型

关联的Issue

如何测试

  1. 复现:numa_config.json 的 item_list 仅配置 2、3、4、5 卡,运行 examples/dflow/python/sample_npu_model.py,部署到物理 2 卡时报 EE1018 context null,模型加载失败
  2. 修复后验证:同配置重跑上述样例,模型加载成功、feed/fetch 正常
  3. context 透明性验证:feed 前后检查调用线程的当前 context/device 不变(torch_npu 混用场景)
  4. 回归:本地增量编译 dflow(model_deployer、dflow_runner 目标)通过;pre-commit 全部通过

核对清单

其他信息

本 PR 为草稿状态,真机验证进行中,完成后转正式。

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 lining23666 的贡献)
Llining23666成员
9 天前 创建了 pull request,commit 6207b6ad
CANN-robotCANN-robot成员
9 天前 添加了label:stat/needs-squash
CANN-robotCANN-robot成员
9 天前 添加了label:cann-cla/yes
CANN-robot
CANN-robot成员
9 天前 评论:

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.
For more, you also can visit HICANN.


PR Approval Progress

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

Module Approval Details

module lgtm status approve status
repo-cann/ge yangyongqiang0606, stevenaw0, xchu42 (3/2) yangyongqiang0606 (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robot成员
9 天前 将yangyongqiang0606,kobemini,ClarkXie,tangqunzhang,xchu42,hugo111,fu-jun2,depeng1994,wqtshg_wt,peiyang,shengnan666,zhangfan_hanq,zhanj,zhujingjing,Mexyy,wangxiaotian995,stevenaw0,yuht9设为评审人
CANN-robotCANN-robot成员
9 天前 将yangyongqiang0606,kobemini,ClarkXie,tangqunzhang,xchu42,hugo111,fu-jun2,depeng1994,wqtshg_wt,peiyang,shengnan666,zhangfan_hanq,zhanj,zhujingjing,Mexyy,wangxiaotian995,stevenaw0,yuht9设为审查人
lining23666成员
9 天前 评论:

compile

likedislike
Llining23666成员
9 天前 update merge request[project id: 8824148, iid: 4697, commit_id: b70f65be543714b04dcd545a8b0fa18dbf226721] virtual merging success
CANN-robot
CANN-robot成员
9 天前 评论:
🚀 CI 流水线已启动
📋 执行详情: 点击查看流水线
likedislike
CANN-robotCANN-robot成员
9 天前 添加了label:ci-pipeline-running
CANN-robotCANN-robot成员
9 天前 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
9 天前 添加了label:ci-pipeline-passed
Llining23666成员
8 天前 取消了草稿状态
黄桂军
黄桂军成员
8 天前 评论:

/lgtm

likedislike
xchu42
xchu42成员
8 天前 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
8 天前 添加了label:lgtm
yangyongqiang
yangyongqiang成员
7 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
7 天前 添加了label:approved
CANN-robotCANN-robot成员
7 天前 合入了pull request