| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
test(npu): adapt FakeStore test path for NPU Co-authored-by: whirlpool_dark<kk2425597323@126.com> # message auto-generated for no-merge-commit merge: !41805 merge test-fake-store-npu-v2.7.1 into v2.7.1 test(npu): adapt FakeStore test path for NPU Created-by: whirlpool_dark Commit-by: whirlpool_dark Merged-by: ascend-robot Description: # test(npu): adapt FakeStore test path for NPU 【合入来源】 [[Usage]: API一致性说明:torch.testing._internal.distributed.fake_pg.FakeStore 功能验证说明](https://gitcode.com/Ascend/pytorch/issues/2094) 【修改方案】 torch.testing._internal.distributed.fake_pg.FakeStore 是 fake process group 的内部 torch.distributed.Store。本 PR 复用 PyTorch 官方 test/distributed/test_fake_pg.py::TestFakePG.test_reduce_scatter(v2.7.1 第 54 行),调用路径为: text test.distributed.test_fake_pg.TestFakePG.test_reduce_scatter -> torch.testing._internal.distributed.fake_pg.FakeStore() -> torch.distributed.init_process_group(backend="fake", store=store) -> torch.testing._internal.distributed.fake_pg._create_fake_pg(...) -> torch.testing._internal.distributed.fake_pg.FakeProcessGroup -> torch.distributed.reduce_scatter(...) 1. 在 test_upstream/torch/testing/_internal/distributed/fake_pg.py.patch 的 fake backend devices 中追加 "npu",保留原有 "cpu"、"cuda"。该声明是 fake backend 接受 NPU 张量路径的必要条件。 2. 在 test_upstream/test/distributed/test_fake_pg.py.patch 中仅将该用例的 torch.ones、torch.empty 改为 .npu(),使 reduce_scatter 的输入、输出均在 NPU。 3. v2.7.1 历史 patch 曾移除 CUDA 注册,并引入 transfer_to_npu、FSDP/tracing 等无关改动;本次恢复上游 CUDA 行为,只保留 FakeStore 调用路径所需修改。该导入涉及额外行为,根据规范并保持各版本适配一致性进行删除。 4. 增加断言验证 FakeStore 的 torch.distributed.Store 类型、实际 backend 为 fake,并确认全部输入 Tensor 和输出 Tensor 位于 NPU,同时保留输出 shape 检查。FakeProcessGroup 按设计不执行真实通信,也不保证 collective 数值结果,因此不增加超出其契约的数值断言。 【资料变更】 torch.testing._internal.distributed.fake_pg.FakeStore 为 PyTorch 私有测试基础设施,不需要更新 native API 支持文档。 【接口变更】 不涉及用户接口,仅补充内部 fake backend 的 NPU 测试声明和官方用例适配。 【功能验证】 两份 patch 已通过 git apply --check;应用后的 fake_pg.py 和 test_fake_pg.py 已通过 python3 -m py_compile。NPU 云算力运行日志如下: text torch=2.7.1 torch_npu=2.7.1.post2 accelerator=npu [root@7cdbc2c6aa6a workspace]# python3 ./pytorch-official-2.7.1/test/distributed/test_fake_pg.py TestFakePG.test_reduce_scatter . ---------------------------------------------------------------------- Ran 1 test in 0.941s OK 【CheckList】 - [x] 代码注释简洁且为英文 - [x] patch 由 git diff 生成 - [x] PR 标题使用 test 标签 - [ ] CI 执行通过 See merge request: Ascend/pytorch!41805 | 1 个月前 |