已合并
test(fx):Add validation cases for torch._C._distributed_rpc._is_current_rpc_agent_set on NPU #43172
olpk创建于 7月29日
test(fx):Add validation cases for torch._C._distributed_rpc._is_current_rpc_agent_set on NPU #43172
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 olpk 的贡献)atomgit-bot
7月29日 评论:
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_setAPI 添加了三个测试用例,覆盖 API 可导入/可调用验证、未初始化 RPC 时的默认返回值验证,以及init_rpc与shutdown后的状态切换验证。 - 新增测试类
TestIsCurrentRpcAgentSet:继承自TestCase,集中管理上述三个测试方法,分别为test_is_current_rpc_agent_set_import、test_is_current_rpc_agent_set_default和test_is_current_rpc_agent_set_after_init,确保 RPC Agent 状态检测逻辑的正确性。


不准确?
ascend-robot
7月29日 评论:
7月29日 评论:
atomgit-bot
7月29日 评论:
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 |
💬 仅评论


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


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


关联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 个测试方法:适配方案
该 API 为框架层 RPC 状态查询接口,与底层设备无关,直接可用,无需 NPU 适配。
运行结果
NPU Ascend910B4 环境测试通过:
