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

关联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
21 天前 创建了 pull request,commit 7db7be15
atomgit-bot
atomgit-bot
21 天前 评论:

变更摘要

此 PR 新增 NPU 平台下针对 torch._C._distributed_rpc._is_current_rpc_agent_set API 的验证测试用例,补充社区 PyTorch 对该接口覆盖不足的问题。新增的测试文件包含可导入性校验、默认状态校验以及完整的 RPC 初始化/关闭生命周期验证。

主要改动

  • 新增测试文件 test/distributed/rpc/test_rpc_agent_set.py:为 torch._C._distributed_rpc._is_current_rpc_agent_set 创建独立的测试类 TestIsCurrentRpcAgentSet,继承自 TestCase,共包含 3 个测试用例。
  • 可导入性与可调用性校验test_is_current_rpc_agent_set_import 验证 _is_current_rpc_agent_set 可从 torch._C._distributed_rpc 正常导入且为可调用对象。
  • 默认状态验证test_is_current_rpc_agent_set_default 验证在 RPC 未初始化时,该接口返回 False
  • 完整生命周期验证test_is_current_rpc_agent_set_after_init 覆盖 init_rpc 后返回 Trueshutdown 后恢复为 False 的完整状态变迁过程。
likedislike
atomgit-bot
atomgit-bot
21 天前 评论:

代码审查

审查总结

本次变更在 test/distributed/rpc/test_rpc_agent_set.py 中新增了 53 行测试代码,共审查 1 个文件,发现 2 个 P2 级别问题,无 P0/P1 问题。

优先级 数量 说明
P0 0 -
P1 0 -
P2 2 RPC agent 状态泄漏 + CI 报告缺失
P3 0 -

审查文件清单

  • test/distributed/rpc/test_rpc_agent_set.py:发现 2 个问题(详见上述记录)

整体风险评估:中等

两个 P2 问题均涉及测试基础设施的健壮性:try/finally 缺失可能导致级联测试失败和资源泄漏,Test Case 基类不一致可能导致 CI 测试报告缺失。建议合入前修复这两个问题。测试逻辑本身的正确性无问题。

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

💬 仅评论

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

/lgtm

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