| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
test: adapt debug_set_autodiff_subgraph_inlining for NPU Co-authored-by: yulin520<yutianaoxiang@163.com> # message auto-generated for no-merge-commit merge: !41603 merge test-debug-set-autodiff-subgraph-inlining-npu-v271 into v2.7.1 test: adapt debug_set_autodiff_subgraph_inlining for NPU Created-by: weixin_65332823 Commit-by: yulin520 Merged-by: ascend-robot Description: # 〖合入来源〗 - [ ] 需求 - [ ] 问题单 - [x] issue/工单:#2850 - [ ] 重构优化 - [ ] 资料更新 Issue: text https://gitcode.com/Ascend/pytorch/issues/2850 # 〖修改方案〗 本 PR 针对 v2.7.1 分支,补充以下 PyTorch 官方社区测试用例的 NPU 适配 patch: text test/jit/test_autodiff_subgraph_slicing.py 提交文件: text test_upstream/test/jit/test_autodiff_subgraph_slicing.py.patch 涉及 API: python torch._C._debug_set_autodiff_subgraph_inlining 该接口用于控制 PyTorch JIT 自动微分子图的内联行为,属于 PyTorch 内部调试接口。 PyTorch 官方社区已经提供相关测试,因此本 PR 不新增独立测试文件,仅对现有官方测试进行必要的 NPU 设备适配,不修改 API 实现代码。 相关测试及适配位置主要位于 PyTorch v2.7.1 官方测试文件约: text 45、69、323、383、396、411 行附近 本次主要修改内容如下: 1. 保留 PyTorch 官方社区测试用例原有验证逻辑和断言; 2. 对两个默认创建在 CPU、需要参与 NPU 计算的外部输入 Tensor 使用 .npu() 迁移至 NPU; 3. 对 JIT 函数内部新建的 zeros/ones Tensor,使用已有输入 Tensor 的 device 创建,避免 CPU/NPU Tensor 混用; 4. import torch_npu # noqa: F401 按项目导入顺序放置在全部 torch.testing 相关导入之后; 5. 保留自动微分子图切分和内联行为相关检查; 6. 未新增 device_type; 7. 未增加额外 NPU 设备检测逻辑; 8. 未增加 torch-npu API 实现代码; 9. 未引入 transfer_to_npu 自动迁移; 10. 未修改 torch.jit.script 或 torch.jit.script_method; 11. patch 基于 PyTorch v2.7.1 官方源码修改后通过 git diff 生成。 本次实际设备适配方式包括: python inputs = [torch.randn(size).npu().requires_grad_() for size in input_sizes] python input = torch.rand(6, 10).npu().requires_grad_() 以及根据已有 Tensor 派生 device,例如: python torch.zeros(..., device=y.device) torch.zeros(..., device=a.device) torch.ones(..., device=y.device) v2.7.1 分支原已存在该测试文件的相关 patch。本 PR 基于对应版本 PyTorch 官方源码重新整理该 patch,在保留原有测试语义的基础上完成显式 NPU 设备适配。 具体提交内容以当前 PR 最新 commit 为准。 # 〖资料变更〗 不涉及。 该 API 完整名称为: python torch._C._debug_set_autodiff_subgraph_inlining 该接口位于 PyTorch 内部 torch._C 模块,属于 PyTorch 私有调试接口。 本 PR 未新增公开 API,也未修改用户可见接口,因此无需补充 torch-npu 公共 API 资料。 # 〖接口变更〗 不涉及。 本 PR 仅补充 PyTorch 官方社区测试用例的 NPU 适配 patch,不修改: text API 定义 API 参数 返回值 调用方式 API 实现 # 〖功能验证〗 ## 验证环境 已在以下匹配环境完成当前 PR 最新提交对应的 NPU Runtime 验证: text 操作系统:Linux(Ubuntu) 昇腾硬件:910B4 CANN 软件版本:8.5.0 目标分支:v2.7.1 PyTorch:2.7.1+cpu torch_npu:2.7.1.post2 npu available:True npu device count:1 Tensor device:npu:0 本次 Runtime 验证对应提交: text PR:#41603 HEAD SHA:afab36ae0d3367eb2e99e800371ac30180544a0c ## NPU Runtime 验证 已在真实 Ascend NPU 环境中执行与以下 API 相关的 PyTorch 官方测试: python torch._C._debug_set_autodiff_subgraph_inlining 运行前检查结果: text RUNTIME_TORCH=2.7.1+cpu RUNTIME_TORCH_NPU=2.7.1.post2 RUNTIME_NPU_AVAILABLE=True RUNTIME_PROBE_DEVICE=npu:0 TARGET_API_DIRECT_CALL=PASS PREFLIGHT=PASS GRAPH_EXECUTOR=ProfilingMode.PROFILING GRAPH_EXECUTOR_INIT=PASS TEST_MODULE_LOAD=PASS 本次连续执行与目标 API 相关的 11 个 PyTorch 官方测试场景: text RELATED_TEST_COUNT=11 RAN_TESTS=11 FAILURES=0 ERRORS=0 SKIPPED=0 EXPECTED_FAILURES=0 UNEXPECTED_SUCCESSES=0 测试完成后检查结果: text FINAL_STATE_RESET=PASS NPU_SYNCHRONIZE=PASS API24_RUNTIME_RESULT=PASS FINAL_RESULT=PASS 本次 Runtime 验证确认: 1. 目标 API 在 PyTorch v2.7.1 与 torch_npu 2.7.1.post2 匹配环境中可正常调用; 2. 实际测试 Tensor 位于 npu:0; 3. 与该 API 相关的 11 个 PyTorch 官方测试均已执行; 4. 11 个测试全部通过,无 failure、error 或 skip; 5. 测试结束后已恢复 _debug_set_autodiff_subgraph_inlining(True); 6. torch.npu.synchronize() 检查通过,未发现异步 NPU 错误; 7. Runtime 验证对应当前 PR 提交 afab36ae0d3367eb2e99e800371ac30180544a0c。 ## 最新 commit 静态检查 对当前最新 patch 已重新完成以下检查: text PATCH_SEMANTIC_CHECK=PASS PATCH_APPLY_CHECK=PASS PATCH_APPLY=PASS PY_COMPILE=PASS SOURCE_DIFF_CHECK=PASS IMPORT_ORDER=PASS PATCH_GIT_DIFF_ROUNDTRIP=PASS POST_COMMIT_WORKTREE=PASS COMMITTED_PATCH_MATCH=PASS 当前 patch 设备适配检查结果: text PATCH_TORCH_NPU_IMPORT=1 PATCH_NPU_CALLS=2 PATCH_DERIVED_DEVICE=4 PATCH_DEVICE_TYPE=0 其中: text torch_npu import:1 处 .npu():2 处 从已有 Tensor 派生 device:4 处 device_type:0 处 torch_npu 导入顺序检查结果: text torch → torch.testing... → torch_npu 已确认: text torch_npu 位于全部 torch.testing 相关导入之后 ## patch 应用检查 已在对应版本 PyTorch 官方源码上执行: bash git apply --check test_upstream/test/jit/test_autodiff_subgraph_slicing.py.patch 结果: text PASS 同时已将 patch 应用到对应 PyTorch 官方源码,并完成: text Python 语法检查:PASS 源码 git diff --check:PASS import 顺序 AST 检查:PASS patch git diff round-trip:PASS # 〖修改范围审计〗 本 PR 当前仅包含以下一个文件: text test_upstream/test/jit/test_autodiff_subgraph_slicing.py.patch 最新检查结果: text FINAL_COMMIT_COUNT=1 FINAL_CHANGED_FILES=test_upstream/test/jit/test_autodiff_subgraph_slicing.py.patch 审计结论: text Changed files:1 Commits:1 patch 仅修改 test/jit/test_autodiff_subgraph_slicing.py patch 不包含整文件删除 patch 不包含无关测试文件 patch 不包含日志、压缩包、环境文件或构建产物 同时确认: text 未引入 transfer_to_npu 未新增 device_type 未增加额外 NPU 检测逻辑 未修改 torch.jit.script 未修改 torch.jit.script_method 未修改 API 实现 # 〖验证结论〗 torch._C._debug_set_autodiff_subgraph_inlining 已在 PyTorch v2.7.1 与 torch_npu 2.7.1.post2 匹配环境中完成一致性验证。 当前结论如下: 1. PyTorch v2.7.1 中已存在该 API; 2. torch-npu 无需增加对应 API 实现; 3. PyTorch 官方社区已有相关测试用例,无需新增 Torch-NPU 原生测试文件; 4. 两个外部输入 Tensor 已按照最小修改原则使用 .npu() 迁移至 NPU; 5. JIT 函数内部新建 Tensor 使用已有输入 Tensor 的 device; 6. import torch_npu # noqa: F401 已位于全部 torch.testing 导入之后; 7. 未新增 device_type; 8. 未增加额外 NPU 检测逻辑; 9. 未引入 transfer_to_npu; 10. 未修改 PyTorch 官方测试原有核心逻辑和断言; 11. patch 基于对应版本 PyTorch 官方源码通过 git diff 生成; 12. patch 已通过对应 PyTorch 官方源码的 git apply --check; 13. patch 应用后的 Python 源码已通过语法和 whitespace 检查; 14. 当前 PR 保持单 commit; 15. 当前 PR 仅修改目标 patch 文件; 16. 已在当前 PR 提交对应的 Ascend 910B4 NPU 环境中完成 Runtime 验证; 17. 与目标 API 相关的 11 个 PyTorch 官方测试全部通过; 18. Runtime 结果为 11 个测试、0 failure、0 error、0 skip; 19. 实际测试 Tensor 位于 npu:0; 20. NPU_SYNCHRONIZE=PASS; 21. API24_RUNTIME_RESULT=PASS; 22. 该 API 为 PyTorch 私有调试接口,无需补充公开 API 资料。 # 〖CheckList〗 - [x] PR 标题已使用 test 类型标签 - [x] 已关联 Issue #2850 - [x] 已确认 PyTorch 官方社区存在相关测试用例 - [x] 已分析社区用例及 NPU 适配需求 - [x] 已确认无需新增 Torch-NPU 原生测试文件 - [x] 已检查测试用例中的 Tensor 使用场景 - [x] 两个外部输入 Tensor 已通过 .npu() 迁移至 NPU - [x] JIT 内部新建 Tensor 已使用已有 Tensor 的 device - [x] torch_npu 已位于全部 torch.testing 导入之后 - [x] 未新增不必要的 device_type - [x] 未增加额外 NPU 检测逻辑 - [x] 已在真实 NPU 环境中完成当前提交对应的 Runtime 验证 - [x] 已确认实际测试 Tensor 位于 npu:0 - [x] 已执行 11 个目标 API 相关 PyTorch 官方测试 - [x] 11 个相关测试全部通过 - [x] Runtime 中 failure、error、skip 均为 0 - [x] 已完成 NPU synchronize 检查 - [x] 已执行 git apply --check - [x] 已完成 patch 应用后的 Python 语法检查 - [x] 已完成 patch 应用后的源码 git diff --check - [x] 已完成 patch git diff round-trip 检查 - [x] 已检查 patch 不包含整文件删除 - [x] 已检查 patch 仅修改目标社区测试文件 - [x] 已确认当前 PR 仅包含一个任务 commit - [x] 已确认当前 PR 仅包含一个目标 patch 文件 - [x] 已确认未引入 transfer_to_npu - [x] 已确认未修改 JIT 方法 - [x] 已确认不涉及 API 实现代码 - [x] 已确认不涉及公开资料变更 - [x] 已确认不涉及公开接口变更 # 〖验证截图〗 ## NPU Runtime 验证 以下截图为当前 PR 提交对应的 Ascend 910B4 NPU Runtime 验证结果。 截图关键信息: text PR:#41603 目标版本:v2.7.1 HEAD:afab36ae0d3367eb2e99e800371ac30180544a0c PyTorch:2.7.1+cpu torch_npu:2.7.1.post2 Device:npu:0 Related tests:11 Ran tests:11 Failures:0 Errors:0 Skipped:0 NPU synchronize:PASS Runtime result:PASS Final result:PASS  以下截图为此前在匹配 Ascend 910B4 NPU 环境中的实际运行验证记录。  See merge request: Ascend/pytorch!41603 | 1 天前 | |
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 | 18 天前 | |
fix: apply_patch.sh 只应用 test/ 目录下的patch,跳过 torch/ 目录 Co-authored-by: wangsike<wangsike@huawei.com> # message auto-generated for no-merge-commit merge: !37974 merge fix/apply_patch_skip_torch_dir into v2.7.1 fix: apply_patch.sh 只应用 test/ 目录下的patch,跳过 torch/ 目录 Created-by: kerer-sk Commit-by: wangsike Merged-by: ascend-robot Description: ## 变更说明 修复 test_upstream/apply_patch.sh 错误将 torch/ 子目录下的环境 patch 应用到源码的问题。 test_upstream/ 目录下有两个 patch 子目录,用途不同: - **test/** — 给源码测试文件打的 patch,由 apply_patch.sh 负责应用 - **torch/** — 给安装到 Python 环境后的 torch 包打的 patch,由 torch_env_patch.sh 负责应用 原脚本 find "$PATCH_DIR" 扫描整个 test_upstream/ 目录,导致 torch/ 下的环境 patch 也被错误打到源码上。修复后只搜索 test/ 子目录。 ## 变更内容 - test_upstream/apply_patch.sh: 将 find "$PATCH_DIR" 改为 find "$PATCH_DIR/test",仅搜索源码测试 patch 目录 ## 关联 Issue Fixes https://gitcode.com/Ascend/pytorch/issues/2327 See merge request: Ascend/pytorch!37974 | 2 个月前 | |
refactor(ci): 精简依赖安装动作优化用例执行速度 Co-authored-by: wangsike<wangsike@huawei.com> # message auto-generated for no-merge-commit merge: !36940 merge v2.7.1_fast_test into v2.7.1 refactor(ci): 精简依赖安装动作优化用例执行速度 Created-by: kerer-sk Commit-by: wangsike Merged-by: ascend-robot Description: ## 变更说明 精简 CI 工作流中的 setup-npu-test-env 复合动作,去除冗余的 checkout、pip cache、PyTorch 安装步骤。这些依赖已在 Docker 镜像中预装,重复执行导致测试启动耗时过长。同时统一工作流中的仓库引用为 Ascend/pytorch。 ## 变更内容 - **精简 setup-npu-test-env**:移除 checkout 仓库、pip cache、PyTorch 卸载/重装步骤,仅保留下载 torch_npu wheel、解压测试源码、应用 patch 的核心逻辑 - **统一仓库引用**:将所有 workflow 中的仓库引用和 action 调用替换为 Ascend/pytorch - **同步适配测试工作流**:所有调用 setup-npu-test-env 的 workflow 同步更新参数接口 - **辅助脚本优化**:collect_all_cases.py 和 run_npu_test_shard.py 配套更新 - **简化 torch_env_patch.sh**:精简参数解析逻辑 - **更新 CI 测试用例列表**:添加 test_ops_jit.py、test_jit.py 到白名单,修正 test_alias_analysis.py.patch import 风格 ## 影响范围 15 files, +802/-776 ## 关联 Issue - Fixes https://gitcode.com/Ascend/pytorch/issues/2136 ## 测试计划 - [x] CI 流水线正常触发 - [x] prepare → build → collect → test 全链路通过 - [x] regular / distributed / custom 三类测试均正常运行 See merge request: Ascend/pytorch!36940 | 2 个月前 | |
test: update NPU max pooling upstream cases Co-authored-by: hz893<zhanghao491@huawei.com> # message auto-generated for no-merge-commit merge: !37153 merge codex/v271-pooling-doc-test-20260529 into v2.7.1 test: update NPU max pooling upstream cases Created-by: hz893 Commit-by: hz893 Merged-by: ascend-robot Description: <!-- PR描述模板更新日期:20260203 --> # 【合入来源】 > <font color="red">**如有社区issue,请关联issue链接**</font>> <font color="red">**请勿携带内部流程信息(需求链接、问题单、内部issue等)**</font> - [ ] 需求 - [x] 问题单 https://gitcode.com/Ascend/pytorch/issues/2205 - [ ] issue/工单 - [ ] 重构优化 - [x] 资料更新 # 【修改方案】 1. 更新 test_ops.py.patch,对 NPU pooling indices 输出在测试侧按期望 dtype 做对齐后比较,并对 nn.functional.max_pool2d 非连续样本过滤当前 NPU 不支持的 memory format 与 dilation 样本。 2. 更新 test_pooling.py.patch,在 max_pool2d indices 对比前将 NPU indices 转为参考输出 dtype。 3. 新增 test_decomp.py.patch,引入 torch_npu.testing 以使 disabled_testcases.json 对 test_decomp.py 生效。 4. 更新 disabled_testcases.json,对当前 NPU 不支持的 int64、float64、dilation/format 场景补充 skip 及原因;FakeTensor 相关用例同步记录 OpInfo 拦截及 disabled json 不生效的原因。 5. 更新 2.7.1、2.9.0、2.10.0、2.11.0、2.12.0 中文原生 API 文档,补充 max_pool1d 支持情况,以及 max_pool1d/max_pool2d 的兼容实现、dilation 与 indices dtype 说明。 # 【资料变更】 涉及资料变更:更新 docs/zh/native_apis/pytorch_2-7-1、pytorch_2-9-0、pytorch_2-10-0、pytorch_2-11-0、pytorch_2-12-0 下 torch-nn-functional.md 中 torch.nn.functional.max_pool1d 和 torch.nn.functional.max_pool2d 的支持说明。 # 【接口变更】 不涉及。 # 【功能验证】 1. 基于 PyTorch v2.7.1 原始测试文件,对 test_ops.py.patch、test_pooling.py.patch、test_decomp.py.patch 执行 git apply --check 并实际 apply,结果通过。 2. 执行 python3 -m json.tool test_upstream/disabled_testcases.json,JSON 格式检查通过。 3. 前置验证中使用兼容性环境变量执行 17 个相关 pooling 用例,结果为 3 PASS / 14 SKIP / 0 FAIL,符合当前预期。 # 【CheckList】 > PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x] - [ ] 代码注释完备,正确记录错误日志 - [ ] 代码实现进行了返回值、空指针等校验 - [x] PR标题正确使用类型标签,如:feat、fix、refactor、docs、test等 - [ ] PR持续集成流水线(CI)执行通过,代码检查无异常 See merge request: Ascend/pytorch!37153 | 1 个月前 | |
doc: readme.md 补充 torch_env_patch.sh 使用说明 Co-authored-by: wangsike<wangsike@huawei.com> # message auto-generated for no-merge-commit merge: !38071 merge fix/readme-add-torch-env-patch-doc into v2.7.1 doc: readme.md 补充 torch_env_patch.sh 使用说明 Created-by: kerer-sk Commit-by: wangsike Merged-by: ascend-robot Description: ## 变更说明 test_upstream/readme.md 当前只介绍了 apply_test_patch.sh,缺少对 torch_env_patch.sh 的说明。补充完整文档。 ## 变更内容 - test_upstream/readme.md: - 目录结构中区分 test/(源码测试 patch)和 torch/(环境 torch 包 patch)子目录 - 新增两个脚本职责对照表 - 新增 torch_env_patch.sh 的环境要求和使用方法 - 注意事项中明确两个脚本相互独立 ## 关联 Issue Fixes https://gitcode.com/Ascend/pytorch/issues/2343 See merge request: Ascend/pytorch!38071 | 1 个月前 | |
refactor(ci): 精简依赖安装动作优化用例执行速度 Co-authored-by: wangsike<wangsike@huawei.com> # message auto-generated for no-merge-commit merge: !36940 merge v2.7.1_fast_test into v2.7.1 refactor(ci): 精简依赖安装动作优化用例执行速度 Created-by: kerer-sk Commit-by: wangsike Merged-by: ascend-robot Description: ## 变更说明 精简 CI 工作流中的 setup-npu-test-env 复合动作,去除冗余的 checkout、pip cache、PyTorch 安装步骤。这些依赖已在 Docker 镜像中预装,重复执行导致测试启动耗时过长。同时统一工作流中的仓库引用为 Ascend/pytorch。 ## 变更内容 - **精简 setup-npu-test-env**:移除 checkout 仓库、pip cache、PyTorch 卸载/重装步骤,仅保留下载 torch_npu wheel、解压测试源码、应用 patch 的核心逻辑 - **统一仓库引用**:将所有 workflow 中的仓库引用和 action 调用替换为 Ascend/pytorch - **同步适配测试工作流**:所有调用 setup-npu-test-env 的 workflow 同步更新参数接口 - **辅助脚本优化**:collect_all_cases.py 和 run_npu_test_shard.py 配套更新 - **简化 torch_env_patch.sh**:精简参数解析逻辑 - **更新 CI 测试用例列表**:添加 test_ops_jit.py、test_jit.py 到白名单,修正 test_alias_analysis.py.patch import 风格 ## 影响范围 15 files, +802/-776 ## 关联 Issue - Fixes https://gitcode.com/Ascend/pytorch/issues/2136 ## 测试计划 - [x] CI 流水线正常触发 - [x] prepare → build → collect → test 全链路通过 - [x] regular / distributed / custom 三类测试均正常运行 See merge request: Ascend/pytorch!36940 | 2 个月前 |
Patch 批量应用脚本使用说明
目录结构
-
核心仓库地址
- 官方 PyTorch 仓库(v2.7.1 版本),需拉取该仓库并切换至 tags/v2.7.1 标签。
- 补丁仓库(Ascend/pytorch),仅需提取该仓库中的 patch 目录。
-
核心目录结构
pytorch/ # PyTorch 源码根目录
├─ ...(其他 PyTorch 原生文件/目录)
└─ test_upstream/ # 补丁目录
├─ apply_test_patch.sh # 源码测试 patch 批量应用脚本
├─ torch_env_patch.sh # 环境 torch 包 patch 应用脚本
├─ test/ # 源码测试用例 patch 文件
├─ torch/ # 环境 torch 安装包 patch 文件
└─ ...(其他补丁子目录)
脚本说明
本目录包含两类 patch,分别由不同脚本负责应用:
| 脚本 | patch 目录 | 应用目标 |
|---|---|---|
apply_test_patch.sh |
test/ |
PyTorch 源码中的测试文件 |
torch_env_patch.sh |
torch/ |
Python 环境中安装的 torch 包 |
两个脚本相互独立,互不干扰。
环境要求
apply_test_patch.sh:仅需安装 gittorch_env_patch.sh:需要 Python 环境已安装 torch 包
使用方法
apply_test_patch.sh —— 源码测试 patch
将 test/ 目录下的 patch 应用到 PyTorch 源码中的测试文件。
- 将本仓库的 test_upstream 文件夹整体复制到 PyTorch 官方仓库中
- 运行脚本:
cd test_upstream
./apply_test_patch.sh
脚本自动定位 PyTorch 根目录,递归扫描 test/ 目录下所有 .patch/.diff 文件,按文件名排序强制应用,冲突部分生成 .rej 文件。
torch_env_patch.sh —— 环境 torch 包 patch
将 torch/ 目录下的 patch 应用到 Python 环境中已安装的 torch 包(如 site-packages/torch)。
- 确保 Python 环境已安装 torch 包
- 运行脚本:
cd test_upstream
./torch_env_patch.sh [--python=<version>]
脚本自动定位 torch 包的安装路径,将 torch/ 目录下的 patch 应用到对应文件。
注意事项
- 所有补丁仅适配 PyTorch tags/v2.7.1,其他版本将导致应用失败,务必提前校验版本。
- test_upstream 目录需整体复制至 PyTorch 根目录。
apply_test_patch.sh仅应用test/下的 patch 到源码,不会触碰torch/目录。torch_env_patch.sh仅应用torch/下的 patch 到安装后的 torch 包,不会触碰test/目录。- 生成 .rej 冲突文件时,需手动解决冲突后重新执行脚本。