Skip to content

[feature] Add quick start doc-test guarding for TRL - #151

Open
lltiaor wants to merge 4 commits into
Ascend:mainfrom
lltiaor:feat/trl-quick-start
Open

lltiaor wants to merge 4 commits into
Ascend:mainfrom
lltiaor:feat/trl-quick-start

Conversation

@lltiaor

@lltiaor lltiaor commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

总结

新增对 TRL 快速上手文档的自动化测试看护。被看护的文档为 sources/trl/quick_start.md:示例在单张 NPU(Atlas 900 A2 / Ascend 910B4)上,使用 Qwen2.5-0.5B-Instruct 分别执行 SFT LoRA 和 DPO LoRA。模型和数据集均通过 ModelScope 自动下载。

文档分别安装 TRL 和 SFT/DPO 示例依赖;训练脚本输出 LoRA 适配器的保存目录。

变更文件

新增:sources/trl/index.rstsources/trl/quick_start.md.github/workflows/trl-quick-start.ymltests/trl/

删除:已过时的 sources/trl/install.rstquick_start.rstimages/image.png

调整:conf.pyquick_start.md 加入排除列表,由 index.rst 作为 TRL 侧边栏落地页;首页 toctree 和 TRL 卡片链接均指向 sources/trl/index.rst

验证

手动触发workflow测试通过

@ascend-robot

Copy link
Copy Markdown

CLA Signature Guide

@lltiaor , thanks for your pull request.

The following commit(s) are not associated with a signed Contributor License Agreement (CLA).

Commit Reason
[eadc509 [feature]支持trl的quick star...](eadc509) the email used in the commit is not linked to a signed CLA!
please verify that it matches the email you used when signing the CLA.

To sign CLA, click here.

To check if your email is configured correctly, refer to the FAQs.

Once you've signed the CLA or updating your email, please comment /check-cla to revalidate CLA status.

@lltiaor

lltiaor commented Sep 7, 2026

Copy link
Copy Markdown
Contributor Author

/check-cla

@ascend-robot

Copy link
Copy Markdown

CLA Signature Pass

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

@github-actions

github-actions Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

📖 文档预览https://ascend.github.io/docs/pr-preview/pr-151/sources/trl/

也可打开整站首页

构建自 ed98dfa441f82d918947053a074ad547a9aa2f1a
每次推送后自动更新,PR 关闭时自动清理。

github-actions Bot pushed a commit that referenced this pull request Sep 15, 2026
Comment thread sources/trl/quick_start.md Outdated

- 可用的 Python 环境
- 可用的 CANN(参考[快速安装昇腾环境](https://ascend.github.io/docs/sources/ascend/quick_install.html))
- 与上面 CANN 匹配的 `torch` + `torch_npu`,且 `torch` 能正常 `import` 并 `torch.npu.is_available() == True`(参考 [Ascend PyTorch 安装文档](https://gitcode.com/Ascend/pytorch),按 torch ↔ torch_npu ↔ CANN 三方兼容矩阵选择版本)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

就说安装匹配的torch_npu就可以了,安装torch_npu的地方会有验证方法的,这里不用赘述。

Comment thread sources/trl/quick_start.md Outdated

**软件版本**:

| 组件 | 版本 |

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个我觉得没有必要展示版本,否则需要经常维护,这个跟楚阳和堆灿可以对齐下,看怎么做比较合适。

Comment thread sources/trl/quick_start.md Outdated
python --version
```
输出结果如下:
```shell #test-result id="check-py" fuzzy='xxx'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不建议写明python版本,减少维护工作量。

Comment thread sources/trl/quick_start.md Outdated
检查 NPU 设备运行时可用:

```shell #test id="check-npu-runtime"
python -c "import torch, torch_npu; print(f'torch={torch.__version__}'); print(f'torch_npu={torch_npu.__version__}'); print('is_available:', torch.npu.is_available());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

格式丢了,显示效果不好。

Comment thread sources/trl/quick_start.md Outdated

安装 `transformers` / `peft` / `modelscope`,装完打印版本验证。示例数据集来自 ModelScope:

```shell #test id="install-deps"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

格式有问题。 另外,这些依赖不能通过requirment.txt安装么?

Comment thread sources/trl/quick_start.md Outdated

## 安装 TRL

用 uv 安装 PyPI 最新 release,装完打印版本验证:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

使用uv的话,还需要安装uv工具,如果pip直接可以安装,那就世界使用pip即可。但是如果官网文档就使用的uv,那就保留

Comment thread sources/trl/quick_start.md Outdated
```shell #test-result id="trl-install-binary" fuzzy='xxx'
trl xxx
```
- xxx 表示最新的版本号

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这句就不用了

Comment thread sources/trl/quick_start.md Outdated

用 ModelScope 数据集 `HuggingFaceH4/ultrafeedback_binarized` 的 SFT 子集对 Qwen2.5-0.5B-Instruct 做 5 步 LoRA SFT。模型由脚本内的 `snapshot_download` 首次运行时自动下载到默认缓存(约 1 GB),数据集经 ModelScope 自动下载;`SFTTrainer` 通过 `peft_config` 注入 LoRA 适配器,底座权重冻结、只训练新注入的低秩矩阵;训练完成后把适配器保存到 `output/trl-sft-lora`。

```shell #test id="sft-lora"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

格式显示不太好。 python << 会丢失代码高亮

Comment thread sources/trl/quick_start.md Outdated

同一个模型与 LoRA 配置,把 `SFTTrainer` / `SFTConfig` 换成 `DPOTrainer` / `DPOConfig` 就是偏好优化:ModelScope 数据集 `HuggingFaceH4/ultrafeedback_binarized` 的 `prompt` / `chosen` / `rejected` 三段对话让模型更倾向 `chosen` 而非 `rejected` 的回答。这里跑 3 步 DPO LoRA,产物保存到 `output/trl-dpo-lora`。

```shell #test id="dpo-lora"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

@ascend-robot

Copy link
Copy Markdown

CLA Signature Pass

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

github-actions Bot pushed a commit that referenced this pull request Sep 15, 2026
@lltiaor
lltiaor force-pushed the feat/trl-quick-start branch from 6a3566d to 2dfa106 Compare September 15, 2026 11:34
@ascend-robot

Copy link
Copy Markdown

CLA Signature Pass

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

github-actions Bot pushed a commit that referenced this pull request Sep 15, 2026
@lltiaor
lltiaor force-pushed the feat/trl-quick-start branch from 2dfa106 to dd23583 Compare September 16, 2026 07:15
@ascend-robot

Copy link
Copy Markdown

CLA Signature Pass

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

github-actions Bot pushed a commit that referenced this pull request Sep 16, 2026
@Devin-DC-Huang

Copy link
Copy Markdown
Contributor
image 要有结果,告诉用户可能的预期,虽然不用对比

@Devin-DC-Huang

Copy link
Copy Markdown
Contributor
image image 类似的结果太简单的,应该有yi'xie一些更明显的对比结果

@ascend-robot

Copy link
Copy Markdown

CLA Signature Pass

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

github-actions Bot pushed a commit that referenced this pull request Sep 23, 2026
@ascend-robot

Copy link
Copy Markdown

CLA Signature Pass

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

github-actions Bot pushed a commit that referenced this pull request Sep 23, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants