On DeepSeek-V4-Flash (43 layers) and DeepSeek-V4.1-Flash (40 layers), LoRA GRPO runs in verl where every response token’s rollout log-prob is bitwise identical to the trainer’s recompute, at every one of 100 steps, while the adapters change. The kernels come from RL-Kernel ; verl and vLLM are unmodified.

We first explain why the mismatch matters and how RL-Kernel plugs into verl, then what makes DeepSeek-V4 hard to keep batch-invariant, and then follow both models through 100 steps against verl’s existing DeepSeek-V4 paths.

Key takeaways

  • Zero mismatch, at full model size. verl’s training/rollout_logprobs_mismatch_count is 0 at all 100 steps on DeepSeek-V4-Flash (43 layers) and DeepSeek-V4.1-Flash (40 layers), each on one node of 8 × H200. The DeepSeek-V4 LoRA recipe of verl#7483 mismatches on 616k response tokens per step on the same setup.
  • No change to verl or vLLM. RL-Kernel enters through model.external_lib (an engine backend) and vLLM’s worker_cls / worker_extension_cls. The example and guide are in verl#9033 .
  • The kernels are what closes the gap. With batch invariance turned off in our rollout only, 156k to 437k tokens per step mismatch again.
  • It costs time per step. A DeepSeek-V4 step takes 296 s against the baseline’s 228 s; the trainer side is faster, generation is slower.
Training reward, AIME 2024 accuracy and log-prob gap over 100 steps for RL-Kernel and the verl#7483 recipe on DeepSeek-V4-Flash
Figure 1. DeepSeek-V4-Flash (43 layers), 8 × H200, 100 GRPO steps. Left: training reward; thin lines are the per-step batch mean, bold lines the trailing 10-step mean. Middle: AIME 2024 accuracy with greedy decoding, evaluated at step 0 and every 10 steps; the vertical axis starts at 0.55. Right: mean \(\lvert \log p_{\text{actor}} - \log p_{\text{rollout}} \rvert\) per response token; RL-Kernel’s line is exactly 0 at every step. One run per configuration, no confidence bands; the two sides use different LoRA target sets.

Why mismatch matters

The rollout engine samples a token and records its log-prob; the trainer recomputes that log-prob with the same weights. Before any update the two should be equal, so the importance ratio is exactly 1. When they differ, the ratio carries numerical noise that the optimizer cannot tell apart from a real policy change. On a mixture-of-experts model a last-bit difference can also flip a routing decision, and the token then goes through different experts.

verl reports the gap directly: training/rollout_logprobs_mismatch_count counts the response tokens whose rollout and recomputed FP32 log-probs differ, with no tolerance. This post is about driving that number to 0 and keeping it there.

How it plugs into verl

Both sides of the run use one set of batch-invariant kernels: the trainer through an engine backend, the rollout through a vLLM model plugin. Nothing in verl or vLLM is patched; everything goes through extension points verl already has.

Pieceverl extension point
Traineractor_rollout_ref.model.external_lib imports RL-Kernel’s module in every worker, which registers an rlkernel backend in verl’s EngineRegistry; model_engine=rlkernel selects it, with its config group added through hydra.searchpath.
Rolloutrollout.engine_kwargs.vllm.worker_cls / worker_extension_cls give vLLM a worker that runs RL-Kernel’s model code and receives the adapters. vLLM keeps its scheduler, KV cache management and sampling.
Weight syncThe rollout loads the frozen base weights from the checkpoint (rollout.load_format=auto); only the BF16 LoRA adapters are synced each step.
Checkrollout.calculate_log_probs=True, so verl compares the two log-probs every step.

The switch is one block of overrides:

"hydra.searchpath=[pkg://rl_engine.integrations.dsv4.verl_config]" \
model_engine=rlkernel \
actor_rollout_ref.model.external_lib=rl_engine.integrations.dsv4.verl_engine \
actor_rollout_ref.actor.rlkernel.lora_rank=16 \
actor_rollout_ref.actor.rlkernel.lora_alpha=32 \
actor_rollout_ref.rollout.load_format=auto \
actor_rollout_ref.rollout.calculate_log_probs=True \
+actor_rollout_ref.rollout.engine_kwargs.vllm.worker_cls=rl_engine.integrations.dsv4.vllm_worker.RlkWorker \
+actor_rollout_ref.rollout.engine_kwargs.vllm.worker_extension_cls=rl_engine.integrations.dsv4.vllm_worker.RlkWorkerExtension

Two details took time to get right:

  • The LoRA rank goes in actor.rlkernel.lora_rank, and model.lora_rank stays 0. A nonzero model.lora_rank turns on vLLM’s own LoRA in the rollout, which would bypass RL-Kernel’s model code.
  • The rollout sleeps at level 1. Since verl then sees no LoRA, it asks the rollout for sleep level 2, which drops the base weights; RL-Kernel’s worker keeps level 1 so the base weights survive the training phase and only the adapters move.

How this differs from fsdp_config.batch_invariant

verl’s fsdp_config.batch_invariant makes an FSDP actor run vLLM’s batch-invariant kernels. Here neither side runs vLLM’s kernels: RL-Kernel supplies the attention, MoE, mHC, quantized linear and log-prob kernels for both, which is what DeepSeek-V4’s compressed sparse attention, FP4 experts and mHC need.

What makes DeepSeek-V4 hard

A kernel is batch-invariant when a token’s result does not depend on what else is in the batch. Most fast kernels are not: they pick split counts, workspaces and tile shapes from the batch, and each choice changes the order of a floating-point sum. DeepSeek-V4 adds several places where that matters:

  • mHC mixes four residual streams through a controller GEMM over K = 16,384 per token, followed by Sinkhorn normalization; a batch-dependent split changes every stream.
  • Compressed sparse attention selects the top 512 compressed KV entries per query. A tie in the top-k or a different accumulation order changes the result, and a KV entry rounded differently affects every later token that reads it.
  • The router is discrete: a last-bit difference in a score can change the sixth expert.
  • The MXFP4 routed experts have no batch-invariant fused kernel on Hopper; existing ones assign rows to slots with atomics.

RL-Kernel fixes the order of every sum in the kernel, sizes every workspace from the config rather than the batch, runs prefill and decode through the same code path, and across GPUs only moves bytes (data-parallel attention with expert-parallel MoE, exchanged in a fixed order). Expert parallel 2, 4 and 8 reproduce the bytes of a single GPU. The module-by-module account is in RL-Kernel’s DeepSeek-V4 post .

DeepSeek-V4.1 reuses most of these kernels. It adds MXFP8 dense weights, a single-pass mHC, compressed KV and top-k indices shared across layers, and the Engram n-gram memory; the DeepSeek-V4.1 post covers what changed.

Results

DeepSeek-V4-Flash

Both runs train all 43 layers on one node of 8 × H200 for 100 GRPO steps: DAPO-Math-17k with verl’s DAPO reward, 32 prompts × 16 responses per step, responses up to 4,096 tokens, LoRA rank 16, AIME 2024 with greedy decoding every 10 steps. They share the verl commit, data, reward, batch, optimizer and PPO settings. The baseline is the DeepSeek-V4 LoRA recipe of verl#7483, each side with its own LoRA target set.

RL-Kernel + verlverl#7483 recipe
TrainerRL-Kernel engine backend, EP 8Megatron, EP 8
RolloutvLLM + RL-Kernel model plugin, DP 8 / EP 8vLLM 0.32 with its own LoRA, DP 8 / EP 8
Mismatched response tokens per step0 at all 100 steps616k on average (344k to 1.01M)
Mean \(\lvert\Delta \log p\rvert\) per response token00.096
AIME 2024, step 0 → 1000.63 → 0.800.61 → 0.65
Time per step296 s228 s

The two runs also differ in how training behaved (Figure 1). The baseline’s 10-step mean reward ranges from about 0.12 to 0.49 and its AIME 2024 accuracy dips to 0.56 at step 40; the RL-Kernel run’s reward stays between about 0.48 and 0.68. These are single runs, and the two LoRA configurations are not identical, so we read this as an observation rather than a controlled result. To isolate the kernels, we also turned batch invariance off in our rollout only and kept everything else: 156k to 437k tokens per step mismatched again.

DeepSeek-V4.1-Flash

Training reward and log-prob gap over 100 steps for RL-Kernel on DeepSeek-V4.1-Flash, with the log-prob gap of verl's native path on an 8-layer cut
Figure 2. DeepSeek-V4.1-Flash, 8 × H200, 100 GRPO steps. Left: RL-Kernel’s training reward on all 40 layers; thin line per step, bold line the trailing 10-step mean. verl’s native path is not plotted: its 8-layer cut scores −2 at every step. Right: mean \(\lvert \log p_{\text{actor}} - \log p_{\text{rollout}} \rvert\) per response token; RL-Kernel (40 layers) is exactly 0 at every step, verl with NeMo Automodel is measured on its 8-layer cut. One run per configuration.

All 40 layers on 8 × H200, 100 GRPO steps, DAPO-Math-17k, 32 prompts × 8 responses, responses up to 2,048 tokens, LoRA rank 16, decode CUDA graphs in the rollout (Figure 2).

RL-Kernel + verlverl with NeMo Automodel
Model that fits on 8 × H200all 40 layersfirst 8 layers only
Mismatched response tokens per step0 at all 100 steps523k on average (8-layer cut)
Time per step175 snot comparable

verl’s native DeepSeek-V4.1 path dequantizes the routed experts to BF16 (about 1,087 GB for 40 layers), so only an 8-layer cut fits, and that cut cannot generate a valid response. We take only its mismatch count from it, as a reference.

Try it

The example is examples/tuning/lora/run_deepseek_v4_rlkernel.sh from verl#9033 ; it picks V4 or V4.1 from the checkpoint.

VERL_ROOT=/path/to/verl-pinned MODEL_PATH=/models/DeepSeek-V4-Flash DATA=/data/dapo \
  bash examples/tuning/lora/run_deepseek_v4_rlkernel.sh

Pinned versions

verl’s main does not load DeepSeek-V4.1 yet; verl#7483 adds the config and prompt support. Until it is merged, the example is pinned to commit 8c047f4d of that pull request, which VERL_ROOT puts first on PYTHONPATH. The guide (docs/advance/rl_kernel_zero_mismatch.md in verl#9033) lists the full tested set and how to build the environment.

Limitations and what’s next

  • Hopper only, one node. The kernels target SM90; every result here is from one node of 8 × H200. Other architectures need their own validation.
  • Rollout speed. A DeepSeek-V4 step takes 1.3× the baseline’s time. The trainer side is faster; generation is 1.77× slower per token, of which batch invariance accounts for 12 to 14% and RL-Kernel’s rollout stack for the rest.
  • One parallel layout. Data-parallel attention with expert-parallel MoE; tensor and context parallelism inside attention are not supported yet.
  • LoRA only. Base weights stay frozen and all routed experts share one adapter. Per-expert adapters and full-parameter training are next.

Acknowledgments

This work builds on verl , vLLM , DeepGEMM and FlashMLA, all used unmodified, and on the DeepSeek-V4 support in verl#7483.

Core contributors

Kai-Jie Lin , Vensen Mu(EmbeddedLLM) , Jian Zhang , Jiajie Li , Xiaosong Ma , Huihong Lu , Ryan Huang , Hsiu-I Liao , Loring Ni , Bignonia7 , Yizheng Jiao , nodeeeeee , why1te , Junyifannnn , carsontung666 , Yang Liu , quan-yi-ai , AlanX-Yan , bitborne , Endeavor-19 , Yuteng-Chen .