Repository navigation
[AMD] DSv4: bring HIP compress-state pool into the memory_saver KV_CACHE region - #31747
Merged
Merged
Conversation
…CHE region On gfx950 the DSv4 compress-state kv_score_buffer was allocated outside the torch_memory_saver region -- the _is_hip branch used a bare torch.empty(), so pause() could not reclaim it during colocate RL. It stayed resident (~52 GiB on a 16k 4-node run), inflating the train-phase sglang footprint and defeating the point of pausing the KV cache. Unify the HIP path with the CUDA path: allocate kv_score_buffer inside region(GPU_MEMORY_TYPE_KV_CACHE) with the custom mem pool, and drop the HIP carve-out in DeepSeekV4TokenToKVPool that passed enable_memory_saver=False to _init_paged_compress_states.
XinyuJiangCMU
requested review from
Ying1123,
hanming-lu,
hnyls2002,
hzh0425,
ispobock,
merrymercy,
xiezhq-hermann and
yizhang2077
as code owners
July 20, 2026 05:01
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
1am9trash
approved these changes
Jul 20, 2026
HaiShaw
approved these changes
Jul 29, 2026
This was referenced Jul 30, 2026
XinyuJiangCMU
added a commit
to XinyuJiangCMU/sglang
that referenced
this pull request
Aug 1, 2026
Unify the KV-score buffer allocation to always go through memory_saver_adapter + custom_mem_pool, removing the HIP-only branch in both CompressStatePool and the paged compress-state memory pool. Matches upstream sgl-project#31747. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GpJi4wXZerKrVfm8virsnc
XinyuJiangCMU
added a commit
to XinyuJiangCMU/sglang
that referenced
this pull request
Aug 1, 2026
The original commit removed the is_hip import and the _is_hip module global along with the branch it gated. That was safe on the tree it was written against, but this branch is a fresh cherry-pick onto current sglang-miles, where line 132 still reads _is_hip for the ratio == 128 case. Every scheduler died with NameError: name '_is_hip' is not defined before the first step. Upstream main, which took the same change as sgl-project#31747, keeps both the definition and the ratio == 128 use and drops only the pool branch. Match that. py_compile does not catch this; the name is only resolved when the line runs.
saturn-acc
pushed a commit
to saturn-acc/sglang
that referenced
this pull request
Aug 16, 2026
…CHE region (sgl-project#31747) Co-authored-by: Zhiyao Jiang <jessicajiang324@gmail.com>
Atituiset
pushed a commit
to Atituiset/sglang
that referenced
this pull request
Sep 10, 2026
…CHE region (sgl-project#31747) Co-authored-by: Zhiyao Jiang <jessicajiang324@gmail.com>
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.
Co-authored-by: @JessicaJiang-123
On gfx950, the DeepSeek-V4 compress-state pool allocated
kv_score_bufferoutside thetorch_memory_saverregion. As a result,pause()could not reclaim this memory during colocated RL training.For a 16k, 4-node DeepSeek-V4-Flash run, this left approximately 52 GiB per GPU allocated throughout the training phase. This PR moves the HIP allocation into
region(GPU_MEMORY_TYPE_KV_CACHE), matching the existing CUDA behavior.The compute path is unchanged. This PR only changes how the buffer is allocated and registered with
torch_memory_saver.Root cause
_alloc_kv_score_bufferused a separate HIP path that allocated the buffer with a plaintorch.empty(), outside anytorch_memory_saverregion:torch_memory_savercan only unmap physical GPU memory for allocations registered inside aregion. Because the HIP allocation was outside the region, the compress-state pool remained allocated afterpause().In addition,
DeepSeekV4TokenToKVPoolexplicitly passedenable_memory_saver=Falseto_init_paged_compress_stateson HIP, preventing the memory-saver allocation path from being used.Change
Use the same allocation path for HIP and CUDA by allocating
kv_score_bufferinsideregion(GPU_MEMORY_TYPE_KV_CACHE)through the custom memory pool and removing the HIP-specificenable_memory_saver=Falsebehavior inDeepSeekV4TokenToKVPool. Both platforms now use the allocation path previously used only by CUDA.Validation
Hardware: 8× MI355X GPUs (
gfx950)Model: DeepSeek-V4-Flash-FP8
Memory reclaimed
I constructed one ratio-128 compress-state pool with
enable_memory_saver=Trueon gfx950 and measured physical GPU memory withmem_get_infobefore and afterpause().On the current
mainbranch,DeepSeekV4TokenToKVPoolforcesenable_memory_saver=Falseon HIP. With this PR, the flag is enabled and the allocation is registered withtorch_memory_saver.pause()mainWith this PR,
resume()correctly remaps the released memory.Each ratio-128 pool uses approximately 1.87 GiB. Across roughly 20 ratio-128 attention pools, this accounts for the approximately 52 GiB per GPU that previously remained allocated during training.
In the full colocated run, the SGLang GPU-memory footprint during the training phase decreased from approximately 143 GiB to 87 GiB.
Correctness (GSM8K, 1319 questions, 8-shot, TP8)
memory_saver=Falsememory_saver=TruemainAll three accuracy results are at least 0.91. The fix does not change model outputs. With
memory_saver=True, the server starts successfully and serves requests correctly, validating the region and custom-memory-pool allocation path added by this PR.Stability
A 4-node 16k colocate GRPO run on the fixed build: cold start and first
resumewith 0 SIGSEGV, and train/infer logprob drift ~0.04 matching the pre-fix baseline over 40+ steps.Notes
elsebranch).CI States
Latest PR Test (Base): ❌ Run #29718179112
Latest PR Test (Extra): ✅ Run #29723719042