Closed
[feat] DCP pinned staging在NPU上面的适配 #5452
AWWOLFAdd on  Oct 16Closed at  11 days ago
AWWOLF
AWWOLFCollaborators
Oct 16 Create

〖问题描述〗

PyTorch DCP StateDictStager 在启用 pin_memory=True 时依赖 torch.cuda._pin_memory_utils 对已分配的 shared CPU staging storage 执行 pin/unpin。NPU 场景需要将该调用映射到 npuHostRegister/npuHostUnregister,使 CANN runtime 可以登记既有 host memory。

〖处理方案〗

复用 transfer_to_npu 现有 CUDA compatibility patch 机制,仅替换 torch.cuda._pin_memory_utils 的 pin_memory 和 unpin_memory 两个 helper:

  • pin_memory(ptr, size) -> torch_npu.npu.npurt().npuHostRegister(ptr, size, ACL_HOST_REG_PINNED);
  • unpin_memory(ptr) -> torch_npu.npu.npurt().npuHostUnregister(ptr)。

不修改 PyTorch DCP、checkpoint 格式、load API、staging cache 或 shared storage 生命周期。

后续消除patch方案:https://gitcode.com/ZHANGJIAOGOU/pytorch_support_NPU_pinned_memory/blob/privateuse1-pinned-memory-migration/PINNED_MEMORY_PATCH_REMOVAL_PLAN.md

〖关联 PR〗

〖适配检查〗

四个目标分支均已完成 source-level 检查:补丁可无冲突应用,且 torch_npu.npu.npurt().npuHostRegister/npuHostUnregister 与 ACL bridge 均存在。

〖功能验证计划〗

  • DCP 首次 staging:shared CPU storage 地址与 register 地址一致;
  • cache hit:同一 source storage 不重复 register;
  • 生命周期:storage 释放后正常 unregister;
  • 正确性:THREAD/PROCESS save-load 一致;
  • 多 rank:各 rank 独立 registration,无 hang 或通信异常。

〖资料变更〗

不涉及。

〖接口变更〗

不涉及新增用户接口。

〖备注〗

当前已完成补丁适配和静态检查;NPU 实机、PROCESS writer 与多 rank 回归由对应 PR CI/测试继续验证。

likedislike
TorchNPU-BotTorchNPU-BotCollaborators
Oct 16 Added label: triage-reviewmodule: core
TorchNPU-Bot
TorchNPU-BotCollaborators
Oct 16 Comments:

无报错,属功能建议/feature request;主题为 DCP pinned staging 支持与 npuHostRegister/npuHostUnregister 接口映射,归 module: core
添加分类标签:module: core。
当前分类由社区bot提供,如分类有误请在评论中回复。

likedislike
AWWOLFAWWOLFCollaborators
Oct 16 changed custom category from Bug-Report to 需求
AWWOLFAWWOLFCollaborators
Oct 16 Modify description of issue
TorchNPU-BotTorchNPU-BotCollaborators
Oct 16 Added label: bot-triaged; Removed label: triage-review
TorchNPU-Bot
TorchNPU-BotCollaborators
Oct 16 Comments:

检测到当前 issue 已关联 PR,自动添加标签:bot-triaged

likedislike
AWWOLFAWWOLFCollaborators
Oct 16 Change title to "[feat] DCP pinned staging support to v2.9.0-v2.12.0", originally titled "[feat] Backport NPU DCP pinned staging support to v2.9.0-v2.12.0".
AWWOLFAWWOLFCollaborators
Oct 16 Change title to "[feat] DCP pinned staging在NPU上面的适配", originally titled "[feat] DCP pinned staging support to v2.9.0-v2.12.0".
chenrayray
chenrayrayCollaborators
11 days ago Comments:

关联的 PR(!46095、!47977、!47978、!47979、!47980)已全部合入,先关闭这个 issue。如问题仍存在或需要继续跟踪,欢迎补充信息后重新打开。

likedislike
chenrayraychenrayrayCollaborators
11 days ago Close issue
chenrayraychenrayrayCollaborators
11 days ago changed custom state from TODO to CLOSED
ascend-robotascend-robotCollaborators
11 days ago Added label: resolved