已合并
test(fx):Add validation cases for torch._C._distributed_rpc._is_current_rpc_agent_set on NPU #43172
test(fx):Add validation cases for torch._C._distributed_rpc._is_current_rpc_agent_set on NPU #43172
已合并
olpk创建于 7月29日
olpk
olpk
7月29日

关联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
7月29日 创建了 pull request,commit c015a669
atomgit-bot
atomgit-bot
7月29日 评论:

变更摘要

此 PR 为 NPU 平台新增了针对 torch._C._distributed_rpc._is_current_rpc_agent_set 接口的验证用例。由于 PyTorch 社区对该 API 缺乏直接且充分的测试覆盖,本次变更新增了独立的测试文件 test/distributed/rpc/test_rpc_agent_set.py,用以验证该 API 的可调用性、默认状态以及在 RPC 初始化/关闭后的状态变化。

主要改动

  • 新增测试文件 test/distributed/rpc/test_rpc_agent_set.py:为 torch._C._distributed_rpc._is_current_rpc_agent_set API 添加了三个测试用例,覆盖 API 可导入/可调用验证、未初始化 RPC 时的默认返回值验证,以及 init_rpcshutdown 后的状态切换验证。
  • 新增测试类 TestIsCurrentRpcAgentSet:继承自 TestCase,集中管理上述三个测试方法,分别为 test_is_current_rpc_agent_set_importtest_is_current_rpc_agent_set_defaulttest_is_current_rpc_agent_set_after_init,确保 RPC Agent 状态检测逻辑的正确性。
likedislike
不准确?
atomgit-bot
atomgit-bot
7月29日 评论:

代码审查

现在我已经完成了对所有 1 个变更文件的全面审查。以下是审查摘要:


审查摘要

变更文件审查结果

文件 结果
test/distributed/rpc/test_rpc_agent_set.py 发现 1 个问题(P2)

按严重度统计

  • P0: 0
  • P1: 0
  • P2: 1 — test_is_current_rpc_agent_set_after_init 缺少异常安全清理,断言失败时 rpc.shutdown() 不会被执行,导致 RPC agent 残留在主进程中
  • P3: 0

整体风险评估

低风险。该变更本质上是一个新增的测试文件,测试逻辑本身正确。唯一的问题是 test_is_current_rpc_agent_set_after_init 中缺少 try/finally 保护,当 self.assertTrue() 断言意外失败时会导致 RPC agent 未清理。这是一个可修复的测试健壮性问题,不影响生产代码。

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

💬 仅评论

likedislike
不准确?
ascend-robotascend-robot成员
7月29日 添加了label:ascend-cla/no
此处折叠了77条消息 查看更多
chenrayray
chenrayray成员
26 天前 评论:

/lgtm

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