Skip to content

Preserve full DFlash draft KV during PD CPU retraction - #39749

Open
chromecast56 wants to merge 2 commits into
sgl-project:mainfrom
chromecast56:codex/pd-full-draft-retraction
Open

chromecast56 wants to merge 2 commits into
sgl-project:mainfrom
chromecast56:codex/pd-full-draft-retraction

Conversation

@chromecast56

@chromecast56 chromecast56 commented Sep 16, 2026 •

Copy link
Copy Markdown
Collaborator

Related PD/DCP/DFlash PRs: #39743, #40794, #39731, #40164. Each is independent and they can merge in any order.

Motivation

PD CPU retraction (--disaggregation-decode-retraction-backup cpu_tensor) saves the target KV but not the full DFlash draft KV. The draft pool has its own tensors indexed by the target allocator's token ids, so once the retracted request's slots are reused, its draft history is overwritten before it resumes. The target still verifies every drafted token, so outputs stay correct; the resumed request drafts against another request's KV and its acceptance rate drops.

Modifications

  • DFlashWorkerV2.full_draft_kv_pool is the one declaration of a full draft pool: a non-compact MHATokenToKVPool. MLA pools localize token ids to this DCP rank's rows, so their rows are not logical. The worker registers it with BaseTokenToKVPoolAllocator.register_full_draft_kv_pool.
  • CPU retraction saves and restores the registered draft pool with the target state, using logical token ids.
  • The allocator slot defaults at class level, since the SWA and HiSparse allocators don't call the base __init__.
  • Compact draft caches are unchanged. The host_pool backend already carries draft KV as a DRAFT sidecar pool.
  • Scope: EAGLE / MTP draft pools share the target allocator too and lose their draft KV the same way under cpu_tensor (acceptance only). They are not registered here: DeepSeek-style MTP draft pools are MLA, and multi-layer EAGLE has one pool per runner.

Related: #39743

Tests

test_pd_full_draft_cpu_retraction.py (3 CPU tests, 5 subtests):

  • Only a non-compact MHA draft pool registers; compact and MLA pools do not.
  • Poison-and-relocate round trips at DCP1 and DCP8 (rank 3, two fragments) restore target, Mamba and draft KV. Both fail without the fix.
  • An SWA allocator round trip without a draft pool, which guards the class-level default.

GPU check, Kimi K3 PD 1P1D on 8xB300 per role (prefill TP8, decode TP8), DFLASH full draft (block size 8), NIXL, GSM8K 5-shot, prefill DCP8 → decode DCP8 with forced decode retraction (SGLANG_TEST_RETRACT=1, interval 30, about 2,950 retractions) on the same 200 questions: main 98.5% accuracy / average accept length 5.02; a build with all five PD/DCP/DFlash PRs (#39743, #40794, #39731, #39749, #40164) 98.5% / 5.29 (+5%). That matches the draft KV now surviving CPU retraction. One run per build on a 200-question subset.


CI States

Latest PR Test (Base): ⏳ Run #35925582614
Latest PR Test (Extra): ⏳ Run #35925582290
Latest PR Test (AMD ROCm 10): ⏳ Run #35925582583

@chromecast56
chromecast56 force-pushed the codex/pd-full-draft-retraction branch 2 times, most recently from 6a1cd3a to 31bec99 Compare September 23, 2026 00:54
chromecast56 and others added 2 commits September 23, 2026 21:41
Replace the externally assigned cpu_retraction_draft_pool with
DFlashWorkerV2.full_draft_kv_pool, which accepts only a non-compact
MHATokenToKVPool (MLA pools localize token ids to DCP rows), and
BaseTokenToKVPoolAllocator.register_full_draft_kv_pool. Trim the
round-trip matrix to the DCP1 and DCP8 cases that fail without the fix
and use the 3.10-safe enter_scope helper.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@chromecast56
chromecast56 force-pushed the codex/pd-full-draft-retraction branch from 31bec99 to 9d448cc Compare September 23, 2026 21:57
@kpham-sgl kpham-sgl self-assigned this Sep 23, 2026

class BaseTokenToKVPoolAllocator(abc.ABC):
# Class-level: SWA and HiSparse allocators do not call this __init__.
full_draft_kv_pool: KVCache | None = None

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we pass the existing draft pool explicitly into Req.offload_kv_cache() / load_kv_cache() instead of registering it on the allocator? Add a keyword-only draft_kv_pool=None argument and use it directly:

# offload_kv_cache: RetractionBackup field
draft_cpu=(
    draft_kv_pool.get_cpu_copy(
        token_indices, req_pool_index=self.kv.req_pool_idx
    )
    if draft_kv_pool is not None
    else None
),
# load_kv_cache
draft_cpu = self.kv.retraction_backup.draft_cpu
if draft_cpu is not None:
    assert draft_kv_pool is not None
    draft_kv_pool.load_cpu_copy(
        draft_cpu, token_indices, req_pool_index=self.kv.req_pool_idx
    )

Thread the eligible existing draft-pool reference through both call paths from the scheduler. This keeps draft_cpu and removes the allocator registration and new DFlash property.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation memory-pool

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants