已合并
test(fx):Add validation cases for torch._C._distributed_rpc._is_current_rpc_agent_set on NPU #43170
test(fx):Add validation cases for torch._C._distributed_rpc._is_current_rpc_agent_set on NPU #43170
已合并
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 bd8b9fee
olpkolpk
7月29日 关联了issue:【社区任务】7月社区任务第一期-Ascend for PyTorch API 一致性开发(26),torch._C._distributed_rpc._is_current_rpc_agent_set API 一致性补齐
atomgit-bot
atomgit-bot
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
likedislike
不准确?
atomgit-bot
atomgit-bot
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

💬 仅评论

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

/lgtm

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