Zero mismatched log-probs: bitwise on-policy RL for Qwen3-Omni across HF + FSDP and vLLM-Omni

TL;DR

  • The problem. On the 48-layer Qwen3-Omni thinker, with the same weights, the same tokens and already the same attention kernel on both sides, the trainer and the sampler disagreed on the log-prob of 2345–2902 response tokens per step, by up to 0.79 nats.
  • The result. With true_on_policy=true the count is 0: raw log-probs compared element by element, no tolerance, at every step, after real optimizer updates and weight syncs.
  • The coverage. Full-parameter and LoRA training, rollout tensor parallelism 1, 2 and 4.
  • The cost. Only the sampler gets slower, by 1.8 to 2.0 times, so the cost depends on how much of a step is generation. Measured whole-step time ranges from no measurable change to 20% longer on a rollout-heavy workload. Details and caveats in Cost.

Load the same weights into a trainer and a sampler. Feed both the same tokens. Ask each one for the log-probability of the next token. Do you get the same number?

The intuitive answer is yes. For the Qwen3-Omni thinker, trained with Hugging Face Transformers under FSDP2 in verl-omni and sampled with vLLM-Omni, the answer was no. On a 4-layer cut of the model every one of 8192 compared tokens came back different. On the full 48 layers, after I had already put the same attention kernel on both sides, it was still 2345 to 2902 tokens per step out of roughly 3.2k to 4.0k, and for the worst token the two engines were 0.79 nats apart. That is a factor of 2.2 in probability.

Why does that matter? PPO-style methods need the log-prob of each sampled token under the “old” policy. You can take the number the sampler reported, and then the ratio in the loss does not start at one. Or you can recompute it with the trainer, as verl does by default, and then the tokens were not drawn from the distribution you call the old policy. Either way the method is told it is on-policy while the arithmetic says otherwise.

So how close can the two sides get? This post is about making the answer “exactly”: the same bits, in the real training loop. It covers where the two engines diverge, how each difference was removed, how the gradient still works, and how the same idea extends to LoRA and to tensor-parallel rollouts.

One thing this post does not claim: that bitwise equality makes training converge better. I have not run that experiment, and I say so again in Not tested.

What has to match

“0-diff” is easy to say and easy to water down, so here is the definition I held every run to. For each training step, over the valid response tokens only:

  • the sampler and the trainer use the same weight version, the same token history and the same sampling distribution;
  • the raw log-probs have the same dtype, are all finite, and differ in zero elements.

And then it has to hold again after a real optimizer update and a weight sync, because a check that only passes on freshly loaded weights proves little.

Why insist on raw log-probs? verl already reported a difference between probabilities, taken after exp. That comparison hides a 1-ULP difference in the log-prob, which is exactly the kind of difference this work is about. The metric to watch is training/rollout_logprobs_mismatch_count, a plain count of elements that are not equal.

The mode also comes with a contract. Temperature 1, no top-p or top-k, no prefix caching, the synchronous trainer, and a few more. The trainer checks all of them at startup and lists every violation in one error, because a setting that silently breaks bitwise equality is worse than a run that refuses to start.

Where the two sides diverge

Before fixing anything I fed the same input to each operator on both sides and compared the outputs.

Operator HF actor vs vLLM-Omni rollout
synced weights, embedding, q/k/v/o and gate GEMMs, lm_head bitwise equal
log-prob from the same hidden state (fp32 log_softmax + gather) bitwise equal
RMSNorm, q/k norm 74% of elements equal: HF casts to bf16 before the weight multiply
residual + norm vLLM normalises the unrounded x + residual in one fused kernel
rope 73% equal
attention HF defaults to FlashAttention-2, vLLM picks FlashAttention-3 on Hopper: 240 of 304 tokens differ end to end
MoE the selected experts are identical; the routing weights are rounded at a different point and the expert GEMM differs

Two things stood out. The big matrix multiplies, the obvious suspects, were already equal. And the differences that remained were not bugs on either side. They were choices: where to round, which kernel to call, whether to fuse two operations.

There was a second, less obvious problem. Is the trainer even consistent with itself? It was not: packing the same sequence after a different one moved its log-probs by 3.3e-2. vLLM under VLLM_BATCH_INVARIANT=1 was self-consistent, decode against prefill and alone against a batch of 32. That made the rollout a valid target to aim at, and it meant the trainer needed batch-invariant operators too.

Aligning both sides

One way to do this is to pick one engine as the reference: the inference kernels define every value, and the trainer wraps them. This work splits it differently. Each difference is fixed on the side that owns it, and the Transformers layers keep their own forward.

changed to match the other side kept as is follows HF actor (Transformers + FSDP2) vLLM-Omni rollout Attention registered attention function calls the FlashAttention-3 varlen kernel FlashAttention-3 on Hopper as vLLM ships it MoE experts registered experts implementation returns the fused_experts output fused_experts kernel as vLLM ships it RoPE frequencies replacement rotary embedding elementwise fp32, stored as int32 bits elementwise fp32 unchanged Log-prob formula fp32 log_softmax, then gather replaces verl's two branches fp32 log_softmax, then gather the sampler's own formula TP > 1 partial sums splits o_proj and experts by rank adds partials in fp32, rounds once fixed-order fp32 all-reduce under batch invariance LoRA linears forward with W + B·A·scaling one merge shared with the export plain merged weights no LoRA operators RMSNorm, residual add, RoPE, MoE routing native Transformers modules unchanged hf_numerics custom ops Hugging Face order and rounding Batch invariance fsdp_config.batch_invariant switched on VLLM_BATCH_INVARIANT=1 switched on
Figure 1. Which side changes for each piece. An arrow points from the side that changed to the side it follows.

The trainer moves toward the sampler where the sampler runs a kernel that cannot reasonably change:

  • Attention. An attention function registered with Transformers’ AttentionInterface calls the FlashAttention-3 varlen kernel, the one vLLM runs on Hopper. It derives the sequence boundaries from the packed position ids.
  • MoE experts. An experts implementation registered with ExpertsInterface returns the output of vLLM’s fused_experts kernel. More on its gradient below.
  • Rope frequencies. A replacement rotary embedding multiplies positions and inverse frequencies elementwise in fp32, as the rollout does.
  • Log-prob formula. fp32 log_softmax over the full vocabulary, then gather: the formula the vLLM sampler uses. verl’s two existing branches were not bitwise equal to it; 4096 of 4096 and 559 of 4096 tokens differed.

The sampler moves toward the trainer where the difference is only operation order:

  • RMSNorm, residual add, rope, MoE routing. A thinker-stage option in vLLM-Omni, hf_numerics, runs these with Hugging Face’s order and rounding. Each one is a torch custom op, so torch.compile treats it as opaque and cannot fuse it back into different arithmetic, and it is still captured into CUDA graphs.

Why split it this way instead of moving everything to one side? Rewriting the trainer’s norm and routing to mimic fused inference kernels would have meant a second copy of the model code to maintain. Asking the sampler to follow a different rounding order for four cheap operators was the smaller change, and it left the expensive kernels, attention and the experts, exactly as vLLM ships them.

The rope piece shows how small a cause can be. Casting the model to bf16 also rounds Hugging Face’s inverse-frequency buffer to bf16, while the rollout keeps it in fp32. With that one buffer wrong, 1724 of 1728 tokens mismatched on a tiny model. The replacement stores the frequencies as int32 bits so the cast cannot touch them.

Forward from one kernel, gradient from another

The first question this raises: if the trainer’s forward now runs inference kernels, how does it train?

The observation that makes this tractable is that 0-diff constrains the forward values only. The backward pass is not compared with anything, so it does not have to be bitwise equal to anything. Each piece gets its gradient in whatever way is correct and cheap:

Piece Forward value Backward
attention hub FlashAttention-3 kernel the kernel’s own backward
MoE experts vLLM fused_experts, under no_grad Transformers’ grouped_mm experts on the same inputs
RMSNorm, residual, routing native Transformers modules ordinary autograd
rope elementwise fp32, under no_grad none needed, no parameters
log-prob fp32 log_softmax + gather ordinary autograd

The experts are the interesting case. fused_experts has no backward at all. So the forward runs twice: once through the fused kernel for the value, once through grouped_mm to build a graph, and a small autograd function returns the first while sending the gradient to the second.

class _ValueWithGradientOf(torch.autograd.Function):
    """Returns ``value`` and sends its gradient to ``reference``."""

    @staticmethod
    def forward(ctx, reference, value):
        return value.view_as(value)

    @staticmethod
    def backward(ctx, grad_output):
        return grad_output, None

Is that gradient “right”? It is the exact gradient of grouped_mm at the same inputs, and the two forwards differ only by rounding. As a sanity check on the same idea for attention, gradients with the registered kernel were within 1.4e-3 to 2.0e-2 relative L2 of Hugging Face’s sdpa path, the same range as Hugging Face’s own eager path against sdpa. The price is that the experts run twice per MoE layer whenever gradients are needed.

LoRA

Full-parameter training of a 31.7B-parameter model is not what most people run. Does the same guarantee survive LoRA?

Not for free. With merged LoRA the sampler receives plain weights W + B @ A * scaling and has no LoRA operators at all. PEFT’s forward on the trainer computes something else: base(x) + B(A(x)) * scaling. Same mathematics, different rounding.

The fix is to make the trainer’s LoRA linears forward with the merged weight, so both sides run one linear on one weight. The gradient still reaches A and B, because the merge is part of the autograd graph.

That was the plan, and on a tiny model it worked. On the 48-layer model it failed with thousands of mismatches per step. What was different? I went through three hypotheses. Two were wrong, and offline experiments ruled them out: a matmul computed in row shards is bitwise equal to the whole one, and so is a product of sharded tensors. The third held:

The same bf16 matmul gives different results on CPU and on GPU. For a rank-32 B @ A of the size of a real projection, 179 of 8,388,608 elements differed. In fp32, none did.

With parameter offload, the adapter shards sit on the CPU when weights are exported, so the sampler was getting a merge computed on CPU while the trainer’s forward merged on GPU. About two hundred elements per projection, each off by one bf16 step, were enough.

So the rule became: one definition of the merge, shared by export and forward: whole tensors rather than shards, in the forward dtype, on the training device. With that, the 48-layer runs went to zero. I should also say what I did not find out: an intermediate version that merged on the shards and then moved the result to the GPU still failed, and I never pinned down why.

Tensor-parallel rollouts

The recipes run the rollout with tensor parallelism, so a mode that only works at TP=1 is a demo. What changes at TP=2?

With TP, vLLM’s row-parallel layers, the attention output projection and the MoE experts, compute one bf16 partial result per rank. Under batch invariance the all-reduce then adds the partials in fp32, in rank order, and rounds once. A single matmul over all the features, which is what the trainer does, rounds differently.

So the trainer replays the sampler’s sum. It splits the same two layers by rank and adds the partial results the same way:

def _tensor_parallel_sum(partials: list[torch.Tensor]) -> torch.Tensor:
    total = partials[0].float()
    for partial in partials[1:]:
        total = total + partial.float()
    return total.to(partials[0].dtype)

The column-parallel layers, q/k/v, the embedding and lm_head, needed no change. And the control behaves as it should: with a TP=4 rollout and a trainer that sums over 2 ranks, 2524 to 2625 tokens per step mismatch.

One hardware condition is worth knowing. Above two ranks the GPUs have to be fully connected, otherwise vLLM does not use its fixed-order all-reduce.

Results

mode off mode on LoRA, natural length 0% 25% 50% 75% 100% 1 2 3 4 5 6 7 mode off, step 1: 2,676 of 3,671 response tokens mode off, step 2: 2,489 of 3,523 response tokens mode off, step 3: 2,569 of 3,515 response tokens mode off, step 4: 2,692 of 3,655 response tokens mode off, step 5: 2,517 of 3,329 response tokens mode off, step 6: 2,561 of 3,475 response tokens mode off, step 7: 2,398 of 3,272 response tokens 2,398 to 2,692 per step mode on, step 1: 0 of 3,647 response tokens mode on, step 2: 0 of 3,006 response tokens mode on, step 3: 0 of 3,260 response tokens mode on, step 4: 0 of 3,250 response tokens mode on, step 5: 0 of 3,362 response tokens mode on, step 6: 0 of 3,420 response tokens mode on, step 7: 0 of 3,295 response tokens 0 at every step LoRA, 1,024 tokens 1 2 3 4 5 6 7 mode off, step 1: 29,259 of 32,768 response tokens mode off, step 2: 29,997 of 32,768 response tokens mode off, step 3: 30,116 of 32,768 response tokens mode off, step 4: 30,163 of 32,768 response tokens mode off, step 5: 30,049 of 32,768 response tokens mode off, step 6: 30,061 of 32,768 response tokens mode off, step 7: 30,302 of 32,768 response tokens 29,259 to 30,302 per step mode on, step 1: 0 of 32,768 response tokens mode on, step 2: 0 of 32,768 response tokens mode on, step 3: 0 of 32,768 response tokens mode on, step 4: 0 of 32,768 response tokens mode on, step 5: 0 of 32,768 response tokens mode on, step 6: 0 of 32,768 response tokens mode on, step 7: 0 of 32,768 response tokens 0 at every step Full-parameter, 1,024 tokens 1 2 3 4 5 6 7 mode off, step 1: 29,628 of 32,768 response tokens mode off, step 2: 30,243 of 32,768 response tokens mode off, step 3: 30,138 of 32,768 response tokens mode off, step 4: 30,438 of 32,768 response tokens mode off, step 5: 29,709 of 32,768 response tokens mode off, step 6: 29,899 of 32,768 response tokens mode off, step 7: 29,601 of 32,768 response tokens 29,601 to 30,438 per step mode on, step 1: 0 of 32,768 response tokens mode on, step 2: 0 of 32,768 response tokens mode on, step 3: 0 of 32,768 response tokens mode on, step 4: 0 of 32,768 response tokens mode on, step 5: 0 of 32,768 response tokens mode on, step 6: 0 of 32,768 response tokens mode on, step 7: 0 of 32,768 response tokens 0 at every step training step y: share of response tokens whose log-prob differs between rollout and actor (counts under each line)
Figure 2. Response tokens whose log-prob differs between rollout and actor, per training step, with a TP=2 rollout. Mode off keeps the FlashAttention-3 kernel on the actor and switches everything else off.

Every row is the 48-layer thinker (31.72B parameters, 28.99B of them in the experts) on H20 GPUs, with CUDA graphs on the rollout.

Training Rollout TP Steps Mismatched tokens, mode on Mode off
full-parameter, experts frozen 1 5 × 32768 tokens 0 2345–2902 per step
full-parameter, experts trainable 1 and 2 9 0  
full-parameter, experts trainable, recipe memory layout 2 5 0 2070–2655 per step
LoRA 1 and 2 3–4 per run 0 2259–2724 per step
LoRA, full-parameter frozen and trainable 4 10 0  
LoRA, full-parameter frozen and trainable, every response 1,024 tokens 2 7 per run 0 29259–30438 per step

Is a run at a small learning rate a trivial test, though? It is a fair worry. At the recipe’s learning rate of 3e-6 with bf16 weights, only 1.38% to 3.92% of the expert elements change at each sync, each by one bf16 step. So I also ran at 1e-4, where 38.8% to 79.0% change, and the count stayed at zero.

TP=4 was measured on a single 4×H20 machine with every pair of GPUs connected by NVLink.

Cost

What does a training step cost with the mode on? I only report whole-step time here, with the workload next to every number, because a rollout benchmark on its own says little about a training run.

rollout generation old log-prob recompute actor update weight sync other seconds per training step, mean of steps 2 to 7 0 10 20 30 0 30 60 90 mode off · rollout generation: 1.81 s mode off · old log-prob recompute: 1.36 s mode off · actor update: 2.70 s mode off · weight sync: 6.40 s mode off · other: 0.30 s 12.6 mode off mode on · rollout generation: 3.32 s 3.3 mode on · old log-prob recompute: 1.24 s mode on · actor update: 2.37 s mode on · weight sync: 3.96 s mode on · other: 0.30 s 11.2 mode on on + bypass_mode · rollout generation: 3.50 s 3.5 on + bypass_mode · old log-prob recompute: 0.05 s on + bypass_mode · actor update: 2.42 s on + bypass_mode · weight sync: 3.80 s on + bypass_mode · other: 0.28 s 10.1 on + bypass LoRA natural length mode off · rollout generation: 10.99 s 11.0 mode off · old log-prob recompute: 2.52 s mode off · actor update: 8.56 s mode off · weight sync: 7.02 s mode off · other: 0.28 s 29.4 mode off mode on · rollout generation: 21.41 s 21.4 mode on · old log-prob recompute: 1.84 s mode on · actor update: 6.62 s mode on · weight sync: 4.03 s mode on · other: 0.28 s 34.2 mode on on + bypass_mode · rollout generation: 21.59 s 21.6 on + bypass_mode · old log-prob recompute: 0.05 s on + bypass_mode · actor update: 6.73 s on + bypass_mode · weight sync: 3.89 s on + bypass_mode · other: 0.27 s 32.5 on + bypass LoRA 1,024 tokens forced mode off · rollout generation: 11.10 s 11.1 mode off · old log-prob recompute: 2.54 s mode off · actor update: 9.62 s mode off · weight sync: 4.78 s mode off · other: 0.29 s 28.3 mode off mode on · rollout generation: 20.82 s 20.8 mode on · old log-prob recompute: 1.80 s mode on · actor update: 7.53 s mode on · weight sync: 3.62 s mode on · other: 0.27 s 34.1 mode on Full-parameter frozen experts 1,024 forced recipe memory layout, 4 GPUs, its own scale mode off · rollout generation: 9.90 s 9.9 mode off · old log-prob recompute: 19.76 s mode off · actor update: 26.09 s mode off · weight sync: 22.22 s mode off · other: 0.27 s 78.2 mode off mode on · rollout generation: 19.84 s 19.8 mode on · old log-prob recompute: 17.69 s mode on · actor update: 23.45 s mode on · weight sync: 21.14 s mode on · other: 0.28 s 82.4 mode on Full-parameter trainable experts 1,024 forced
Figure 3. Whole-step time by phase. 48-layer thinker, TP=2 rollout, 16 prompts × 2 samples per step, one run per arm. The first three groups run on two H20 GPUs with the rollout engine kept loaded. The last one uses the recipe's memory layout on four GPUs, where training and generation take turns on the GPU memory, and has its own scale.

The same numbers as a table, in seconds. “Natural length” is about 3,300 response tokens per step; “1,024 tokens” forces every response to the length limit, 32,768 response tokens per step.

Workload Arm Step Generation Old log-prob Actor update Weight sync
LoRA, natural length mode off 12.57 1.81 1.36 2.70 6.40
  mode on 11.20 3.32 1.24 2.37 3.96
  on + bypass_mode 10.06 3.50 0.05 2.42 3.80
LoRA, 1,024 tokens mode off 29.37 10.99 2.52 8.56 7.02
  mode on 34.18 21.41 1.84 6.62 4.03
  on + bypass_mode 32.54 21.59 0.05 6.73 3.89
Full-parameter, experts frozen, 1,024 tokens mode off 28.32 11.10 2.54 9.62 4.78
  mode on 34.05 20.82 1.80 7.53 3.62
Full-parameter, experts trainable, 1,024 tokens, recipe memory layout mode off 78.24 9.90 19.76 26.09 22.22
  mode on 82.41 19.84 17.69 23.45 21.14

“Mode off” is the same recipe with true_on_policy=False and batch invariance off on both sides. The actor keeps the FlashAttention-3 kernel, so the control differs from the mode in the alignment work only, not in the attention kernel.

So where does the time go? Into generation, and only there. The rollout is 1.8 to 2.0 times slower with the mode on. A standalone rollout benchmark at TP=2 puts most of that on vLLM’s batch-invariant mode rather than on the Hugging Face-order operators: 3243 tokens/s by default, 1749 with batch invariance alone, 1497 with both.

And the trainer? Running the experts twice should cost something. It did not show up: both the old log-prob pass and the actor update were a little faster with the mode on in every pair. I have not profiled why.

What does that add up to for a whole step? It depends on how much of the step is generation.

  • Rollout-heavy steps (every response forced to 1,024 tokens): 16% longer with LoRA, 20% longer with full-parameter training and frozen experts, and 5% longer with trainable experts under the recipe’s memory layout. That layout offloads parameters and optimizer state to the CPU between phases, so the three trainer-side phases take 62 to 68 s of a roughly 80 s step and the same extra generation time weighs less.
  • With bypass_mode (LoRA): 11% longer instead of 16%. Once the two sides are bitwise equal, recomputing the old log-probs on the trainer returns the numbers the sampler already reported, so the pass can be skipped. That saves 1.1 to 1.6 s per step here.
  • Short responses, LoRA: the step is 1.4 s shorter with the mode on. Is bitwise equality somehow faster? No. I timed the weight sync piece by piece, and the whole gap is in one place: merging the adapters into the base weights takes 2.6 s per sync with the mode off and 0.4 s with it on. The mode merges whole tensors in bf16 on the GPU, while the default export follows PEFT’s merge on each rank’s shards. The receiving side takes the same time either way. So the saving belongs to that merge path, not to on-policy training, and it also sits inside the LoRA figure above: with weight sync left out of both arms, the rollout-heavy LoRA step is 35% longer rather than 16%.
  • Short responses, full-parameter: there is no merge to save on, and the step is 1.4 s longer with the mode on, 11.93 s against 10.53 s.

One measurement trap is worth passing on. The trainer checks for finished rollouts every 2 s by default, so the generation time it reports is rounded up to a multiple of 2 s. My first set of runs said 2.03 s against 4.03 s for the short workload, which could have meant almost any real difference. The numbers above were measured with a 0.05 s poll, and all but one arm came out 0.6 to 1.6 s shorter per step than under the default.

Two older measurements cover what the table does not, both taken with the 2 s poll and short responses, one run each. With the experts trainable and the recipe’s memory layout at TP=2, a short-response step took 56.29 s with the mode off and 55.61 s with it on, and single steps ranged from 54.0 to 57.4 s. With a TP=1 rollout, LoRA took 12.89 s both ways, and full-parameter training with frozen experts took 10.70 s off against 14.48 s on.

Keeping it at zero

Bitwise equality is brittle by nature. One kernel swap in a dependency and it is gone, and nothing crashes. How do you keep it?

  • The startup contract rejects the settings that break it.
  • A gate trains a tiny random thinker on two GPUs and checks that the count is zero at steps 1 and 2, with a nonzero gradient norm in between. A third stage does the same with merged LoRA.
  • A CPU test compares the vLLM-Omni norm, residual, rope and routing ops with the Transformers modules bit for bit on every CI run. It cannot see kernel-level differences, so the gate has to be rerun after a vLLM, CUDA or cuBLAS upgrade.

The equal GEMMs deserve the same caution. They came out bitwise equal in every run at the pinned versions. That is a measurement, not something the kernels promise.

Not tested

  • A real dataset, and whether bitwise equality changes convergence. Every run above used dummy text data for a handful of steps.
  • Multimodal inputs. The mode covers text-only prompts, and the actor raises on a batch with image, video or audio features.
  • GPUs other than Hopper.
  • Repeated runs. Most arms ran once.
  • Where two timing differences come from. In the rollout-heavy full-parameter runs the control spent 1.2 s longer in weight sync, which did not show up with short responses. And the trainer-side passes are slightly faster with the mode on. Both are measured in Cost and neither is explained.
  • TP values other than 1, 2 and 4.

Status and thanks

The full-parameter mode is merged in verl-omni (#898); the usage is in the docs. LoRA and tensor parallelism are in open pull requests, verl-omni #952 (still a draft) and vllm-omni #11051, and TP above 1 needs that vLLM-Omni change.

This builds directly on other people’s work: the DeepSeek-V4 true on-policy recipe in verl (#7688), vLLM’s batch invariance, and Thinking Machines’ post on batch-invariant kernels. The pieces of this work outside verl-omni are verl #8025, verl #8026 and vllm-omni #8186.

AI assistance was used for the implementation and the experiments.




Enjoy Reading This Article?

Here are some more articles you might like to read next: