已合并
[feat]新增一站式平台verl-torchtitan qwen1.7B SFT训练样例 #158
[feat]新增一站式平台verl-torchtitan qwen1.7B SFT训练样例 #158
已合并
horizon_C创建于 7月23日
horizon_C
7月23日

主要变更包括:

  1. 新增 Qwen3_1.7B TorchTitan SFT 训练样例
  • 新增 llm_sft/qwen3_1.7B_torchtitan 目录,提供基于 TorchTitan-NPU 的 Qwen3-1.7B SFT 完整训练流程。
  • 包含环境构建脚本、训练启动脚本以及相关配置文件,支持在 NPU 环境下一键启动 SFT 训练。
  • 提供从模型权重准备、数据集下载、训练启动到 checkpoint 导出的完整流程。
  1. 训练验证流程
  • 增加训练完成后的 checkpoint 推理验证流程。
  • 提供基于 infer_server 的模型部署方式,支持通过 API 进行推理测试。
  • 集成 vf-eval 评测工具,对 Wordle 环境下模型输出格式、reward 以及任务完成能力进行评估。

类型

Checklist:

likedislike
Pull Request已成功合入, 合并人@CANN-robot
(感谢 horizon_C 的贡献)
atomgit-bot
atomgit-bot
7月23日 评论:

变更摘要

本次 PR 新增了基于 TorchTitan-NPU 的 Qwen3-1.7B SFT 一站式训练样例,主要包含两个环境构建脚本:build_project_platform.sh 用于搭建 TorchTitan-NPU 训练平台及其 Python 依赖,setup_prime_rl.sh 用于安装 Prime-RL Wordle 游戏环境与 vf-eval 评测工具,为后续完整的 SFT 训练→推理验证→评测流程提供基础环境支持。

主要改动

  • 新增 build_project_platform.sh 训练平台构建脚本:克隆 torchtitan-npu 仓库,加载 CANN 9.1.0 环境,安装 torchtitantriton-ascendsafetensors 等核心训练依赖,并固定 pyarrow==21.0.0 版本,同时安装 uvopenaitextarena==0.7.4 等辅助工具。
  • 新增 setup_prime_rl.sh 评测环境安装脚本:克隆 prime-rl 仓库并锁定至特定 commit 188192ce,以独立 commit d822f6a 拉取 verifiers 依赖,通过 uv 为 Wordle verifier 创建独立虚拟环境并安装 verifiers 及 Wordle 环境包,最终验证 vf-eval 命令行工具可用。
  • 采用 uv 包管理器管理依赖:在两个脚本中均使用 uvuv venvuv pip install)替代传统 pip 进行环境隔离与包安装,并配置清华镜像源加速下载。
likedislike
atomgit-bot
atomgit-bot
7月23日 评论:

代码审查

审查总结

按文件逐一审查结果:

文件 审查结果
README.md 1 个 P1 问题:第 42 行 torchtitan 样例链接路径多了一层 qwen3_1.7B_torchtitan/ 目录,导致 404
llm_sft/qwen3_1.7B_torchtitan/README.md 无问题
llm_sft/qwen3_1.7B_torchtitan/README_EN.md 无问题
llm_sft/qwen3_1.7B_torchtitan/build_project_platform.sh 2 个 P3 问题:依赖版本 pin 不一致(第 19 行)、冗余 cd 硬编码路径未复用 $repo 变量(第 11 行)
llm_sft/qwen3_1.7B_torchtitan/setup_prime_rl.sh 1 个 P2 问题:文件末尾缺少换行符(第 35 行)

统计:P1 × 1,P2 × 1,P3 × 2,合计 4 个问题。

整体风险评估:该 PR 引入的变更整体风险中低。最需要关注的是主 README 中的断链(P1),会导致用户无法从首页导航到新增的 torchtitan 训练文档,建议合并前修复。Shell 脚本方面代码质量尚可(均启用了 set -euo pipefail),无安全硬编码密钥、无命令注入等高风险问题;存在的 P2/P3 问题属于健壮性和可复现性改进范畴,不影响基本功能运行。

类型 数量
🔴 阻塞 1
🟡 建议 4

⛔ 需要修改

likedislike
CANN-robotCANN-robot成员
7月23日 添加了label:cann-cla/no
CANN-robot
CANN-robot成员
7月23日 评论:

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-cann/cann-recipes-train xuyujun, 张德鹏 (2/2) xuyujun (1/1)

💡 Tip:

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

CLA Signature Pass

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

likedislike
CANN-robotCANN-robot成员
7月23日 将xbjlu,lrwei0709,huangwayne28,zhanghz1,depeng1994,zhangky_gitcode,lianghengyi,LiuXinxin23,fafahan,xuyujun,panchao-gitcode设为评审人
CANN-robotCANN-robot成员
7月23日 将xbjlu,lrwei0709,huangwayne28,zhanghz1,depeng1994,zhangky_gitcode,lianghengyi,LiuXinxin23,fafahan,xuyujun,panchao-gitcode设为审查人
Hhorizon_C
7月23日 修改了pull request 的描述
horizon_C
7月23日 评论:

/check-cla

likedislike
CANN-robotCANN-robot成员
7月23日 删除了label:cann-cla/no
CANN-robotCANN-robot成员
7月23日 添加了label:cann-cla/yes
atomgit-bot
atomgit-bot7月23日进行代码检视1
llm_sft/qwen3_1.7B_torchtitan/README.md
@@ -0,0 +250,4 @@
250+| `--api-base-url` | inference server 地址 |
251+| `--max-concurrent` | 串行请求(避免单线程服务器过载)|
252+| `--temperature` | 生成采样温度 |
253+| `--save-results` | 保存评测结果 |
atomgit-bot
atomgit-bot7月23日评论:

🟡 Medium Priority

vf-eval wordle 命令块的最后一行,--save-results \ 包含一个尾部反斜杠 \,它是 shell 的续行符。当用户复制整个代码块并粘贴到终端时,shell 会将反斜杠解释为"下一行还有命令",从而显示 > 提示符等待更多输入,导致命令无法正常执行。用户必须手动删除反斜杠或按 Ctrl-C 中断。该问题同时存在于中英文两个 README 文件中。

建议:将 --save-results \ 末尾的反斜杠去除,改为 --save-results。同时修复 README_EN.md 中相同的问题(第 251 行)。

likedislike
atomgit-bot
atomgit-bot7月23日进行代码检视2
llm_sft/qwen3_1.7B_torchtitan/README_EN.md
已过期
@@ -0,0 +248,4 @@
248+--max-concurrent 1 \
249+--verbose \
250+--temperature 0.6 \
251+--save-results \
atomgit-bot
atomgit-bot7月23日评论:

🟡 Medium Priority

vf-eval wordle 命令块的最后一行,--save-results \ 包含一个尾部反斜杠 \,它是 shell 的续行符。当用户复制整个代码块并粘贴到终端时,shell 会将反斜杠解释为"下一行还有命令",从而显示 > 提示符等待更多输入,导致命令无法正常执行。该问题与 README.md 中的问题相同,在两个文件中同时存在。

建议:将 --save-results \ 末尾的反斜杠去除,改为 --save-results

改动建议
251
- --save-results \
251
+ --save-results
应用建议
likedislike
System
系统消息系统
7月23日 评论:

changed this line on a503a8de view diff detail

atomgit-bot
atomgit-bot7月23日进行代码检视2
llm_sft/qwen3_1.7B_torchtitan/build_project_platform.sh
已过期
@@ -0,0 +2,4 @@
2+ 
3+# 可以用这个变量自定义下载路径。
4+repo=/mnt/workspace/cann-recipes-train/llm_sft/qwen3_1.7B_torchtitan/torchtitan-npu
5+git clone https://gitcode.com/cann/torchtitan-npu.git "$repo"
atomgit-bot
atomgit-bot7月23日评论:

🟡 Medium Priority

build_project_platform.sh 第 5 行直接执行 git clone … "$repo",但脚本顶部设置了 set -euo pipefail。如果目标目录 $repo 已经存在(例如上一次运行中途失败、用户重新运行),git clone 会因目录已存在而报错退出,导致整个脚本无法继续执行。用户需要手动删除目录后才能重试,降低了"一站式快速启动"的易用性。

触发条件:用户在执行此脚本中途遇到错误(如 pip 安装网络超时),再次运行脚本时触发。

建议:在 git clone 前增加目录状态检查,若目录已是有效的 git 仓库则跳过 clone。

likedislike
System
系统消息系统
7月23日 评论:

changed this line on a503a8de view diff detail

atomgit-bot
atomgit-bot7月23日进行代码检视2
README.md
已过期
@@ -40,2 +40,3 @@
40-|[Qwen3-1.7B SFT训练样例](llm_sft/qwen3/README.md#一站式平台快速启动sft训练示例) |在一站式平台Atlas A2/A3环境中完成Qwen3-1.7B 单卡SFT训练。|
40+|[Qwen3-1.7B 基于mindspeed SFT训练样例](llm_sft/qwen3/README.md#一站式平台快速启动sft训练示例) |在一站式平台Atlas A2/A3环境中完成Qwen3-1.7B 单卡SFT训练。|
4141|[Qwen2.5-1.5B RL训练样例](llm_rl/qwen2_5/verl_npu_demo/README_single.md) |在一站式平台Atlas A2/A3环境中基于verl框架完成Qwen2.5-1.5B-Instruct 单卡RL训练。|
42+|[Qwen3-1.7B 基于torchtitan SFT训练样例](llm_sft/qwen3_1.7B_torchtitan/qwen3_1.7B_torchtitan/README.md) |在一站式平台Atlas A2/A3环境中完成Qwen3-1.7B 单卡SFT训练。|
atomgit-bot
atomgit-bot7月23日评论:

🟠 High Priority

变更行(README.md 第 42 行)新增的链接路径为 llm_sft/qwen3_1.7B_torchtitan/qwen3_1.7B_torchtitan/README.md,但实际 README 文件位于 llm_sft/qwen3_1.7B_torchtitan/README.md(无重复的 qwen3_1.7B_torchtitan/ 子目录)。用户从主 README 点击该链接会得到 404,无法访问新增的 torchtitan SFT 训练样例文档。

证据:list_directory 确认 llm_sft/qwen3_1.7B_torchtitan/ 目录下直接包含 README.md,不存在名为 qwen3_1.7B_torchtitan 的子目录。

建议:将链接路径中的重复目录段移除,改为 llm_sft/qwen3_1.7B_torchtitan/README.md

改动建议
42
- |[Qwen3-1.7B 基于torchtitan SFT训练样例](llm_sft/qwen3_1.7B_torchtitan/qwen3_1.7B_torchtitan/README.md) |在一站式平台Atlas A2/A3环境中完成Qwen3-1.7B 单卡SFT训练。|
42
+ |[Qwen3-1.7B 基于torchtitan SFT训练样例](llm_sft/qwen3_1.7B_torchtitan/README.md) |在一站式平台Atlas A2/A3环境中完成Qwen3-1.7B 单卡SFT训练。|
应用建议
likedislike
System
系统消息系统
7月23日 评论:

changed this line on a503a8de view diff detail

atomgit-bot
atomgit-bot7月23日进行代码检视2
llm_sft/qwen3_1.7B_torchtitan/setup_prime_rl.sh
已过期
@@ -0,0 +32,4 @@
32+echo '=== 验证 ==='
33+echo "vf-eval: $(which vf-eval)"
34+echo "prime-rl revision: $(git rev-parse HEAD)"
35+echo "verifiers revision: $(git -C deps/verifiers rev-parse HEAD)"
atomgit-bot
atomgit-bot7月23日评论:

🟡 Medium Priority

setup_prime_rl.sh 第 35 行(文件最后一行)echo "verifiers revision: $(git -C deps/verifiers rev-parse HEAD)" 之后没有换行符。POSIX 标准要求文本文件的每一行(包括最后一行)以换行符结尾。缺少末尾换行符可能导致:某些 shell 解析器忽略最后一行、wc -l 计数偏少、git diff 等工具产生警告,以及拼接脚本时出现语法错误。

建议:在文件末尾添加一个换行符。

likedislike
System
系统消息系统
7月23日 评论:

changed this line on a503a8de view diff detail

Hhorizon_C
7月23日 强制推送  1 个提交:a503a8de-[feat]新增一站式平台verl-torchtitan qwen1.7B SFT训练样例
CANN-robotCANN-robot成员
7月23日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7月23日 评论:

流水线任务触发成功
任务链接 [e7a2a28650cb4c86a6191dcb694bda56][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
Check_Pr ✅ SUCCESS >>>>>
Check_Patches ✅ SUCCESS >>>>>
codecheck_codestyle ✅ SUCCESS >>>>>
precommit ⚠️ WARNING >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>

[2026-07-23 11:04:55]    CI执行结束

likedislike
CANN-robotCANN-robot成员
7月23日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
7月23日 添加了label:ci-pipeline-passed
Hhorizon_C
7月23日 修改了pull request 的描述
张德鹏成员
7月24日 评论:

/lgtm

likedislike
xuyujun成员7月24日进行代码检视2
llm_sft/qwen3_1.7B_torchtitan/build_project_platform.sh
已过期
@@ -0,0 +13,4 @@
13+echo "Repo: $repo"
14+echo "Branch: $branch"
15+ 
16+cd /mnt/workspace/cann-recipes-train/llm_sft/qwen3_1.7B_torchtitan/torchtitan-npu
xuyujun7月24日评论:

readme里没强调要克隆仓库到/mnt/workspace/,这里直接强制切换目录可能会失败,可以继续使用$repo

likedislike
System
系统消息系统
7月24日 评论:

changed this line on 3483423f view diff detail

xuyujun成员7月24日进行代码检视1
llm_sft/qwen3_1.7B_torchtitan/build_project_platform.sh
@@ -0,0 +6,4 @@
6+if [ -d "$repo/.git" ]; then
7+ echo "Using existing repository: $repo"
8+else
9+ git clone https://gitcode.com/cann/torchtitan-npu.git "$repo"
xuyujun7月24日评论:

上游主干并不稳定,建议当前锚定一个commit点?否则后续主线升级,当前脚本可能失效

likedislike
xuyujun成员7月24日进行代码检视5
llm_sft/qwen3_1.7B_torchtitan/build_project_platform.sh
已过期
@@ -0,0 +22,4 @@
22+pip install --user --force-reinstall --no-deps \
23+ "pyarrow==21.0.0"
24+pip install -U uv openai mcp httpx tenacity textarena==0.7.4
25+export UV_CACHE_DIR=/tmp/uv-cache
xuyujun7月24日评论:

这个环境变量有啥 意义吗?

likedislike
horizon_C
7月24日 评论:

UV_CACHE_DIR 是 uv 包管理工具的缓存目录

在后续执行setup_prime_rl.sh:

uv venv .venv-wordle-legacy --clear
uv pip install -e deps/verifiers
uv pip install -e deps/verifiers/environments/wordle

时,uv 会自动读取该环境变量,并将下载的 Python 包(如 wheel、源码包、构建缓存等)缓存保存到该目录

xuyujun成员
7月24日 评论:

那你应该放到setup_prime_rl.sh里吧,放在这个sh脚本,等它执行完毕,这个环境变量就失效了;

System
系统消息系统
7月24日 评论:

changed this line on 3483423f view diff detail

horizon_C
7月24日 评论:

感谢已修改

Hhorizon_C
7月24日 强制推送  1 个提交:3483423f-[feat]新增一站式平台verl-torchtitan qwen1.7B SFT训练样例
CANN-robotCANN-robot成员
7月24日 删除了label:ci-pipeline-passed
CANN-robot
CANN-robot成员
7月24日 评论:

Notification

This pull request has been changed(code update) or closed, so removes the following label(s): ci-pipeline-passed.

likedislike
CANN-robotCANN-robot成员
7月24日 添加了label:ci-pipeline-running
CANN-robot
CANN-robot成员
7月24日 评论:

流水线任务触发成功
任务链接 [7ad57217905b4c25a56f4ab9281e3af7][流水线指导]

任务名称状态日志下载链接
codecheck ✅ SUCCESS >>>>>
SCA ✅ SUCCESS >>>>>
antipoison ✅ SUCCESS >>>>>
Check_Pr ✅ SUCCESS >>>>>
Check_Patches ✅ SUCCESS >>>>>
codecheck_codestyle ✅ SUCCESS >>>>>
precommit ⚠️ WARNING >>>>> >>>>>
pre_comment ✅ SUCCESS >>>>>

[2026-07-24 12:19:31]    CI执行结束

likedislike
CANN-robotCANN-robot成员
7月24日 删除了label:ci-pipeline-running
CANN-robotCANN-robot成员
7月24日 添加了label:ci-pipeline-passed
Hhorizon_C
29 天前 修改了pull request 的描述
Hhorizon_C
29 天前 修改了pull request 的描述
Xxuyujun成员
29 天前 解决了最后一个问题
xuyujun成员
29 天前 评论:

/approve

likedislike
CANN-robotCANN-robot成员
29 天前 添加了label:approved
rui-zhang
rui-zhang
29 天前 评论:

/check-pr

likedislike
CANN-robot
CANN-robot成员
29 天前 评论:

The following label is not ready.

lgtm: Please wait for reviewers to review the code.

likedislike
张德鹏成员
29 天前 评论:

/lgtm

likedislike
CANN-robotCANN-robot成员
29 天前 添加了label:lgtm
CANN-robotCANN-robot成员
29 天前 合入了pull request