← 返回 2026-11-26 总览(保持原阅读位置) 快捷键:Esc 返回 · ←/→ 切篇 · C 复制 zoteroctl

TRL v1.19.0:多教师智能体蒸馏、SDPA行打包提速与AsyncGRPO工程加固

huggingface/trl v1.19.0

作者:huggingface
单位/机构:huggingface
发布日期与渠道:2026-11-25 · GitHub Release (v1.19.0) · 代码+权重已开源 · 协议:Apache-2.0 / MIT

① 真实痛点与翻车场景

① 在后训练和强化学习工程中,旧版存在多处高频翻车点:其一,默认最佳适配降序打包(BFD)会把整个批次展平为单行,导致PyTorch原生缩放点积注意力(SDPA)出现跨序列二次方计算复杂度,不仅拖慢速度,在Trainium2上还会直接内存溢出崩溃;其二,AsyncGRPO的微批规划与打包耗时过长(每轮18秒),且遇到病态数学输出(如多重幂嵌套)会永久卡死math-verify进程拖垮整次训练;其三,vLLM服务模式下原地合并LoRA权重会移动冻结参数并发送打包后的4-bit基座,导致QLoRA不可用且策略与采样对数概率严重漂移;其四,Qwen与Gemma等模型因未将对话模板的回合结束符写入eos_token_id,微调后会一直生成到max_new_tokens上限。

② 具体方法机制

② 本版本围绕训练吞吐、数值一致性和功能扩展做了五类核心改动:1)多教师与有状态环境蒸馏:DistillationTrainer接受教师字典并按样本的teacher_id列路由打分(实现MOPD融合阶段),同时接入与GRPOTrainer一致的environment_factory接口以支持智能体在有状态环境中蒸馏;2)SDPA行级打包:BFD打包不再把批次展平为单行,而是保留为多行并在每条序列起始处重置position_ids,消除跨样本注意力开销(padding_free=True仍保持展平);3)AsyncGRPO提速与容错:用数组向量化操作替代原规划打包逻辑并保证批次比特级一致,为Nemotron-H等Mamba2混合架构新增Triton树扫描/卷积/融合混合器核函数,并将准确率奖励判定隔离到独立子进程防止死锁;4)离位LoRA权重合并:向vLLM同步权重时改为离位合并,避免破坏4-bit量化基座与冻结参数;5)自动补齐终止符与模板适配:SFTTrainer在缺失时自动将对话模板回合结束符加入generation_config.eos_token_id,并扩展DeepSeek-V3.1/V3.2、Phi-4、Gemma 4等仅助手损失及工具调用模板支持。

③ 实验基准数字与对比口径

基座模型与参数量示例与基准涉及Qwen2.5-0.5B/1.5B、Qwen3-0.6B/1.7B、Inkling-2-Mini,以及Mamba2混合架构(Nemotron-H、Granite-4.0-H、Bamba)与多款对话模板模型(DeepSeek-V3.1/3.2、Phi-4、Gemma 4、GLM-4.7/5、LFM2-24B-A2B等);部分架构参数量原文未单列。
训练算力与耗时H100(单卡,Inkling-2-Mini LoRA SFT耗时53分钟;Qwen3-1.7B SFT测单步耗时)、4×B300(Qwen3-1.7B AsyncGRPO测规划打包耗时与吞吐)、Trainium2(Qwen3-0.6B编译SFT测单步耗时);其余示例与推理硬件及总耗时所给材料未单列。
评测随机种子数所给材料未单列(发行说明中的所有耗时、吞吐与示例准确率均未报告多种子均值或标准差)。

③ 发行说明给出了多项局部微基准与示例结果,但均非严格受控论文评测:1)BFD打包SFT(s/step):H100上Qwen3-1.7B使用SDPA从v1.18的2.06秒降至1.02秒(提速约2倍),Flash Attention 2基本持平(0.828→0.832秒),Trainium2上Qwen3-0.6B编译模式从崩溃变为3.2秒/步;2)AsyncGRPO规划打包:4×B300上跑Qwen3-1.7B数学采样,每轮规划加打包从18秒降至1秒,训练吞吐提升+28% tokens/s(批次比特级一致);3)vLLM服务模式权重同步:Qwen2.5-0.5B的对数概率差值从0.19–0.24降至0.02–0.04;4)新示例结果:Inkling-2-Mini在单张H100上LoRA SFT 53分钟,保留测试集时钟精确到秒的读数准确率从0%升至87.0%;s3多智能体聚合示例保留集团队成功率从4.7%升至60.9%。所有实验均未单列随机种子数、样本分母总数、序列长度分布及完整超参。

评测基准指标实测结果(自动核验)对比基线增量实验设置备注
Packed SFT (packing_strategy=bfd, SDPA)单步耗时 (s/step)1.02 ⚠️ 原文待核-1.04 (v1.18为2.06)H100,Qwen3-1.7B;样本数、序列长度与批大小未单列
Packed SFT (packing_strategy=bfd, Flash Attention 2)单步耗时 (s/step)0.832 ⚠️ 原文待核+0.004 (v1.18为0.828)H100,Qwen3-1.7B;验证无明显回归,具体批大小未单列
Packed SFT (packing_strategy=bfd, compiled)单步耗时 (s/step)3.2v1.18崩溃(crashes)Trainium2,Qwen3-0.6B;具体编译配置与批大小未单列
AsyncGRPO数学Rollout微批规划与打包规划+打包耗时 / 训练吞吐1 s/pass,+28% trained tokens/s ⚠️ 原文待核-17 s/pass (原18 s/pass),+28% tokens/s4×B300,Qwen3-1.7B,保证批次比特级一致;总步数与样本数未单列
vLLM Server模式权重同步 (QLoRA/LoRA)对数概率差值 (log-prob gap)0.02–0.04原0.19–0.24Qwen2.5-0.5B;统计分母(token数或样本数)与卡型未单列
Inkling-2-Mini 模拟时钟读数示例精确到秒准确率 (held-out)87.0%+87.0个百分点 (原0%)1×H100,LoRA SFT耗时53分钟;测试集时钟样本总数未单列
s3多智能体聚合示例保留集团队成功率 (held-out team success)60.9% ⚠️ 原文待核+56.2个百分点 (原4.7%)基座模型、算力预算、任务分母与种子数均未单列

④ 公开技术参考与复现成本评估

④ 代码完全开源于huggingface/trl(v1.19.0),对应每项改动均附有具体PR链接与示例脚本(如sft_inkling_2_mini_clocks),工程可复现性高。门槛主要来自依赖升级与硬件:Inkling 2 Mini需transformers>=5.24.0,全局升级至accelerate>=1.12.0并支持vLLM 0.34.x(同时移除peft 0.17兼容代码);单卡H100即可复现SFT与时钟示例,但AsyncGRPO的+28%吞吐数据基于4×B300测得,在消费级或旧架构显卡上的加速比例需实测验证。

⑤ 审稿人视角批判与独立观点

高价值工程迭代建议升级

针对SDPA打包OOM、AsyncGRPO打包瓶颈、奖励判题死锁及QLoRA同步漂移给出了比特级或数值级可验证的工程修复,并补齐多教师与环境交互蒸馏能力;但需注意依赖门槛(transformers>=5.24.0、accelerate>=1.12.0及移除peft 0.17兼容)可能带来迁移成本。

  1. 核心优化的适用边界与失效条件:BFD行级打包的2倍提速仅针对SDPA后端,在已使用Flash Attention 2时几乎无收益(0.828→0.832 s/step);AsyncGRPO的+28%吞吐收益依赖于CPU侧规划打包成为瓶颈的高算力配置(4×B300),在低算力卡或长上下文GPU计算受限场景下加速比会显著收窄;此外,多教师蒸馏依赖数据集显式提供teacher_id路由列,在跨领域样本归属模糊或需要动态混合打分的分布变化下该静态路由假设可能失效。
  2. 基准对比口径与方差缺失:发行说明中的速度与准确率数字多为单次示例快照,未交代随机种子、序列长度分布、测试集样本分母及硬件利用率;例如vLLM同步的log-prob gap仅在Qwen2.5-0.5B上给出区间(0.02–0.04),尚未证明在7B/70B或MoE模型及长生成轨迹上仍能保持低漂移,且Inkling-2-Mini时钟读数与s3多智能体示例均缺少外部强基线与多种子方差。
  3. 机制贡献与工程修补的剥离:本版本属于基础设施发布而非算法论文,其中SDPA行打包与AsyncGRPO数组打包通过明确对比v1.18且后者声明批次比特级一致,能清晰剥离出纯系统优化贡献;但多教师DistillationTrainer与environment_factory仅提供了接口实现,所给材料并未包含控制数据与基座后的MOPD多教师对比单教师消融实验,若用于科研立项需自行设计对照实验验证收益来源。
仅基于原文摘要与元数据研判,正文消融与附录算力细节待核原文
展开/收起原文英文摘要对照(用于核验原始措辞与数字)
## Features ### 👥 Multi-teacher and agent distillation `DistillationTrainer` takes a dict of teachers, and each example's `teacher_id` column picks the one that scores its completion: the fusion stage of [MOPD](https://huggingface.co/papers/2606.30406). It also takes `environment_factory`, with the same contract as `GRPOTrainer`, so agents can be distilled against stateful environments. ```python trainer = DistillationTrainer( model="Qwen/Qwen2.5-0.5B-Instruct", teacher_model={"math": "Qwen/Qwen2.5-Math-1.5B-Instruct", "code": "Qwen/Qwen2.5-Coder-1.5B-Instruct"}, train_dataset=dataset, # with a "teacher_id" column: "math" or "code" ) ``` * Implement MOPD for the `DistillationTrainer` by @cmpatino in https://github.com/huggingface/trl/pull/7215 * Add `environment_factory` support to `DistillationTrainer` by @sergiopaniego in https://github.com/huggingface/trl/pull/8453 ### 🕐 Inkling 2 Mini Support for [`thinkingmachines/Inkling-2-Mini`](https://huggingface.co/thinkingmachines/Inkling-2-Mini): coverage in the VLM tests and an [example](https://github.com/huggingface/trl/tree/main/examples/sft_inkling_2_mini_clocks) that teaches it to read analog clocks. LoRA SFT on one H100 in 53 min takes it from 0% to **87.0% of held-out clocks read to the second**. Needs `transformers>=5.24.0`. * Add Inkling 2 Mini: tiny model, tests and clock-reading SFT example by @qgallouedec in https://github.com/huggingface/trl/pull/8517 * Add a tiny Inkling 2 model and run it in the VLM tests by @qgallouedec in https://github.com/huggingface/trl/pull/8498 * Add a tiny Inkling model by @albertvillanova in https://github.com/huggingface/trl/pull/8512 ### ⚡ AsyncGRPO: faster packing, more architectures * **Plan and pack micro-batches with array operations**: on Qwen3-1.7B math rollouts (4×B300), planning + packing goes from 18 s to 1 s per pass, **+28% trained tokens/s**, with bit-identical batches. By @qgallouedec in https://github.com/huggingface/trl/pull/8533 * **Nemotron-H tree packing**: Mamba2 layers (Nemotron-H, Granite-4.0-H, Bamba) now follow the tree, with new Triton tree scan, conv and fused mixer kernels. By @AmineDiro in https://github.com/huggingface/trl/pull/8457 * **LFM in tree attention** by @younesbelkada in https://github.com/huggingface/trl/pull/7966 ### ✂️ 2x faster packed SFT with SDPA BFD packing (the default with `packing=True`) flattened the batch into one row, so SDPA attended across the whole batch: quadratic, and out of memory on Trainium. Packed examples now stay as rows, with `position_ids` restarting at each sequence. `padding_free=True` still flattens. s/step with `packing_strategy="bfd"`: | | v1.18 | v1.19 | | --- | --- | --- | | H100, Qwen3-1.7B, SDPA | 2.06 | **1.02** | | H100, Qwen3-1.7B, flash attention 2 | 0.828 | 0.832 | | Trainium2, Qwen3-0.6B, compiled | crashes | **3.2** | by @qgallouedec in https://github.com/huggingface/trl/pull/7804 ### 🛑 Fine-tuned models stop at the end of their turn Qwen base, Gemma 1/2 instruct, Qwen3.5 and a few others don't list their chat template's end-of-turn token as a stop token, so a model fine-tuned on them generated until `max_new_tokens`. `SFTTrainer` now adds that token to `generation_config.eos_token_id` when it's missing, and changes nothing elsewhere (checked on the 348 matching checkpoints among the 3000 most-downloaded Hub repos). by @albertvillanova in https://github.com/huggingface/trl/pull/8565 ### 💬 More chat templates `assistant_only_loss=True` and tool calling work on more checkpoints, all by @albertvillanova: * Assistant-only loss: DeepSeek-V3.1 (#8431), DeepSeek-V3.2-Exp (#8471), DeepSeek-R1-Distill (#8529), SmolLM2 (#8444), Phi-4 (#8445), Gemma 4 (#8493), GLM-4.7 and GLM-5 (#8494), Qwen3-Coder (#8496), Llama 3.1 and 3.2 (#8495), OLMo 3 Think (#8475), LFM2-24B-A2B (#8526), Inkling (#8513) * Tool calling: DeepSeek-R1-0528 and V3-0324 (#8443), DeepSeek-V3.1 and V3.2-Exp (#8508) * More template revisions recognized (#8272, #8275, #8317, #8467, #8468, #8503, #8509, #8510, #8527, #8528, #8561, #8562, #8575) ### Other * **Grade accuracy rewards in a separate process so a pathological answer can't hang training**: an answer like `5^{5^{5^{5^5}}}` blocked math-verify forever and killed AsyncGRPO runs. By @sergiopaniego in https://github.com/huggingface/trl/pull/8330 * Support `pad_to_multiple_of` with vision-language models in SFT, DPO and KTO, which fixes VLM training on Trainium, by @albertvillanova in https://github.com/huggingface/trl/pull/8553 * Raise in AsyncGRPO when a whole pass over the prompts drops every group, instead of hanging, by @albertvillanova in https://github.com/huggingface/trl/pull/8425 * Add an s3 multi-agent aggregation example (held-out team success 4.7% → 60.9%) by @kashif in https://github.com/huggingface/trl/pull/8424 * Detect HF Jobs via `HF_JOB_ID` and add the hardware flavor to the model card by @davanstrien in https://github.com/huggingface/trl/pull/8576 * Load the processing class in `OnlineDPOTrainer` when it is omitted by @behroozazarkhalili in https://github.com/huggingface/trl/pull/7519 * Add Python 3.15 to the test matrix and the classifiers by @qgallouedec in https://github.com/huggingface/trl/pull/7498 ### Removals and requirement bumps * **Add support for vLLM 0.34.x**, so the range is `vllm>=0.23.0, =0.18.0` and drop the peft 0.17 compatibility code by @albertvillanova in https://github.com/huggingface/trl/pull/8426 * Require `accelerate>=1.12.0` and drop the older accelerate fallbacks by @albertvillanova in https://github.com/huggingface/trl/pull/8542 * Default `ModelConfig.model_revision` to `None` like the other revision arguments by @albertvillanova in https://github.com/huggingface/trl/pull/8530 * Follow the transformers 5.23 rename of gradient checkpointing to activation checkpointing by @qgallouedec in https://github.com/huggingface/trl/pull/8113 ## Fixes * **Merge LoRA adapters out of place for the vLLM weight sync.** Frozen weights moved at every sync and a 4-bit base was sent packed. QLoRA in server mode now works, and the server-mode log-prob gap on Qwen2.5-0.5B drops from 0.19–0.24 to 0.02–0.04. By @qgallouedec in https://github.com/huggingface/trl/pull/8269 * **Stop pasting a fake tool call before every tool result** when the eos is ` `, as in Unsloth's Gemma 4 tokenizers (#8521), **and repeating GLM's ` `** (#8522), by @qgallouedec * **Read vLLM >= 0.32 generate log-probs in AsyncGRPO**, which raised `KeyError: 'token'` on the first rollout with `top_k` or `top_p`, by @rycerzes in https://github.com/huggingface/trl/pull/8573 * **Fix AsyncGRPO score-centering tail ratios and sampler validation** by @kashif in https://github.com/huggingface/trl/pull/8373 and https://github.com/huggingface/trl/pull/8414 * Keep the generation prompt's ` \n` out of the DeepSeek-V3 (#8313) and DeepSeek-R1-Distill (#8314) assistant-only loss, and its `\n` out of Qwen2.5's (#8279), by @albertvillanova * Fix `BEMACallback` when some parameters are frozen by @qgallouedec in https://github.com/huggingface/trl/pull/8455 * Keep the `environment` column in GRPO when `remove_unused_columns=True` by @qgallouedec in https://github.com/huggingface/trl/pull/8520 * Load a reward model given by name without the policy's revision by @albertvillanova in https://github.com/huggingface/trl/pull/8538 * Skip the InternVL tile count for models that split their images by `image_grid_thw`, so GRPO and RLOO no longer crash on Inkling 2, by @qgallouedec in https://github.com/huggingface/trl/pull/8484 * Convert nested image arrays with `np.array` before making tensors in GRPO, RLOO and Distillation by @albertvillanova in https://github.com/huggingface/trl/pull/8394 * Render `None` content as empty text in the GLM-4-MoE training template by @albertvillanova in https://github.com/huggingface/trl/pull/8454 * Skip torch's sparse invariant checks for GOLD's X-Token projection matrix by @albertvillanova in https://github.com/huggingface/trl/pull/8393 * AsyncDistillation: freeze the vision tower of VLM students (#8412), load students with the architecture their config declares (#8413), and fix VLM students on transformers < 5.0 (#8462), by @albertvillanova * Fix the CLI parser on Python 3.15 by @qgallouedec in https://github.com/huggingface/trl/pull/8271 * Compare version checks against plain release versions, not .dev0, by @qgallouedec in https://github.com/huggingface/trl/pull/8256 * Drop `--api-server-count` from the AsyncGRPO adapter-sync command, which vLLM rejects, by @sergiopaniego in https://github.com/huggingface/trl/pull/8383 * Gate the MoE dense and shared layer LoRA warning on peft 0.22.0 (#8328, #8483) and only check models whose targets peft remaps (#8428), by @albertvillanova ## Documentation * Fix dead links in the docs by @erdogan-deniz in https://github.com/huggingface/trl/pull/8459 * Clarify `max_completion_length` (#8450) and `max_tool_calling_iterations` (#8464) with tools, the sessions `environment_factory` opens on OpenEnv servers (#8452), and why the rollout worker can't start child processes (#8463), by @sergiopaniego * Add the results to the Wordle example README (#8099), open one OpenEnv client per game (#8129), update the blog posts on the landing page (#8579) and point to the new OpenEnv docs site (#8586), by @sergiopaniego * Use the activation checkpointing names in the docs (#8114) and examples (#8117), and the stable `DistillationTrainer` API everywhere (#8293), by @qgallouedec * Add Albert Villanova del Moral and Sergio Paniego Blanco to the TRL citation by @qgallouedec in https://github.com/huggingface/trl/pull/8335 * Document that assigned issues belong to their assignee by @albertvillanova in https://github.com/huggingface/trl/pull/8534 ## CI **Flash Attention compatible tiny models**, all by @albertvillanova: Gemma3, Mistral Large 4, GLM-5.3-Flash, Remote, Phi-3, Phi-3.5, LFM2, LFM2.5, LFM2.5-MoE, LFM2.5-VL, Qwen2-VL, Qwen3-VL, LLaVA-NeXT, Idefics2, Idefics3, InternVL, Granite 4.0 hybrid, GPT-2, OPT, GPT-NeoX, Bart and Muse Glimmer (#8319, #8320, #8321, #8380, #8381, #8382, #8409, #8410, #8411, #8435, #8436, #8437, #8446, #8478, #8479, #8480, #8481, #8482, #8487, #8488, #8489, #8536, #8537), the Qwen3 models at `head_dim=16`, the smallest vLLM allows (#8415, #8416, #8417), and fallbacks for the models that refuse it (#8399, #8401, #8402, #8403, #8404) **Tiny models**, all by @albertvillanova: pin every tiny model to a Hub commit (#8262, #8264, #8531, #8539), FP8 checkpoints laid out like their references for GLM-5.3-Flash and Mistral3 (#8227, #8298), and new tiny Qwen3-Coder and Qwen3-Coder-Next (#8449, #8544) **Tests that run what users run**: AsyncGRPO tests on GRPO's layout (#8146), tools and environments tested through what the user sees (#8251), adapter sync on the stand-in server (#8368), prompt tuning settings (#8557) and consistent test ids (#8563) by @qgallouedec; tiny Qwen3 in the vLLM tests (#8297), tiny models in the async tests (#8470), an MoE teacher in the distillation tests (#8492), conversational data and reward functions in the router and packing tests (#8336, #8337, #8338), AsyncGRPO fp16 (#8421), RewardTrainer with prompt learning (#8485) and the Qwen3-Coder tool-call tests (#8515, #8545) by @albertvillanova **Other**, all by @albertvillanova: run the OpenEnv harness tests in the experimental CI (#8036), skip experimental tests on draft PRs (#8301), post chat template checks to Slack only from main (#8408), time out test steps after 60 minutes (#8422), report tests that raise peak host memory by 2 GB or more (#8442), stand-in vLLM server fixes (#8379, #8430), chat template tests (#8312, #8570), test fixes (#8261, #8265, #8407, #8448), warning filters (#8392, #8395, #8396, #8397, #8543), plus dependency bumps by @dependabot[bot] (#8374, #8519) ## New Contributors * @erdogan-deniz made their first contribution in https://github.com/huggingface/trl/pull/8459 **Full Changelog**: https://github.com/huggingface/trl/compare/v1.18.0...v1.19.0
← 返回总览 首篇 下一篇 →