Repository navigation
[sglang-miles] Colocate RL: flush hybrid state pools before releasing KV cache - #40815
Closed
Zhichenzzz wants to merge 2 commits into
Closed
Zhichenzzz wants to merge 2 commits into
Zhichenzzz wants to merge 2 commits into
Conversation
… KV cache release_memory_occupation paused (unmapped) the KV cache region and only then called flush_cache(). For hybrid models the pools cleared there live inside that region and clear() writes device memory: req_generation, mamba states, and qwen4_exp's PLE short-conv / n-gram states (ShortConvPool.conv_state.zero_(), NgramPool.context.fill_()). The write hit unmapped memory and raised a sticky CUDA error 700 at the next sync. Plain-KV models never noticed because their clear() is host-side only. - release_memory_occupation: flush before pausing the KV region. - Scheduler.flush_cache: skip while the KV region is released. The trainer side sends /flush_cache again while the engine is offloaded; the pools were already flushed right before the pause, so there is nothing left to clear.
Zhichenzzz
requested review from
Ying1123,
hnyls2002,
merrymercy and
xiezhq-hermann
as code owners
September 23, 2026 01:46
This was referenced Sep 23, 2026
Collaborator
Author
|
Folded into #40821, which carries this fix as its first commit. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
In colocated RL,
release_memory_occupationpaused (unmapped) the KV cache memory-saver region and only then calledflush_cache(). For hybrid models, the pools cleared byflush_cache()live inside that region, and theirclear()writes device memory:req_generation, mamba statesShortConvPool.conv_state.zero_(),NgramPool.context.fill_()The write hits unmapped memory and raises a sticky CUDA error 700 (illegal memory access). It surfaces at whatever synchronizes next, so the reported stack names an unrelated op. Plain-KV models never hit this because their
clear()is host-side only.With
CUDA_LAUNCH_BLOCKING=1the fault lands exactly onple_state_pool.pyShortConvPool.clear(), called fromrelease_memory_occupation -> flush_cache -> HybridReqToTokenPool.clear.Modifications
release_memory_occupation: flush before pausing the KV region.Scheduler.flush_cache: skip while the KV region is released. The trainer sends/flush_cacheagain while the engine is offloaded; the pools were already flushed right before the pause, so there is nothing left to clear. Returns success so callers treat the cache as clean.Fixing only (1) is not enough: the second
/flush_cachearriving mid-pause faults the same way.Accuracy / validation
Full-model colocated RL e2e with miles PR radixark/miles#2777 (Qwen3.8-Flash-Next, 8 nodes x 4 GB300, TP2 PP8 EP4 trainer, four TP8 rollout engines, CUDA graph on,
--colocate, R3 routing replay,--check-weight-update-equal):train_rollout_logprob_abs_diff0.0082 to 0.0129, raw reward 0.47 to 0.75.CI States
Latest PR Test (Base): ❌ Run #35818880571
Latest PR Test (Extra): ❌ Run #35818880333
Latest PR Test (AMD ROCm 10): ❌ Run #35818880525