TRL
huggingface / trl
Hugging Face 的强化学习与对齐训练库:SFT、DPO、PPO、GRPO、奖励模型都能接。Hugging Face's RL and alignment training library: SFT, DPO, PPO, GRPO and reward models.
为什么选Why choose it
- 与 transformers 生态无缝,模型、分词器、数据集直接复用。Seamless with the transformers ecosystem; reuse models, tokenizers and datasets directly.
- 对齐算法覆盖全,适合做 RLHF/DPO 实验。Broad alignment coverage, suitable for RLHF/DPO experiments.
- 文档与示例多,适合作为对齐训练的基线。Good docs and examples; a solid baseline for alignment training.
不适合Not for
只做推理或简单微调,直接用 transformers Trainer 更轻。For inference or simple fine-tuning, transformers Trainer is lighter.
超大模型多机训练要另配 DeepSpeed/FSDP。Very large multi-node training still needs DeepSpeed/FSDP.
最小上手Minimum setup
- 从官方示例跑一个小的 SFT 或 DPO 任务,确认依赖版本。Run a small SFT or DPO example from the official docs and pin dependency versions.
- 用 1–2 个模型与固定评测集建立基线,再改奖励或数据。Build a baseline with 1–2 models and a fixed eval set before changing rewards or data.
- 记录显存与吞吐;对齐训练对超参敏感,一次只改一个变量。Record VRAM and throughput; alignment is hyperparameter-sensitive, so change one variable at a time.
依赖与成本Dependencies and cost
Python + PyTorch;对齐训练通常需要奖励模型或偏好数据;大模型要配 DeepSpeed/FSDP。Python + PyTorch; alignment usually needs a reward model or preference data; large models need DeepSpeed/FSDP.
许可与使用边界License and usage boundaries
代码 Apache-2.0;模型、数据集与偏好数据各有许可。Code is Apache-2.0; models, datasets and preference data carry their own licenses.
开源不等于可商用:GPL / AGPL 有传染性;代码许可、模型许可、生成内容许可要分开看。上线前读仓库 LICENSE 与模型卡,必要时让法务确认。Open source is not automatically commercial-use friendly: GPL / AGPL are copyleft; code, model and output licenses are separate. Read the LICENSE and model card before launch, and involve legal when needed.
替代与相邻Alternatives and neighbors
- OpenRLHF — 规模 / 性能Scale / performance,基于 Ray + vLLM 的 RLHF 训练框架:PPO、GRPO、DPO、KTO 与多机多卡编排。A Ray + vLLM RLHF framework: PPO, GRPO, DPO, KTO and multi-node orchestration.
- verl — 规模 / 性能Scale / performance,字节跳动的 RL 训练框架:面向 LLM Agent 与推理任务,支持 PPO/GRPO 与多轮工具调用。ByteDance's RL training framework for LLM agents and reasoning tasks, with PPO/GRPO and multi-turn tool use.
下一步Next steps
- 打开 GitHub,先读 README、LICENSE、最近 release 与 issue。Open GitHub and read the README, LICENSE, latest release and issues first.
- 按“部署依赖 / 显存 / 数据 / 网络 / 权限”列一张上手清单。Make an onboarding checklist for deployment dependencies, VRAM, data, network and permissions.
- 用一个小样本跑通,再决定是否进生产;不要直接上生产数据。Run a small sample first, then decide on production; never start with production data.
GitHub 仓库 ↗GitHub repository ↗ 文档 ↗Docs ↗ 加入对比Add to compare