已合并
test(fx):Add validation cases for torch._C._distributed_rpc._is_current_rpc_agent_set on NPU #43171
test(fx):Add validation cases for torch._C._distributed_rpc._is_current_rpc_agent_set on NPU #43171
已合并
olpk创建于 23 天前
olpk
olpk
23 天前

关联issue:https://gitcode.com/Ascend/pytorch/issues/2748
关联issue: https://gitcode.com/Ascend/pytorch/issues/2828

API 功能

torch._C._distributed_rpc._is_current_rpc_agent_set:检查当前 RPC agent 是否已初始化,返回 bool。

用例完备性说明

PyTorch 社区在 test/ 目录下无针对此 API 的直接测试用例(grep 结果为 0),仅在 torch/testing/_internal/distributed/rpc/rpc_test.py 中有一处非直接的辅助引用。因此新增测试文件。

新增用例

本次自写用例 test/distributed/rpc/test_rpc_agent_set.py,包含 3 个测试方法:

测试方法 验证内容
test_is_current_rpc_agent_set_import 验证 API 可导入且 callable
test_is_current_rpc_agent_set_default 验证 RPC 未初始化时返回 False
test_is_current_rpc_agent_set_after_init 验证 init_rpc 后返回 True,shutdown 后恢复 False

适配方案

该 API 为框架层 RPC 状态查询接口,与底层设备无关,直接可用,无需 NPU 适配。

运行结果

NPU Ascend910B4 环境测试通过:
image.png

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 olpk 的贡献)
olpkolpk
23 天前 创建了 pull request,commit cb4eb436
atomgit-bot
atomgit-bot
23 天前 评论:

变更摘要

此PR为NPU平台新增了 torch._C._distributed_rpc._is_current_rpc_agent_set 接口的测试用例文件,旨在弥补PyTorch社区对该API验证覆盖不足的问题。新增的测试类 TestIsCurrentRpcAgentSet 覆盖了导入可用性、默认状态以及完整的RPC初始化/关闭生命周期中的返回值校验。

主要改动

  • 新增测试文件 test/distributed/rpc/test_rpc_agent_set.py: 为 torch._C._distributed_rpc._is_current_rpc_agent_set 新增独立的测试用例文件,包含3个测试方法,覆盖NPU场景下的API验证。
  • test_is_current_rpc_agent_set_import 测试用例: 验证 _is_current_rpc_agent_set 可从 torch._C._distributed_rpc 正常导入且为可调用对象。
  • test_is_current_rpc_agent_set_default 测试用例: 验证在RPC未初始化的默认状态下,_is_current_rpc_agent_set() 返回 False
  • test_is_current_rpc_agent_set_after_init 测试用例: 验证完整生命周期——init_rpc 后返回 Trueshutdown 后恢复为 False
likedislike
atomgit-bot
atomgit-bot
23 天前 评论:

代码审查

审查总结

已审查文件清单:

文件 结果
test/distributed/rpc/test_rpc_agent_set.py 发现 2 个问题

按严重度统计:P2 × 1,P3 × 1

整体风险评估:此变更新增了一个 RPC agent 状态查询 API 的验证测试。两个发现的问题均不涉及生产代码正确性——一个是测试内部的清理不完整(P2,可能导致级联测试失败),另一个是测试基础设施基类选择不一致(P3,可选改进)。总体风险较低,可在合入前修复 P2 问题。

类型 数量
🔴 阻塞 0
🟡 建议 1

💬 仅评论

likedislike
ascend-robotascend-robot成员
23 天前 添加了label:ascend-cla/no
此处折叠了78条消息 查看更多
chenrayray
chenrayray成员
7 天前 评论:

/lgtm

likedislike
ascend-robotascend-robot成员
7 天前 添加了label:lgtm
ascend-robotascend-robot成员
7 天前 删除了label:ci-pipeline-passed
ascend-robotascend-robot成员
7 天前 合入了pull request
ascend-robot
ascend-robot成员
7 天前 评论:
流水线 pytorch_gitcode_PR_multiVersion#14011 [ commitID:60b087d5 ] 已完成
likedislike