跳到正文

THE JOURNAL / FIELD NOTES

异步 RL:状态、路由回放与调度耦合

这是技术笔记的公开整理版,原始记录日期为 2026-08-21,本次编辑于 2026-09-21。保留原笔记的公式、代码位置与证据分级;本次仅整理内容,未重新运行 GPU 实验或逐项复核上游。标为【码】【核验】的内容指原记录的核查结果,不代表当前版本仍然如此。

对照:Kimi K3 技术报告 §5.3.1(arXiv:2607.24653v2)


0. 一句话

异步化的收益来自"维持高并发以压平长尾",代价是"样本由多个策略版本生成"。整套基础设施就是围着这一个矛盾设计的。

【原文,§5.2 开头】:

"The long-tail problem during the rollout phase of RL for LLMs has consistently been a major bottleneck for training efficiency. To address this, we extend our post-training infrastructure to allow asynchronous generation of samples, which significantly mitigates the long-tail issue by maintaining a sufficiently high level of concurrency. Asynchronous training is now enabled for nearly all our RL and OPD tasks."

长尾为什么致命:同步 RL 里,一个 batch 的步调由最慢的样本决定。若 1% 的样本耗时 100 倍,GPU 就有大量时间在等待。


1. 架构:一条关键边界

┌────────────────── 训练池(可抢占,GPU)──────────────────┐
│  ┌────────────┐  ← 权重同步   ┌──────────────────────┐  │
│  │  Trainer   │ ────────────→ │  Rollout 推理引擎     │  │
│  │ 训练/优化器 │ ←──────────── │ (colocate + 时间片共享)│  │
│  └─────┬──────┘  训练抢占rollout└──────────┬───────────┘  │
└────────┼──────────────────────────────────┼─────────────┘
         │ 训练样本                  dispatch│ 请求
         │                                  ▼
┌─────────┴──────────── DSec(不可抢占,CPU)──────────────┐
│  ┌────────────────────────────────────────────────────┐ │
│  │ Worker Container —— scaffold-agnostic 控制层         │ │
│  │ · 编排 rollout                                      │ │
│  │ · 把异构交互归一化成 common trajectory schema         │ │
│  │ · 与 trainer 通信                                    │ │
│  └───────────────────────┬────────────────────────────┘ │
│  ┌───────────────────────▼────────────────────────────┐ │
│  │ Agent Sandbox —— 跑 scaffold 和它的工具              │ │
│  │ 等推理时可暂停(可占生命周期 98%)                     │ │
│  └────────────────────────────────────────────────────┘ │
│  状态存储:KV cache + 专家路由(token 粒度)+ sandbox 状态 │
└──────────────────────────────────────────────────────────┘

【原文,§5.1.2】 这条边界是明确的设计决策:

"We decouple agent rollout execution into an agent sandbox and a worker container. The sandbox runs the scaffold and its tools, while the worker provides a scaffold-agnostic control layer that orchestrates the rollout, normalizes heterogeneous interactions into a common trajectory schema, and communicates with the trainer. Both run on DSec, outside the preemptible GPU training pool, separating long-lived rollouts from fine-grained training scheduling."

这个解耦同时解决三件事:

设计 解决
worker 是 scaffold-agnostic 的 换 harness 不用改 trainer(§5.3.4 跨 6 个 scaffold 家族靠这个)
归一化成 common trajectory schema trainer 只认一种数据格式
放训练池之外 长生命周期 rollout 不被细粒度训练调度打断

2. 五个必须做对的耦合点

2.1 调度粒度:试了三次才定(最有价值的一段,因为它记录了失败)

【原文,§5.2.1】:

方案 结果 原文
batch 级:开始多派几个 batch,每次训练后补一整批 ❌ 训练指标剧烈震荡 "caused severe oscillations in training metrics, indicating that batch-level granularity was too coarse"
prompt 级:一个 GRPO group 完成后再派新 prompt ❌ 卡在 group 内长尾样本上 "it stalled easily on long-tail samples within a GRPO group"
sample 级(最终) ✅ "once the number of newly completed samples reaches the GRPO group size assigned to the next prompt, we dispatch that prompt regardless of which groups produced those completions"

⭐ 关键洞察在最后半句:regardless of which groups produced those completions —— 不要求某个 prompt 的整个 group 完成,只要攒够足够多的样本就派下一个 prompt。

为什么这样能压平长尾:按 group 等,一个慢样本卡住整个 group;按样本攒,慢样本慢慢跑,其他资源继续产出。

【推断】实现含义:需要一个全局完成样本计数器(而非 per-prompt 状态机),在计数达 GRPO group size 时触发下一次 dispatch。设计很轻量,但与"per-group 等待"的直觉相反。

2.2 长度偏置(副作用一)

【原文】:

"shorter sequences tend to complete first and thus dominate the initial training batches"

两个机制:

  1. 按数据集限制并发 —— 通过控制样本来源,间接调控 steady-state batch 里各数据集比例
  2. 丢弃早返回的短样本 —— 详见 §3

2.3 off-policy(副作用二)

【原文】:

"off-policy samples, i.e., samples whose tokens are partially or entirely generated by earlier checkpoints"

机制 层次 做法
bound 最大 off-policy 比例 调度层 "tuning the logic that controls sample dispatching and the waiting condition for training samples"
loss masking 按 staleness 损失层 "eliminates the contribution of tokens with excessive staleness"

⭐ 第二个是 token 级而非样本级:一个样本可能前半段旧策略、后半段新策略,只 mask 过期 token,保留可用部分。

【推断】代价:advantage 估计会变得不干净(一个序列里 token 来自不同策略)。报告未讨论这个理论问题。

2.4 路由重放(MoE 专属的坑)

【原文】:

"we use concatenated routing-replay: for samples that span multiple checkpoints, we concatenate the expert routing produced at each rollout segment rather than discarding and recomputing the routing information with new checkpoints."

问题:一个样本跨两个 checkpoint,前半段的专家路由按旧权重算、后半段按新权重算。

做法 代价
朴素:用新 checkpoint 重算整条路由 要重跑 prefill,成本高
V4.1:拼接各段路由 无需重算

【推断】 这是 MoE 专属问题 —— dense 模型不会遇到。也意味着 rollout 状态持久化必须包含专家路由,不只是 KV cache。

2.5 无缝 checkpoint 切换

目标【原文】:

"interruptions should be near-instantaneous, and interrupted rollouts should resume as if never stopped"

机制 原文 作用
token 级中断 "generation can be halted at any token boundary" 攒够数据后 in-flight 样本几乎立刻停下
token 粒度持久化 "KV cache and expert routing are persisted at token granularity" 换 checkpoint 后直接复用,免重新 prefill,从断点继续
样本级 GC "sample-grained garbage collection, releasing each sample's states as soon as it completes" 要保留所有 in-flight 状态,必须及时释放

⭐ 额外红利【原文】:

"the same fast-interruption and seamless-resumption machinery allows the training jobs to respond promptly to cluster scheduling preemption signals without losing progress, thereby improving overall cluster utilization."

【推断】 "为 A 做的机制顺便解决了 B" —— 为换 checkpoint 做的中断/恢复,正是应对集群抢占所需的。


3. ⭐ 为什么丢弃早返回的短样本

【原文,§5.2.2】 只有一句:

"we support discarding early-returned short samples to smooth the transition into the steady-state length distribution, and prevent the model from overfitting to overly short sequences."

3.1 偏差怎么产生的

异步下"谁先到"取决于"谁先跑完",而长度与完成时间正相关:

训练开始,样本池空 → 挂 N 个 in-flight 样本
  → 短样本先跑完 → 池里先只有短的
  → "攒够样本"的触发条件先被短样本满足
  → 第一批训练数据 ≈ 全是短序列

同步 RL 没这个问题:等整个 batch 完成,样本池组成是真实分布,与完成顺序无关。

注意是暂态【原文】:"especially in the early training stage"。

3.2 两个层次,第二个才是真原因

层次 1:统计偏差 —— 第一批训练集的长度分布被截断。只这一层的话,忍几步就自愈了,不值得丢弃。

层次 2:动力学放大(正反馈)

in-flight 样本是正在演进的策略生成的:

训练集偏短 → 策略更新 → 策略更爱输出短序列
                              ↓
                    新样本更短 → 更快返回
                              ↓
                    下一批训练集偏得更厉害  ←── 正反馈
                    训练集偏短 ─────────────────┘

👉 原文用 "overfitting" 而不是 "bias",支持这个解读:过拟合到某个模式是动力学问题,不是采样偏差问题。

结论:丢弃短样本的目的是切断一个正反馈回路,而不只是修正第一批的统计分布。 前者可以忍,后者必须在回路建立前掐断。

3.3 为什么是"丢弃"而不是"重加权"

  1. 切断回路需要"不训练":重加权仍会用短样本更新策略;只要策略还在朝短偏移,回路就没断。丢弃 = 权重归零。
  2. 经济性:生成成本 ∝ 长度,丢弃短样本 = 丢弃最便宜的产出。
  3. GRPO 结构提供了天然判定点:训练本来要等完整 group;跑得快的 group 大概率是短 group。(补:短 group 的组内奖励方差往往也小,GRPO 从中学到的信号本来就弱,机会成本更低。)

3.4 这是暂态,不是永久

到 steady state 后池子自我平衡:长样本陆续返回 → 每次返回都取走一个、补派一个新 prompt → 池中长度分布收敛到稳态。所以应做成可开关、只在前若干步生效,而不是全程开着(全程开 = 持续浪费 rollout 产出,而 rollout 是瓶颈)。

3.5 ⚠️ 实现陷阱:阈值不能用"当前策略的分布"定

阈值 = 当前 P10 长度
  → 丢弃低于阈值者 → 训练集变长 → 策略输出变长
  → 阈值跟着抬高 → 丢得更多 → 输出更长 ...

可能造成长度膨胀,而不是回到正常分布。

【推断】正确做法:阈值锚定任务/数据集的预期长度(历史 run 统计),或固定绝对值,不跟随当前策略漂移。

3.6 与 token 级 mask 的区别(两者不是一回事)

丢弃早返回短样本 token 级 loss masking
解决 长度偏置(副作用 1) off-policy / staleness(副作用 2)
粒度 整个样本 单个 token
层 数据准入 损失计算
触发 训练早期暂态 常态,按 staleness 阈值

【推断】 取舍哲学相同:在"浪费产出"与"污染训练"之间找平衡点。前者是暂态可选粗粒度,后者是常态必须精细。


4. 两个扩展

4.1 跨 scaffold 的异构 RL

【原文,§5.1.2】:

"We scale RL runs in two dimensions, i.e., training compute and the number of scaffolds... whether scaling within a single scaffold, jointly across variants of the same scaffold, or across heterogeneous scaffolds."

规模【核验,Figure 7/8】:2000+ cumulative RL steps、输出长度到 400k tokens、上下文 512K 甚至 1M。评测基准:DeepSWE v1.1、SWE-Bench Pro、Terminal-Bench v2.1/v3.0。

依赖:worker 层的 scaffold-agnostic 抽象(§1)。

4.2 模型合并来聚合并行 RL 算力(最聪明的一招)

【原文】:

"To extend effective RL compute beyond a single training run, we use model merging to reinitialize successive RL runs. Specifically, we merge checkpoints from runs across different scaffolds or configurations, combining improvements acquired along different optimization paths."

机制:Figure 7/8 里断开的曲线段就是"重新初始化后的连续 RL run"。

为什么聪明:单个 RL run 的算力有上限(稳定性、超参、时间);沿不同 scaffold/配置跑多个 run 各自探索,合并 checkpoint 就能聚合改进、继续外推 scaling 曲线。报告称它 "yields further gains in both task performance and token efficiency"。

【推断】 本质是用"并行多路径 + 权重合并"换取有效的 RL 算力扩展,绕开"单次 run 能跑多长"的限制。具体合并方法报告未给(权重平均?任务算术?)。

4.3 (§5.2.4)OPD 的异构 teacher 与配置版本化

【原文】:

"the final full-vocabulary OPD task is trained on datasets from all domains using over 40 teacher models... supporting full-vocabulary OPD with an effectively unbounded number of architecturally heterogeneous teachers, and efficient switching among them at negligible cost"

两个难点:① teacher 架构可以和学生不同;② 训练中动态调整数据集混合、per-dataset 并发上限、激活哪些 teacher。

⭐ 异步在这里的新问题最尖锐【原文】:

"Such changes are straightforward in synchronous training where rollout batches provide explicit configuration boundaries. In the asynchronous setting, however, samples generated under different configurations may coexist in flight."

【推断】 同步里"batch 边界 = 配置边界",异步里这个不变量没了 → 需要一套"配置版本"机制:每个 in-flight 样本记住自己的配置版本,切换时不能混。这与 off-policy 的 staleness 追踪是同一类问题(都给样本打版本标签)。


5. 与 Kimi K3 的对照

【核验】 两家都选 co-located RL:

  • V4.1:colocate + 时间片共享,训练抢占 rollout,唯一旋钮是 in-flight 样本数上限
  • Kimi §5.3.1:"We adopt co-located RL training to keep each 1M-context Kimi K3 RL experiment within a few hundred GPUs"

解法不同:

问题 V4.1 Kimi K3
长尾 sample-level dispatch + 异步生成 partial rollouts 降低尾延迟
KV 压力 token 粒度持久化 + 抢占恢复 外部 KV cache 池(write-back 到 CPU DRAM)+ NVMe 卸载训练状态
并发控制 in-flight 上限 + per-dataset 并发限制 rollout auto-throttling(按活跃/排队请求数、KV 利用率动态调)
状态对齐 KV cache + 专家路由 KDA state 与 MLA KV block 一起 offload,"lifecycles aligned"

【推断】 两家没有统一答案,说明异步 RL infra 还没有最佳实践 —— 这对想进入这个方向的人是好事。


6. 可直接照做的清单

第 1 层:进程边界
  □ rollout 移出可抢占的 GPU 训练池
  □ 拆成 sandbox(跑 scaffold+工具)与 worker(scaffold-agnostic 控制层)
  □ 定义 common trajectory schema

第 2 层:调度
  □ 全局完成样本计数器(不是 per-prompt 状态机)
  □ 计数 ≥ GRPO group size 就派下一个 prompt(不管谁产出的)
  □ in-flight 样本数上限作为主旋钮
  □ per-dataset 并发限制(控长度偏置)

第 3 层:正确性
  □ 每个样本打"策略版本"标签 → 算 staleness
  □ bound 最大 off-policy 比例(调度层)
  □ token 级 loss masking(损失层)
  □ MoE:拼接各段专家路由,不重算
  □ 长度偏置:早期丢弃短样本(阈值锚定任务预期,不跟随策略漂移)

第 4 层:中断/恢复
  □ token 级中断
  □ token 粒度持久化 KV cache + 专家路由
  □ 样本级 GC(完成即释放)

第 5 层:扩展
  □ 多 scaffold 联合训练(依赖第 1 层抽象)
  □ 多 run 模型合并扩展有效算力
  □ 配置版本化(OPD 动态重配置必需)

7. 证据缺口与不确定

  1. V4.1 没给任何量化数据 —— 没有 rollout 效率提升幅度、off-policy 比例上限、staleness mask 阈值、丢弃短样本的比例与持续步数。只有机制,没有数字。
  2. token 级 staleness 下 advantage 是否仍无偏,报告未讨论 —— 我认为这是一个理论空白。
  3. 模型合并的具体方法未给(权重平均?任务算术?)—— 只说 "model merging"。
  4. §3.2 的"正反馈放大"是我的推断 —— 论文只说 "prevent overfitting to overly short sequences",没有明确描述回路。我认为 "overfitting" 一词支持这个解读,但这是推理而非原话。
  5. 另一个可能解释:早返回的短样本可能包含"被 max_tokens 截断"或"提前 EOS"的低质量样本。【无法确认】 —— 报告未提;但若你自建系统,值得统计早返回短样本里异常终止的比例。
  6. 参考实现:slime是 GLM 系列的 RL 框架,README 自述 "the RL framework behind GLM-5.3 / 5.2 / 5.1 / 5.0 / 4.7 / 4.6 / 4.5",走 Megatron + SGLang 路线,可作对照实现。

文献版本说明

本文所引 DeepSeek-V4.1-Flash 技术报告为原笔记记录的 2026-09-10、51 页版本(文件名 DeepSeek_V41_Tech_Report.pdf),页码对应这一版本。本次整理未获得可独立确认的公开下载链接,未将 PDF 打包进本站;涉及该报告的数值沿用原笔记,仍需对照原文复核。