已合并
test(fx):Add validation cases for torch._C._distributed_rpc._is_current_rpc_agent_set on NPU #43170
olpk创建于 7月29日
test(fx):Add validation cases for torch._C._distributed_rpc._is_current_rpc_agent_set on NPU #43170
已合并
Pull Request已成功合入, 合并人@ascend-robot
(感谢 olpk 的贡献)7月29日 关联了issue:【社区任务】7月社区任务第一期-Ascend for PyTorch API 一致性开发(26),torch._C._distributed_rpc._is_current_rpc_agent_set API 一致性补齐
7月29日 关联了issue:【社区任务】7月社区任务第一期-Ascend for PyTorch API 一致性开发(26),torch._C._distributed_rpc._is_current_rpc_agent_set API 一致性补齐
atomgit-bot
7月29日 评论:
7月29日 评论:
变更摘要
此 PR 新增测试文件 test/distributed/rpc/test_rpc_agent_set.py,为 torch._C._distributed_rpc._is_current_rpc_agent_set API 补充验证用例。该 API 原本在 PyTorch 社区中没有直接测试用例,此次新增针对 NPU 环境的验证,覆盖 API 可导入性、默认状态及 RPC 初始化/关闭后的状态变化。
主要改动
- 新增测试类
TestIsCurrentRpcAgentSet:继承自TestCase,包含三个测试方法,用于全面验证_is_current_rpc_agent_set的行为。 - 新增
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:验证调用rpc.init_rpc后_is_current_rpc_agent_set()返回True,调用rpc.shutdown后恢复为False。


不准确?
ascend-robot
7月29日 评论:
7月29日 评论:
atomgit-bot
7月29日 评论:
7月29日 评论:
代码审查
审查总结
已审查文件:
test/distributed/rpc/test_rpc_agent_set.py— 发现 2 个问题
问题按优先级统计:
| 优先级 | 数量 |
|---|---|
| P0 | 0 |
| P1 | 0 |
| P2 | 1 |
| P3 | 1 |
总体风险判断: 低风险。核心问题是 test_is_current_rpc_agent_set_after_init 中缺少 try/finally 保护,在断言失败时会导致 RPC agent 资源泄漏并污染后续测试。这是一个测试健壮性问题,不影响生产代码。建议在合入前用 try/finally 包裹 shutdown() 调用,即可消除该风险。
| 类型 | 数量 |
|---|---|
| 🔴 阻塞 | 0 |
| 🟡 建议 | 1 |
💬 仅评论


不准确?
此处折叠了76条消息 查看更多
chenrayray
24 天前 评论:
24 天前 评论:
/lgtm


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


关联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 环境测试通过:
