Repository navigation
Conversation
Decode-side HiCache offload copies KV to host asynchronously. Retraction could return those device pages to the allocator while a copy still read them: pause/retract runs before the decode loop's offload drain, and so does memory-pressure retraction in the PP loop. A retract pause also left the offload acks pending, so the paused engine never became idle for flush_cache. Run the offload manager's existing check_offload_progress() before retract_all() in pause_generation and before retract_decode() in update_running_batch, and add a regression case for each entrypoint. Based on sgl-project#30899 by Kevin Flansburg.
Jiminator
requested review from
Ying1123,
hnyls2002,
merrymercy and
xiezhq-hermann
as code owners
September 23, 2026 22:39
5 tasks done
Jiminator
added a commit
to kflansburg/sglang
that referenced
this pull request
Sep 24, 2026
Bring this branch to the implementation that was reviewed and tested separately in sgl-project#40982. The resulting tree is exactly that tested commit's tree: the offload manager's check_offload_progress() now runs before retract_all() in pause_generation and before retract_decode() in update_running_batch, with a regression case for each entrypoint. The earlier callback-based changes on this branch are superseded by that tree. Their commits stay in the history; nothing is rewritten. Original fix and PR by Kevin Flansburg.
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.
Consolidated into #30899, the original PR by Kevin Flansburg (@kflansburg), to keep the implementation, validation and credit together. The reviewed source tree and Kevin-authored fix commit are preserved there.
Motivation
Decode-side HiCache offload copies KV to host asynchronously. Retraction can return those device pages to the allocator before the copy finishes, allowing an independent writer to overwrite data the old offload still reads. A retract pause can also leave offload bookkeeping pending and prevent cache flush while paused.
Based on @kflansburg's #30899, adapted to current main.
Modifications
Reuse
check_offload_progress()beforeretract_all()in pause/retract and beforeretract_decode()in the memory-pressure branch. Add two deterministic regression cases that observe copy completion when KV is freed.Normal and overlap decode already drain before memory-pressure retraction. The PP loop selects the next batch before its drain, and abort paths release with
offload_kv=False, without the synchronizing CPU backup. The second call protects that ordering. These are the current decode retraction entrypoints; future decode release paths must preserve it too. The ordinary asynchronous offload path is unchanged.Accuracy Tests
Validated on main
2909f84ewith H200, Torch 2.13.0+cu130 and sglang-kernel 0.4.7:c1899de2), TP1 prefill/decode: paired pause, delayed pause, resume, flush and abort checks pass with exact output-token equality. Each variant also completes four concurrent requests through 85 forced retractions, matching the uninterrupted reference. Delayed paused flush changes from HTTP 400 on base to HTTP 200 on the candidate.The CUDA control uses an independent writer stream to model forward/RDMA reuse; no corruption from natural PD traffic is claimed. PP decode was not run end to end; its ordering is covered by the memory-pressure entrypoint control and source inspection. Full TP2 serving did not fit the available container host-memory budget. Its coverage is the standalone two-rank control above, not a trained TP2 serving run.
Speed Tests and Profiling
Three alternating launches per variant, telemetry off, 16 requests at concurrency 4, 210 input / 256 output tokens. Each launch has one warmup repeat and two measured repeats. Qwen3-0.6B BF16, overlap on, Triton attention, CUDA graphs disabled, 4096 device KV tokens, decode HiCache ratio 1 and file storage; prefill uses its ordinary cache.
All requests completed and no benchmark retracted. The ranges overlap; this is a regression check for this workload, not a speedup claim. Injected-delay timings are excluded from performance results.
Checklist
CI States
Latest PR Test (Base): ❌ Run #35929520979
Latest PR Test (Extra): ❌ Run #35929520712
Latest PR Test (AMD ROCm 10): ❌ Run #35929521042