Closed
【API一致性任务】torch.autograd.profiler_util.StringTable 四个容器接口无需 NPU 适配 #3034
hhjAdd on  Jul 18Closed at  Sep 30
hhj
hhj
Jul 18 Create

分析结论

以下四个接口均由 Python 的 dict/defaultdict 直接提供实现:

  • torch.autograd.profiler_util.StringTable.fromkeys
  • torch.autograd.profiler_util.StringTable.update
  • torch.autograd.profiler_util.StringTable.keys
  • torch.autograd.profiler_util.StringTable.get

这些接口不涉及 Tensor、device、NPU 算子、CANN 或其他硬件相关逻辑,无需补充 torch-npu 功能代码,也无需在 torch-npu 中新增仅验证 Python 容器行为的单元测试。本任务按“issue + docs”处理:issue 记录一致性分析结论,资料 PR 补充支持状态。

官方实现与社区用例核查

活动版本的 torch/autograd/profiler_util.py 中,StringTable 仅覆写 __missing__:

class StringTable(defaultdict):
    def __missing__(self, key):
        self[key] = torch._C._demangle(key) if len(key) > 1 else key
        return self[key]

四个目标接口没有 torch-npu 自定义实现,其行为由 Python dict/defaultdict 决定。

已检查 PyTorch 官方 test/,未发现四个接口的直接测试;同时实际读取了 torch-npu 现有 profiler/autograd test_upstream patch,也未发现相关覆盖。由于这些接口没有 NPU 适配逻辑,即使在 torch-npu 仓库新增测试,也只能重复验证 Python 标准容器行为,不能形成 NPU 功能看护,因此不新增 test/ 用例或 test_upstream patch。

API 功能与 NPU 一致性结论

接口 功能 NPU 相关性 处理结论
torch.autograd.profiler_util.StringTable.fromkeys 根据可迭代 key 创建新映射 无 无需代码或测试适配
torch.autograd.profiler_util.StringTable.update 使用 mapping、键值对 iterable 或关键字参数更新映射 无 无需代码或测试适配
torch.autograd.profiler_util.StringTable.keys 返回键的动态视图 无 无需代码或测试适配
torch.autograd.profiler_util.StringTable.get 按 key 获取值,缺失时返回 default 无 无需代码或测试适配

上述接口不接收或返回 NPU Tensor,不触发设备迁移或算子执行;在各活动版本中的实现来源和行为一致,因此无需逐版本提交代码 PR。

版本核查

已核查 master、v2.7.1、v2.11.0、v2.12.0 对应实现,四个接口均直接继承自 dict/defaultdict,结论一致。v2.9.0、v2.10.0 已进入维护阶段,本任务也不对这些分支提出代码补齐要求。

资料补齐

独立资料 PR !42887 在当前 docs/zh/api/native_api 目录中补充四个接口的原生文档链接和硬件支持状态,覆盖当前存在的 PyTorch 2.7.1、2.11.0、2.12.0、2.13.0 页面。

上游已删除 PyTorch 2.9.0、2.10.0 资料页面,因此不恢复已删除目录。

历史测试 PR 处理

此前提交的以下测试 PR 仅验证 Python 容器行为。根据最新审核意见,本任务调整为“issue + docs”,这些测试 PR 不再合入:

原 v2.9.0 PR !42338 已关闭。以上历史 PR 的关闭不影响本 issue 和资料 PR 的处理结论。

2026-09-12 资料 PR 更新

资料 PR #42887 已基于最新 master 解决四个资料文件冲突并 squash 为 17713eccd4bee46017bcc89fcfdcbe500a13a42b。仅更新当前存在的 PyTorch 2.7.1、2.11.0、2.12.0、2.13.0 页面,不恢复 2.9.0、2.10.0 页面。

A5(Ascend950PR、CANN 9.1.0)runner 验证同时覆盖关联 Kernel 修复的四个版本,均为 1/1 通过;StringTable 四个纯 Python 容器接口的“无需 NPU 适配”结论不变。

likedislike
群青世界
群青世界Collaborators
Jul 21 Comments:

上游无直接测试用例需编写测试用例后提交,如果有,请提供运行日志和命令。并且请说明文档补齐的检查情况。

likedislike
hhjhhj
Jul 22 Change title to "[API Analysis] torch.autograd.profiler_util.StringTable.fromkeys/update/keys/get — 需补充测试用例", originally titled "[API Analysis] torch.autograd.profiler_util.StringTable.fromkeys/update/keys/get — 无需 NPU 适配".
16 event messages are collapsed here。 See more
TorchNPU-BotTorchNPU-BotCollaborators
Jul 28 Added label: bot-triaged
TorchNPU-Bot
TorchNPU-BotCollaborators
Jul 28 Comments:

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

likedislike
hhjhhj
Aug 6 Modify description of issue
hhjhhj
Aug 6 associated Kanban: FrameworkPTAdapter 版本issue看板
hhjhhj
Aug 6 Modify description of issue
hhjhhj
Aug 18 Change title to "【API一致性任务】torch.autograd.profiler_util.StringTable 四个容器接口缺少直接测试", originally titled "[API Analysis] torch.autograd.profiler_util.StringTable 四个容器接口缺少直接测试".
TorchNPU-BotTorchNPU-BotCollaborators
Aug 18 Added label: help-wantedevent: api-consistency
TorchNPU-Bot
TorchNPU-BotCollaborators
Aug 18 Comments:

检测到社区任务相关 issue,自动添加标签:event: api-consistency、help-wanted

likedislike
hhjhhj
Aug 20 Change title to "【API一致性任务】torch.autograd.profiler_util.StringTable 四个容器接口无需 NPU 适配", originally titled "【API一致性任务】torch.autograd.profiler_util.StringTable 四个容器接口缺少直接测试".
hhjhhj
Aug 20 Modify description of issue
hhj
hhj
Aug 20 Comments:

已按最新审核意见调整任务范围:torch.autograd.profiler_util.StringTable.fromkeys、update、keys、get 均为直接继承自 Python dict/defaultdict 的纯容器行为,与 NPU 无关,因此改为 issue + docs,不再向 torch-npu 合入新增测试。issue 正文已更新,测试 PR #42336、#42337、#42339、#42340 已分别说明原因并关闭;资料继续由 #42887 补齐。

likedislike
hhjhhj
Sep 12 Modify description of issue
群青世界群青世界Collaborators
Sep 30 changed custom state from TODO to DONE
群青世界群青世界Collaborators
Sep 30 Close issue
ascend-robotascend-robotCollaborators
Sep 30 Added label: resolved