Repository navigation
[RL] fix deepseek v4 MXFP8 flashinfer_trtllm_routed MoE weight update - #28676
Conversation
Signed-off-by: zhihaow6 <[email protected]>
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
zianglih
left a comment
There was a problem hiding this comment.
The cache was intentionally added there as a perf optimization, otherwise the weight update can be throttled by shuffle index recompute and take several minutes (https://github.com/sgl-project/sglang/pull/21280/changes#r2984699405) .
With the cache optimization the entire weight update for mxfp8 deepseek v3 can be done in <10s. We should verify this time does not change before and after the fix.
We should consider:
- Option 1 (I prefer): Non-colocate mode RL does not have this issue, so only clear cache if sglang offload used by colocate RL is triggered. When sglang weight is restored, flashinfer sees a cache miss and recompute and refresh cache once.
- Option 2: Clear the cache once and recompute the cache only once per weight update cycle, so the cache is still reused within the same cycle.
|
Could you use this test and maybe replace |
Signed-off-by: zhihaow6 <[email protected]>
Signed-off-by: zhihaow6 <[email protected]>
10s is too short for this test, 120s is enough for update weight and could pass the test |
Signed-off-by: zhihaow6 <[email protected]>
|
Verified no extra update overheads: |
Thanks for the benchmark! |
|
/rerun-test test/registered/rl/test_update_weights_from_disk_blackwell.py |
|
Results for 🚀 |
…sgl-project#28676) Signed-off-by: zhihaow6 <[email protected]>
…sgl-project#28676) Signed-off-by: zhihaow6 <[email protected]>
Motivation
DeepSeek-V4 (MXFP8) on the
flashinfer_trtllm_routedMoE path breaks after thefirst RL weight update:
train_rollout_logprob_abs_diffjumps from ~0.06 to~3.83. Steady-state is fine — the bug is specific to the weight-reload path.
Root cause
align_mxfp8_moe_weights_for_flashinfer_trtllmshuffles MoE weights/scales intothe kernel layout using row-permutation index tensors that depend only on shape,
so they're memoized in the GPU cache
_flashinfer_trtllm_shuffle_row_indices_cache_mxfp8(added in #21280).
These cached index tensors are GPU-resident and live in the pauseable weights memory region. On a weight update sglang releases that region's physical memory on pause and reallocates it on resume; since the cache is a plain module global outside the saved/restored static state, its tensors are left pointing at stale memory. We drop it so the indices get recomputed.
The cachestill hits (same shape) but the contents are now garbage, so the post-update
alignpermutes the new weights with stale indices → corrupted layout → the 3.83blowup. Affects any FP8 MoE on the flashinfer-trtllm path that goes through a
weight update, not just V4.
Changes
clear_mxfp8_shuffle_index_cache()inflashinfer_trtllm.pyand call it from the weight-load funnel in
fused_moe_triton/layer.py(
_weight_loader_impl+weight_loader_fused, gated onFp8MoEMethod). Thisfunnel covers both the colocate and distributed/EP update paths, so the next
alignrecomputes correct indices after any reload.apply_routed_scaling_factor_on_outputinhash_topk.py(store the flag, drop thenot implementedassert, applytopk_weights *= routed_scaling_factorinforward), as required by therouted kernel.
Testing
5-step Pinaster/DeepSeek-V4-Flash-FP8-4layer MXFP8 RL run (weight update before each step):
train_rollout_logprob_abs_diffAll steps healthy (~0.06), no 3.83 blowup.
CI States
Latest PR Test (Base): ❌ Run #28472150683
Latest PR Test (Extra): ❌ Run #28472150366