Repository navigation
[Fix] Allocate SWA KV pools inside the memory-saver region - #40979
Merged
Merged
Conversation
guapisolo
requested review from
Ying1123,
alphabetc1,
hanming-lu,
hnyls2002,
huangtingwei9988,
hzh0425,
ispobock,
merrymercy,
xiezhq-hermann and
yizhang2077
as code owners
September 23, 2026 22:34
Collaborator
Author
|
/tag-and-rerun-ci |
Collaborator
Author
|
/rerun-test test_dsa_pool_host_unit.py test_dsa_layer_split_broadcast.py test_swa_unittest.py registered/attention/unittests/dsa/test_dsa.py test_swa_pool_v_head_dim.py |
Contributor
|
Results for 🚀 🚀 🚀 🚀 |
Collaborator
Author
|
/tag-and-rerun-ci |
guapisolo
force-pushed
the
jiajun/swa-kv-pool-memory-saver
branch
from
September 24, 2026 19:59
29bc585 to
8d6a9ee
Compare
SWAKVPool hard-coded enable_memory_saver=False for its full and SWA sub-pools and the MHA sliding-window configurator never passed the flag, so for SWA models the KV cache was allocated outside torch_memory_saver's region and release_memory_occupation(kv_cache) was a no-op. Measured on an H200 TP2 engine of a hybrid SWA model: 85.3 GiB after load, 32.9 GiB after release(all), 85.3 GiB after resume(weights), i.e. only the weights were pausable and a colocated Miles trainer had no memory left for its own init. Thread the flag through SWAKVPool and pass the server setting from the configurator, like every other KV pool class does. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
…he memory-saver region The hybrid MLA SWA builder passes explicit sub-pool kwargs to SWAKVPool with enable_memory_saver hard-coded to False, so neither MLA/DSA sub-pool was allocated inside the torch_memory_saver region and release_memory_occupation(kv_cache) left their KV cache resident. Pass the server setting there, as the MHA SWA builder now does. IndexKeyCache allocated the DSA index-K buffers outside memory_saver_adapter.region(), so every DSA pool, hybrid or not, kept its index-K resident after a release even with the flag on. Allocate them inside the KV_CACHE region, like the MLA buffers of the same pool. Measured by pausing the kv_cache tag on pools built through the configurator builders on one H200 (48 layers, 12 full / 36 SWA): hybrid MLA freed 0 -> 6.0 GiB of 5.9 GiB; hybrid DSA freed 0 -> 6.4 GiB of 6.3 GiB, 0.39 GiB of which is index-K. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
guapisolo
force-pushed
the
jiajun/swa-kv-pool-memory-saver
branch
from
September 24, 2026 22:08
8d6a9ee to
34ba83f
Compare
ch-wan
approved these changes
Sep 25, 2026
The comment restated why the change was made and claimed an unconditional invariant that the parameter's False default does not enforce; the PR body carries that rationale. No behavior change. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
Author
|
cc cmt CI record for this PR:
The current head c7db69c only removes a code comment on top of 34ba83f; its CI run stopped at the maintenance-mode rebase check and ran no tests. |
This was referenced Sep 30, 2026
ziang-and
pushed a commit
to zianglih/sglang
that referenced
this pull request
Oct 2, 2026
… graph registration (sgl-project#40648, sgl-project#40978, sgl-project#40979, sgl-project#40980, sgl-project#40977, sgl-project#41972) Retain colocated training fixes above the release MiMo implementation, including address-stable Marlin reload and mandatory TopK layer IDs. Disable NCCL graph registration for TP LM-head all-to-all and pausable graph pools. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.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.
Summary
release_memory_occupationnow frees the KV cache of MHA, MLA and DSA sliding-window models.Symptom & Reproduction
--enable-memory-saver, releasingkv_cacheleaves the KV cache of SWA models resident, and every DSA model keeps its index-K buffers.KVCacheConfiguratorbuilder with the flag on, pause the torch_memory_saverkv_cachetag, and readtorch.cuda.mem_get_info; expected: the pool's bytes are freed; observed on the merge base: 0 GiB freed for all three SWA pool kinds.Root Cause
pause(GPU_MEMORY_TYPE_KV_CACHE)unmaps only buffers allocated inside a memory-saver region._build_hybrid_swa_kv_poolnever passes the flag, soSWAKVPoolgives both sub-poolsFalse._build_hybrid_mla_swa_kv_poolhard-codesFalsein the explicit sub-pool kwargs it handsSWAKVPool.IndexKeyCache.__init__allocates index-K outsidememory_saver_adapter.region, in every DSA pool.Fix
Each pool builder now passes
get_exec().features.enable_memory_saver, as every other pool builder already does. The MHA builder uses a newSWAKVPoolargument that is forwarded to both sub-pools and defaults toFalse. The hybrid MLA/DSA builder sets the flag in its explicitcommonkwargs, because explicit sub-pool kwargs bypass that argument.IndexKeyCacheallocates index-K inside theGPU_MEMORY_TYPE_KV_CACHEregion, like the MLA buffers of the same pool. With the flag off the adapter is a no-op, so allocation is unchanged. Unchanged: the NPU SWA path,LayerSplitIndexKeyCache.remote_bufferand the DSA compress-tail buffers.Verification
pre-commit run --fileson the three changed files at this head: passed.29bc585196, whose three-file diff equals this head's except one deleted comment:data_ptr, read back zero, and accepted writes.34ba83fa52(this head minus the comment-only commit):PR Test Basepassed;/rerun-testof the SWA and DSA pool unit tests passed at29bc585196.Review Focus
index_key_cache.py: index-K now joins thekv_cachetag for every DSA model; resume zero-fills it, andflush_cache()runs right after the pause, so stale index-K is never read._build_hybrid_mla_swa_kv_pool: its explicit sub-pool kwargs bypass theSWAKVPoolargument, so the flag must stay incommon.🤖 Generated with Claude Code
CI States
Latest PR Test (Base): ❌ Run #36200923877
Latest PR Test (Extra): ❌ Run #36200923762
Latest PR Test (AMD ROCm 10): ❌ Run #36200923733