已合并
workflow触发上游pytorch全量用例测试 #35958
kerer-sk创建于 5月18日
workflow触发上游pytorch全量用例测试 #35958
已合并
kerer-sk创建于 5月18日
kerer-sk
kerer-sk成员
5月18日

【合入来源】

【修改方案】

一、触发层

  1. torch-npu-upstream-test-trigger.yml — 入口触发器

触发方式:schedule(每日 UTC 11:00)+ workflow_dispatch(手动)

唯一的作用是接收触发事件,将参数(python_version、分片数、test_files 等)传递给下游主编排 workflow。本身不执行任何
job,只是一个可复用的参数入口。


二、编排层

  1. _torch-npu-upstream-test.yml — 主编排器

类型:workflow_call(被 trigger 调用)

定义了 7 个 job 的执行顺序和条件分支:

┌──────────────────┬───────────────────────────┬────────────────────┐
│ Job │ 依赖 │ 条件 │
├──────────────────┼───────────────────────────┼────────────────────┤
│ prepare │ 无 │ 总是执行 │
├──────────────────┼───────────────────────────┼────────────────────┤
│ build_torch_npu │ prepare │ 总是执行 │
├──────────────────┼───────────────────────────┼────────────────────┤
│ collect_cases │ prepare + build │ test_files 为空 │
├──────────────────┼───────────────────────────┼────────────────────┤
│ test_distributed │ prepare + build + collect │ test_files 为空 │
├──────────────────┼───────────────────────────┼────────────────────┤
│ test_regular │ prepare + build + collect │ test_files 为空 │
├──────────────────┼───────────────────────────┼────────────────────┤
│ test_custom │ prepare + build │ test_files 不为空 │
├──────────────────┼───────────────────────────┼────────────────────┤
│ report │ 所有以上 job │ always(),汇总输出 │
└──────────────────┴───────────────────────────┴────────────────────┘

两个执行路径:

  • 全量模式(默认):走 collect → distributed + regular 分片测试
  • 指定文件模式(手动触发传 test_files):跳过 collect,直接跑 custom 测试

三、执行层 — Workflow

  1. _torch-npu-upstream-prepare.yml — 准备测试源码
  • Clone 上游 PyTorch 源码(pytorch/pytorch)
  • 拷贝 test_upstream/ 补丁目录
  • 执行 apply_patch.sh 打 NPU 适配补丁
  • 打包并上传 patched 源码为 artifact
  • 输出 patch_count(补丁数量)供 report 使用
  1. _torch-npu-upstream-build.yml — 构建 torch_npu Wheel
  • 运行在 linux-aarch64-a3-2(ARM64 + NPU 构建机)
  • 在 Docker 容器内从源码编译 torch_npu
  • 使用 ccache 加速 C++ 编译
  • 上传构建产物 .whl 为 artifact
  • 输出 wheel_name 和 build_status
  1. _torch-npu-upstream-collect.yml — 收集并分片测试用例
  • 运行在 linux-aarch64-a3-8(8 卡 NPU 机器)
  • 调用 collect_all_cases.py 遍历 test/ 目录
  • 按 case_paths_ci.yml 配置将用例分为 distributed 和 regular 两类
  • 每类按分片数(默认 distributed=2, regular=5)拆成多个 JSON 文件
  • 输出 distributed_matrix / regular_matrix(JSON 数组,供 matrix strategy 使用)
  1. _torch-npu-upstream-test-dist.yml — 执行分布式测试
  • 运行在 linux-aarch64-a3-16(16 卡 NPU)
  • 使用 strategy.matrix 并行跑多个 shard(max-parallel: 2)
  • 每个 shard 调用 run_npu_test_shard.py,串行执行该分片内的用例
  • timeout: 1200 分钟(20 小时)
  • 失败时单独上传 error-logs
  1. _torch-npu-upstream-test-regular.yml — 执行常规测试
  • 运行在 linux-aarch64-a3-16(16 卡 NPU)
  • 使用 strategy.matrix 并行跑多个 shard(max-parallel: 5)
  • 每个 shard 调用 run_npu_test_shard.py,64 并发执行该分片内的用例
  • timeout: 1200 分钟
  1. _torch-npu-upstream-test-custom.yml — 执行指定文件测试
  • 运行在 linux-aarch64-a3-8
  • 不走 collect/shard 流程,直接对用户指定的文件执行测试
  • 单 job,无 matrix 并行
  1. _torch-npu-upstream-report.yml — 生成测试报告
  • 运行在 ubuntu-latest(普通 x86 runner,无需 NPU)
  • 下载所有 shard 的测试报告 artifact(distributed + regular + custom)
  • 调用 generate_npu_full_test_report.py 生成:
    • npu-full-test-summary.md — Markdown 报告
    • npu-full-test-summary.json — 结构化数据
  • 将 Markdown 追加到 GITHUB_STEP_SUMMARY

四、共享 Action

  1. setup-npu-test-env/action.yml — NPU 测试环境初始化

类型:composite action
被调用方:collect / test_distributed / test_regular / test_custom 四个 workflow

这是一个被多个测试 job 复用的环境准备步骤组合,包含:

  1. Checkout Ascend/pytorch 仓库(获取脚本和配置)
  2. pip 缓存(与 build job 共享 key)
  3. 下载并安装构建好的 torch_npu wheel
  4. 安装上游 PyTorch + triton-ascend
  5. 下载并解压 patched 测试源码
  6. 验证 NPU 设备可用性
  7. 安装测试依赖(requirements.txt, requirements-ci.txt)
  8. 执行 torch_env_patch.sh(环境级 NPU 适配脚本)

五、脚本层

  1. collect_all_cases.py — 用例收集与分片
  • 扫描 test/ 目录,根据 case_paths_ci.yml 配置归类用例
  • 将 distributed 和 regular 用例按指定分片数分配到不同 JSON 文件
  • 输出 cases_collection_summary.json 记录总数等统计信息
  1. run_npu_test_shard.py — 测试执行引擎
  • 两种模式:
    • 分片模式:读取 *_cases_shard_N.json,执行该分片内的所有用例
    • 文件模式:直接执行 --test-files 指定的文件
  • 支持串行/并发执行(--max-workers)
  • 支持 --disabled-testcases 黑名单跳过
  • 生成 JUnit XML 报告 + 单用例日志
  1. generate_npu_full_test_report.py — 报告生成
  • 聚合所有 shard 的测试结果 JSON
  • 生成 Markdown 摘要(通过率、失败列表、耗时统计等)
  • 生成按文件分组的 *_cases_results_by_file.jsonl
  1. discover_test_files.py — 测试文件发现
  • 扫描指定目录找出所有测试文件
  1. parse_test_results.py — 测试结果解析
  • 解析 JUnit XML 或测试输出日志,提取通过/失败/跳过统计

整体数据流

trigger.yml
│ schedule (每日) 或 workflow_dispatch (手动)

_torch-npu-upstream-test.yml (编排层,路由到两条路径之一)

├─ [路径A: test_files为空] 全量测试
│ prepare → build → collect → test_distributed (matrix并行)
│ → test_regular (matrix并行)
│ │
│ ▼
│ report (汇总)

└─ [路径B: test_files指定] 指定文件测试
prepare → build → test_custom → report (汇总)

每个测试 job 都通过 setup-npu-test-env action 统一初始化环境(装 wheel、装依赖、打补丁),保证一致性。

【资料变更】

不涉及

【接口变更】

不涉及

【功能验证】

https://github.com/Ascend/pytorch/actions/runs/25964865787
image.png

【CheckList】

PR提交人对以下CheckList自检项进行全量自检,自检通过或不涉及,均修改 [ ] 为 [x]

likedislike
Pull Request已成功合入, 合并人@ascend-robot
(感谢 kerer-sk 的贡献)
kerer-skkerer-sk成员
5月18日 创建了 pull request,commit 2392945d
ascend-robot
ascend-robot成员
5月18日 评论:

Thanks for your pull-request.
The full list of commands accepted by me can be found at here
You can get sig-info at here


PR Approval Progress

Congratulations! All modules have met the lgtm and approve requirements.

Module Approval Details

module lgtm status approve status
repo-Ascend/pytorch huangjingwei, liangsongwei (2/2) liangsongwei (1/1)
test huangjingwei, liangsongwei, sunyu-xuan (3/2) liangsongwei (1/1)
test_upstream liangsongwei, sunyu-xuan, huangjingwei (3/2) liangsongwei (1/1)

💡 Tip:

  • Committer can comment /approve or /lgtm
  • Commenting /approve implies both code review (lgtm) and intent to merge (approve)

CLA Signature Pass

kerer-sk, thanks for your pull request. All authors of the commits have signed the CLA. 👍

likedislike
ascend-robotascend-robot成员
5月18日 添加了label:ascend-cla/yes
ascend-robot
ascend-robot成员
5月18日 评论:

当前仓库存在以下 保护分支

Protected Branch Version Release
master
v2.7.1
v2.9.0
v2.11.0
v2.10.0
v2.12.0

评论 /sync <branch1> <branch2> ... 可将当前 PR 修改同步到其它分支(创建同步 PR):
a) 如果当前 PR 是 Open 状态,同步操作将延迟到 PR 被合并时执行
b) 如果当前 PR 已经 Merged,将立即执行同步操作

注意:

  1. /sync 命令可以指定同步到多个分支,仅最后一个 /sync 命令生效
  2. 如果创建的同步 PR 不正确,可通过向同步 PR 的源分支提交轻量级 PR 完善,或使用 /close 命令关闭
likedislike
此处折叠了92条消息 查看更多
kerer-skkerer-sk成员
5月19日 关联了issue:feat(ci): 新增workflow定时/手动触发 NPU 上游全量测试流水线
梁松伟
梁松伟成员
5月19日 评论:

/approve
/lgtm

likedislike
ascend-robotascend-robot成员
5月19日 添加了label:approvedlgtm
ascend-robot
ascend-robot成员
5月19日 评论:

Review Guide

This pull-request passes review.
Committers who wrote a comment of /approve are: liangsongwei.
Reviewers who wrote a comment of /lgtm are: liangsongwei, sunyu-xuan, huangjingwei.

likedislike
ascend-robotascend-robot成员
5月19日 合入了pull request