Intro
Reinforcement learning (RL) on large language models (LLMs) samples responses with an inference engine (the rollout) and updates the weights with a separate trainer. On-policy methods such as PPO and GRPO assume the samples came from exactly the policy being updated: the trainer should give each sampled token the same probability the rollout did. In practice the two sides run different kernels on different batch shapes, sometimes at different precision, and in mixture-of-experts (MoE) models a small numerical difference can route a token to different experts. So the trainer scores each token with a slightly different probability than the policy that generated it, and training becomes off-policy without anyone choosing it. An off-policy update is biased unless a correction is added. True on-policy (TOP) RL removes that gap: in SGLang and Miles, the trainer reproduces the rollout's log-probabilities bit for bit.

This post explains what that involves and what it costs, on DeepSeek-V4-Flash and V4.1, GLM-5.2/5.3 and 5.3-Flash, and Qwen3, 3.5/3.6/3.8 and 3.8-Flash-Next. We compare against the common alternative, which we call standard: the usual rollout and training kernels. The mismatch is corrected separately by R3 (the trainer replays the rollout's MoE routing) and TIS (truncated importance sampling). Six takeaways:
- Exact across models. On every model above, the trainer's log-probabilities equal the rollout's on every token.
- Full RL runs. We trained TOP next to standard + R3 + TIS on DeepSeek-V4-Flash, V4.1 and GLM-5.2 synchronously, and on Qwen3.6 asynchronously on multi-turn text-to-SQL. TOP's train/rollout log-prob difference was zero on every fresh token; reward and evaluation curves for both arms are below.
- Staleness without kernel mismatch. In asynchronous RL the importance weight covers two gaps: weight lag, as the trainer scores tokens that older weights sampled, and kernel mismatch at equal weights. TOP removes the kernel mismatch and leaves the weight lag. In our Qwen3.6 run the kernel mismatch is 0.006–0.0095 per token with standard kernels and zero with TOP. With no cap on the importance weight, TOP with routing replay stays smooth, while standard + R3 and TOP without replay both lose accuracy mid-run.
- One design across model families. Each model is a binding from its modules to shared ops with fixed numerical contracts, so adding a model reuses the matching ops and implements only what is new. The trainer side integrates with Megatron through Miles.
- Exactness at practical speed. On 64 H200s, whole-step token throughput is 0.90× standard's on DeepSeek-V4-Flash and 0.93× on GLM-5.2. Rollout token rate is 0.79× and 0.88×. The sections below break the cost down by kernel, memory and parallelism.
- Agents add and maintain models. An agent added DeepSeek-V4.1 support end to end in under 8 hours. It followed a written skill, which we updated twice during the run.
Code: the SGLang and Miles changes, the model-support skill, and the gate tests, and launch recipes for the experiments will be released as branches of the SGLang and Miles repositories.
Exact across models
Every family below passes bitwise forward parity at full depth. "Exact" means the trainer's FP32 log-prob bytes equal the rollout's on every token. This holds with speculative decoding on, for every family that uses it. TOP has been tested on Hopper and Blackwell GPUs.
| Model | Precision |
|---|---|
| DeepSeek-V4-Flash | FP8 |
| DeepSeek-V4.1-Flash | FP8 |
| GLM-5.2 / 5.3 | FP8 |
| GLM-5.3-Flash | BF16 |
| Qwen3 dense | BF16 |
| Qwen3.5 family | BF16 |
| Qwen3.8-Flash-Next | BF16 |
FP8 here is blockwise, with power-of-two scales. DeepSeek-V4.1 uses FP8 dense weights and converts its MXFP4 experts to FP8 at load on Hopper; it was added by an agent. TOP also takes image inputs on the Qwen3.5 family (including 3.6 and 3.8), Qwen3.8-Flash-Next and DeepSeek-V4.1.
Parallelism. Both sides use tensor parallelism (TP) of degree 1. The trainer combines pipeline (PP), context (CP), and expert parallelism (EP); rollout uses attention data parallelism (DP) with EP.
Training runs
The table above checks that trainer and rollout agree token by token; this section follows that agreement through whole RL runs. We trained TOP next to standard + R3 + TIS on four models: DeepSeek-V4-Flash (DS4), GLM-5.2 and DeepSeek-V4.1 (DS4.1) synchronously, then Qwen3.6-35B-A3B asynchronously. DS4.1 is in the agent section below. Within a pair, both arms use the same data, batch and learning rate; the settings under each figure list what differs. In the synchronous runs, TOP uses neither R3 nor TIS, and its train/rollout log-prob diff was 0.0 at every step. In the asynchronous run, the TOP arm is TOP + R3: stale weights change expert routing, so the trainer replays the rollout's routing, and it runs without a cap on the importance weight.


In the asynchronous Qwen3.6 run, fresh tokens matched the rollout bit for bit. Its log-prob difference panel includes stale tokens, so TOP + R3's is not zero there: it is weight lag alone. The Staleness section below separates the parts.

Staleness: separating weight lag from kernel mismatch
Large RL runs increasingly go asynchronous, largely to escape the rollout tail: instead of waiting while a few long responses decode nearly alone, the trainer starts on what is ready, so it scores tokens that older weights sampled. The natural question is whether exactness still matters once tokens are stale anyway. The gap between trainer and rollout has two parts: weight lag, which the staleness bound controls, and kernel mismatch at equal weights, which nobody chooses. With standard kernels both land in one number; TOP makes the second part zero, so what remains is lag alone. The async Qwen3.6 runs let us measure each part.
The kernel part. At equal weights (lag 0), the standard arm's trainer and rollout differ by 0.006–0.0095 per token, about a tenth to a half of the lag term in the TOP + TIS run (0.020–0.058 per token), and the two disagree on 94–98% of tokens. TOP's kernel part is zero at every check.

The lag part. Stale tokens give the importance weights a heavy tail, and left uncapped a few tokens can carry most of an update. Truncating the weight at 2 (an upper bound only) keeps both TOP + TIS and standard + R3 + TIS smooth, as the Arcwise-Plat panel above shows. Without a cap, TOP and standard + R3 both see weights in the thousands and lose accuracy mid-run, while TOP + R3 stays smooth. Routing changes are most of TOP's tail. They are also why TOP + TIS's total log-prob difference is larger than standard's, and with routing replayed it falls below standard's. How much correction to apply remains a choice of the training recipe; what TOP changes is that the quantity being corrected is exactly the lag.

Design
This section explains how the trainer reproduces the rollout exactly. It builds on SGLang's deterministic inference, which made the rollout engine batch-invariant, and extends it to the trainer. TOP is organized around ops: computations such as a linear projection, attention, MoE routing or a recurrent update. Each op has a numerical contract that fixes how it is computed in both the rollout engine and the trainer.
The contract controls three ways a token's result can change between rollout and training:
- Batch shape. Fixed kernel tiles and a fixed reduction order keep a token's result independent of which other requests are in the batch.
- Serving schedule. Each token’s row is computed in the same order as in the trainer’s prefill. That holds in prefill and in decode, wherever the prompt is chunked, after a prefix-cache hit, and when a retracted request resumes.
- Placement. Expert results are combined in a fixed order whatever the expert-parallel size, and a token's row is the same on whichever data-parallel rank computes it.
TOP also keys each sampled token to the request's seed and position, so the tokens, not only their log-probs, do not depend on how the rollout was served.
Miles supplies the model bindings. Megatron builds its layers from a ModuleSpec tree. Miles substitutes TOP modules through that interface, or subclasses a Megatron module to replace one operation. The adapters call rollout ops in forward and supply backward implementations for training. They preserve Megatron’s parameter interfaces, so its optimizer, checkpointing and pipeline schedule continue to manage the model.
Miles also installs runtime wrappers where there is no module to replace, including a wrapper that keeps activation recomputation batch-invariant. The Megatron-side additions are generic kernel hooks and pipeline-shape support; the model-specific trainer bindings stay in Miles.
Ops are shared across model families: a binding maps each of a model's modules to an op contract, so adding a model reuses the matching ops and implements only what is new.
The cost of exactness
Exactness has costs in time, memory and parallel execution. FP8 checkpoints add a numerical pitfall: small updates can disappear when weights are rounded back to FP8.
Time. TOP fixes kernel tiles and reduction order to preserve each token’s arithmetic across batch shapes. The plot ranks the added time per decode iteration (ms) and show which costs stay roughly fixed as concurrency grows. The trainer follows the same arithmetic, including during recomputation. The largest single cost is GLM-5.2's decode attention: TOP decodes with the same sparse-attention kernel it uses for prefill, adding 2.2–2.8 ms per iteration. On Qwen3.6, TOP's MoE matrix multiply adds 1.3–1.7 ms.

Time: recurrent layers (GDN, KDA). TOP makes decode follow the same chunked arithmetic as prefill and training, adding work as concurrency grows: on Qwen3.6, 0.5 ms per decode iteration at 1 request and 2.0 ms at 128. GLM-5.3-Flash's KDA layers use the same design. For rollout-bound workloads, schedule replay offers another route: keep the standard rollout kernels, record the prefill/decode schedule, and replay it in the trainer. This avoids the extra rollout arithmetic at the cost of slower training; we plan to release it as a plugin.
Memory. TOP retains processed-weight caches and model-specific runtime state to reproduce rollout arithmetic. Its backward adapters also introduce temporary buffers for reference computations and expert-row transformations. These allocations contribute to memory overhead; their impact depends on the model and workload.
Parallelism. TOP adds costs where preserving arithmetic constrains parallel execution. TOP does not support tensor parallelism yet, so each GPU computes whole projections. This can hurt single-request latency, although DP can recover throughput across requests. For EP, preserving canonical expert-slot order and fixed-order output combination introduces reordering, buffering and combination work. Expert transport remains present during decode and can include waits for peer GPUs. With context parallelism on Qwen's GDN layers, later sequence shards wait for the recurrent state from earlier shards, adding transfers and synchronization.
Numerical: FP8 weights can lag behind master updates. The trainer keeps high-precision master weights and rounds them to FP8 for the forward pass. Masters loaded from an FP8 checkpoint sit at the center of their rounding cells, so when training rounds on the checkpoint's grid, small updates accumulate without changing any FP8 weight. Any setup that rounds on the checkpoint's grid stalls this way; TOP always does, because it must round as the rollout does. TOP therefore shifts each master once when initializing weights, by a deterministic offset within its cell, so that small updates cross boundaries sooner.

Rollout speed
We compare TOP and standard on H200 GPUs. For decode we use 8,192-token prompts, sweeping request concurrency with speculation on and off. Both arms run the same engine layout, attention DP with EP at TP1, the usual layout for batched MoE rollout. With speculation on, each arm keeps one deployment (layout and speculation setting) for the whole sweep, as an RL run must, and that deployment has to serve every load without capping or evicting requests. Tensor parallelism could lower the standard arm's latency at low concurrency; TOP does not support it yet (see Parallelism above). We swept the standard arm's tensor-parallel layouts as well: on DS4-Flash and GLM-5.2 none serves every load, and on Qwen3.6 TP2 does and is 1.3× faster than the shared layout at one request. Standard Qwen3.6 gets its recurrent-state pool sized for 128 requests, since the default pool caps concurrency under speculation. A speculation setting such as 1, 1, 2 gives the number of speculative steps, the top-k and the number of draft tokens. Decode speed is measured from the extra batch wall time needed to generate 257 tokens instead of 1. The plots report tokens/s per request, calculated from median timings across repeated runs with different seeds (TOP's sampling is deterministic, so identical repeats would retrace one trajectory). Prefill throughput is a batch's prompt tokens divided by the wall time to return one token per request, with the whole batch sent at once, an empty prefix cache and no speculation. We sweep prompt lengths from 1k to 16k tokens, once with a single request and once with a full batch of about 128k prompt tokens (128 × 1k down to 8 × 16k); each point is the median of six batches. A single request runs on one attention-DP rank, so its throughput sits well below the full batch. In full batches, TOP reaches 0.88–0.90 of standard's prefill throughput on DS4-Flash and about two thirds on GLM-5.2 and Qwen3.6, at every length; at 8,192-token prompts the ratio also holds from 8 to 128 concurrent requests. On 4 B200s, DS4-Flash decodes at 0.80–0.89× standard's speed without speculative decoding, in line with H200.


A whole training step
The sections above measure TOP's cost one piece at a time. A training step adds them up: rollout, then training, then the weight sync. In synchronous RL, training waits for the last responses to finish, so the low-concurrency rollout tail can widen the overall gap beyond what a high-concurrency decode benchmark suggests.
We compare elapsed time and token-normalized throughput from the same checkpoint and prompts at learning rate 0, with 64 H200s per arm and each arm's chosen micro-batch budget. We exclude the warmup step and report means over steps 1–5. For throughput, we divide total tokens by total time across those steps: generated tokens for rollout, and trained tokens (including prompts) for training and the whole step. Training uses the actor's training timer; whole-step time includes rollout, training, weight sync and lifecycle waits. Each arm is one run.
Without token normalization. Mean elapsed seconds are shown as TOP / standard, with the TOP / standard time ratio in parentheses; lower is faster.
| Phase | GLM-5.2 | DS4-Flash |
|---|---|---|
| Whole step | 357.9 s / 333.0 s (1.075×) | 414.4 s / 402.3 s (1.030×) |
| Rollout | 94.7 s / 83.3 s (1.137×) | 229.7 s / 198.1 s (1.159×) |
| Training | 160.7 s / 147.1 s (1.093×) | 107.0 s / 132.6 s (0.807×) |
Token-normalized throughput. Each ratio is TOP tokens/s divided by standard tokens/s; higher is faster.
| TOP / standard token rate | GLM-5.2 | DS4-Flash |
|---|---|---|
| Whole step | 0.93× | 0.90× |
| Rollout | 0.88× | 0.79× |
| Training | 0.91× | 1.14× |
The two tables differ where the arms process different numbers of tokens. On GLM, token counts differ by less than 0.3%. On DS4, TOP generates 7.8% fewer tokens and trains 7.7% fewer, so its gap is larger per token than in raw time. Trainer layouts: on GLM both arms use TP1/PP8/EP8/CP1; on DS4, TOP uses TP1/PP8/EP8/CP1 and standard TP4/PP4/EP8/CP1.
Agents add and maintain models
We added DeepSeek-V4.1 support with an agent following our model-support skill, which ships with the code so the community can use it to add their own models to Miles.
With a per-op contract, adding a model becomes a task with a fixed definition, which an agent can carry end to end.
The task an agent gets:
- Parity. Trainer log-probs equal rollout log-probs bit for bit across a weight sync, over at least two rollouts. Each module's backward matches its declared FP32 reference at the rollout weights, within measured floors.
- Method. The skill takes the agent from the model's config through the steps in the Design section above to passing forward and backward gates.
- Perf. A sanity comparison with the standard setup (TOP / standard rollout and training token rates, kernel timings, speculative accept length) flags fallback paths. The per-op measurements in the cost section above give the agent a reference, not a goal.
Demo: DeepSeek-V4.1. An agent (Claude Opus 5.5 at high effort, one session on one 8×H200 node) added DS4.1 from the release checkpoint (FP8 dense layers; MXFP4 experts, converted to FP8 at load because Hopper has no FP4), with its DSpark speculative decoder in the loop. It worked from a standalone model-support skill that contained nothing specific to DS4.1 when the run started. It ran in a fresh session on a fresh clone of the code, with instructions not to read our notes or look anything up online. In 7 h 51 min (no human input on the port apart from the two skill updates) it built every op and the family binding, matched the rollout's log-probs exactly, and checked DSpark on the full checkpoint.
As the agent implemented and tested the ops, it ran into two problems the skill did not check for: one in gradients through quantized forward passes, and one in speculative decoding's accept length compared with the standard setup. For each, we added the missing check to the skill, and the agent continued from the updated version; it finished within the hour. Both checks are now part of the skill, so every model it ports also runs them.
We then trained the agent-built DS4.1 for 100 steps, next to standard + R3 + TIS at the same recipe.

Maintenance. Each model binds a fixed set of ops, so an SGLang or Miles upgrade touches only the ops whose upstream code changed, and the bitwise train/rollout check flags any forward break on the first step. Rebasing TOP onto the Miles v0.2.0 release was one such upgrade: an agent resolved the merge conflicts in Miles and SGLang and ported TOP to Miles' typed configs in about five hours, most of it gate time, and the end-to-end gates passed on the result. We also have an internal maintenance skill that works from those failures; it needs more tests before we open-source it. The DS4.1 run makes us optimistic that agents can carry most of the engineering work of supporting and maintaining this feature.
CI. End-to-end gates for each family are registered for nightly GPU CI, so a change or a dependency bump that breaks exactness is caught early.
Acknowledgments
We thank the rest of the Miles team, the SGLang team, and both communities, and the slime, Together AI and vLLM/verl teams, whose earlier work on train-inference consistency informed ours.
Citation
Please cite this post as:
Yiming Li (RadixArk Miles Team), "True On-Policy RL: Bit-Exact Rollout and Training with SGLang and Miles", RadixArk: Miles Blogs, November 23, 2026.
Or use the BibTeX citation:
@article{li2026trueonpolicy,
author = {Yiming Li (RadixArk Miles Team)},
title = {True On-Policy RL: Bit-Exact Rollout and Training with SGLang and Miles},
journal = {RadixArk: Miles Blogs},
year = {2026},
note = {https://miles.radixark.com/blogs/true-on-policy-rl-bit-exact-rollout-and-training-with-sglang-and-miles}
}
AI 热点