[None][fix] kv_cache_v2: fix SWA scratch on deferred-context revert under ADP balance#14934
Closed
qiaoxj07 wants to merge 1 commit into
Closed
[None][fix] kv_cache_v2: fix SWA scratch on deferred-context revert under ADP balance#14934qiaoxj07 wants to merge 1 commit into
qiaoxj07 wants to merge 1 commit into
Conversation
…nder ADP balance revert_allocate_context() undoes resize_context()'s capacity grow when attention-DP balance (or batch waiting) defers a context request after V2 scheduling. For sliding-window-attention layers this collided with SWA scratch reuse in two ways: - a fresh deferred context (history_length == 0) tripped resize()'s scratch invariant (history_length >= old_capacity - max_rewind_len), which only holds for a generation-time window slide; - a context whose prefill grew past the sliding window holds scratch slots, and resize() refuses to shrink while scratch slots are live. Fix: - _KVCache.resize() gains a keyword-only allow_swa_scratch_reuse (default True); revert passes False to perform a scratch-free capacity shrink. - revert_allocate_context() suspend()s caches that hold scratch slots, freeing scratch slots and releasing pages back to the pool; the request is resumed via prepare_context()/_resume_and_restore() on reschedule, the same machinery generation and the pre_cap>0 revert already use. adp_balance stays fully functional and pages are still freed during the defer window (no KV-cache capacity regression). Validated on DSv4-Pro DEP8 + adp_balance (timeout_iters=100, batching_wait_iters=20) + SWA + mtp0 + nvfp4: the full benchmark now completes (Total Token Throughput ~13.6k tok/s) where the unpatched build crashed during warmup with "SWA scratch requires ...". Signed-off-by: Xianjie <5410381+qiaoxj07@users.noreply.github.com>
Collaborator
|
This issue is fixed in #14849. I suggest you to use that PR. |
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
revert_allocate_context()undoes the per-iterationresize_context()capacity grow when attention-DP balance (attention_dp_config.enable_balance) or batch-waiting defers a context request after V2 scheduling. On sliding-window-attention (SWA) layers this collided with SWA scratch reuse and crashed DeepSeek-V4 DEP8 runs onceadp_balancewas enabled.Two failure modes:
history_length == 0) trippedresize()'s SWA-scratch invarianthistory_length >= old_capacity - max_rewind_len(which only holds for a generation-time window slide) — e.g.AssertionError: SWA scratch requires old_capacity - max_rewind_len (965) <= history_length (0) <= old_capacity (965).resize()refuses to shrink while scratch slots are live.Fix
_KVCache.resize()gains a keyword-onlyallow_swa_scratch_reuse(defaultTrue). The revert path passesFalseto perform a scratch-free capacity shrink, leaving the generation-time window-slide path untouched.revert_allocate_context()suspend()s caches that hold scratch slots — freeing the scratch slots and releasing pages back to the pool — and resumes them viaprepare_context()/_resume_and_restore()on the next schedule (the same machinery generation and the existingpre_cap > 0revert already use).adp_balancestays fully functional and deferred pages are still freed during the wait window (no KV-cache capacity regression).Test
DSv4 DEP8 (TP8/EP8, attention-DP),
adp_balance(timeout_iters=100,batching_wait_iters=20), SWA, MTP0, NVFP4, bs128 / conc256 on GB200:SWA scratch requires ....🤖 Generated with Claude Code