Skip to content

[Refactor] disaggregation: Track unified PD transfers per row and reuse their pages only once quiescent - #48009

Merged
ch-wan merged 1 commit into
mainfrom
cheng/refactor/unified-kv-page-ledger
Nov 9, 2026
Merged

ch-wan merged 1 commit into
mainfrom
cheng/refactor/unified-kv-page-ledger

Conversation

@ch-wan

@ch-wan ch-wan commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

This PR is part of a stack (oldest at bottom):

Motivation

Under --enable-unified-memory, a PD node kept every band of the shared KV arena in place while any PD transfer might be in flight: the scheduler registered one pin source over every sub-pool (disagg_transfers_in_flight), true while a prefill send was queued or still sending a chunk, or while a decode destination was published, receiving or offloading. Under steady PD load the pool therefore never compacted and floats never moved, and the predicate had to be read again on every capacity query, since its answer changes with no write to the pool.

A PD transfer addresses device rows by physical id from the moment the ids are translated for a send, or published to the peer for a receive, until its engine is done with them. That is a per-row hazard like a forward's or a host copy's, which the per-band page ledger already orders. This PR records each send and each receive on the rows it reads or writes, so pages move like any page unfinished work touches, and their bytes are reused only once the transfer is quiescent on every rank.

Modifications

  • Network transfers in the ledger (kv/alloc/signals.py, kv/alloc/page_usage.py, kv/alloc/band.py):
    • NetworkTransfer is one send or receive, released where its owner observes its end on every rank; ReceiveHold holds receive rows whose destination is not published yet; it copies its rows once for every band it is recorded in. A NumPy page-id array is kept as an owned array copy (PageUsage._owned).
    • A copy of a row a transfer writes waits for the transfer; a row it reads may move at once, and the bytes it vacates are reused only after the transfer's release. Decisions read releases only (PageUsage.transfer_ended), so every rank makes the same ones.
    • A network engine runs outside every CUDA stream, so these waits happen on the host, through the storage's network waiter (Band.network_waiter, ChainAllocator.set_network_waiter); with no waiter installed, a move that must wait raises instead of waiting on the GPU.
    • Transfers are recorded by the physical rows the engine was handed (record_transfer(release=, unit_tokens=)), which stay right whatever moves later.
    • An opportunistic compaction leaves a page a transfer still writes, and a band holding receive rows; a move an allocation needs proceeds after the host wait.
    • The band-wide pin sources (add_pin_source, pinned_by_source) are removed; moves_blocked is whether a page is fixed, and the capacity snapshot key no longer reads a predicate.
  • NetworkTransferWaiter (disaggregation/utils.py): waits on the host until every rank's engine is done with the transfers a move waits for. Each round, a rank contributes one flag, whether all of its listed transfers are done, and the flags are MIN-reduced over the attention TP group, on prefill (prefill._send_waiter) as on decode, so the collective has the same length on every rank of the group and every rank returns in the same round. Attention TP ranks record the same transfers on the same pages and so enter a wait together; attention CP ranks hold different shards and ledgers, so the wait never spans them (test_the_send_waiter_spans_the_attention_tp_ranks_only). The transfers a wait lists are deduplicated (signals.unreleased_transfers): one transfer can sit in several fences, and how many differs across ranks, since host copies end at different times per rank. It sleeps between rounds with the GIL released (the transfer threads report through Python), and logs a waiting move every 10 s with this rank's count still running. The transfer protocol's deadlines end every transfer (a receive's waiting timeout, then its failed-transfer acknowledgements or deferred-release deadline), and a transfer worker that raises marks its room failed, which ends the wait too. Each round feeds the scheduler watchdog (Scheduler.feed_watchdog), so a long legitimate wait does not trip it; past its own deadline (SGLANG_DISAGGREGATION_PAGE_MOVE_WAIT_TIMEOUT, by default beyond the bootstrap, waiting and deferred-release timeouts together), decided in the same reduced round on every rank, every rank raises naming the stuck rooms and feeds the watchdog no more.
  • PD sends and receives (disaggregation/prefill.py, decode.py, common/conn.py, common/utils.py, mooncake/conn.py, kv/storage.py, static_kv_storage.py, mem_cache/common.py):
    • Prefill records each segment's send on the KV pages and state rows it reads. The ledger takes the device pages of the send's host-index copy, so a send segment's page indices are computed once. A send is done when the transfer worker finished it: each room's sends are counted in one per-room record (CommonKVManager.send_record), created at the first queued send and dropped when the sender is cleared or the room starts a new lifecycle. A worker report for a cleared room, or one from the room's previous lifecycle, finds no record and counts nothing. A sender's abort retires the room's record too (CommonKVSender._retire_sends), so the abort paths that release a request without clearing its sender leave no record behind; the deferred abort acknowledgement keeps its own count.
    • Decode records each receive when its destination is sent, and ends it when the request's KV is committed, or when its row is released.
    • Unified memory refuses staging buffers at startup (arg_groups/kv_cache_hook.py): SGLANG_DISAGG_STAGING_BUFFER=1 with --enable-unified-memory and PD disaggregation fails with "heterogeneous-TP staging is not supported with unified memory". The flag also selects the decode side's non-blocking metadata readback, for matching TP sizes too, which recorded a receive as an active transfer before its destination was published; a move waiting on that receive could never end. Without the flag, every unified receive whose publish is postponed is held until its destination is sent.
    • A request's transfers and receive hold are kept by the request object, never by its rid (KVStorage._lifetime): a retry may reuse a rid while the earlier request's rows are still in deferred release, and ending one request ends only its own transfers and hold. record_network_transfer, hold_receive_rows, end_receive_hold, end_network_transfer and release_row all key by it.
    • A decode destination published later (the deferred publish, or under overlap a send held until the forward in flight is done) holds its receive rows until it is sent. No peer has their ids yet, so a move of them waits for nothing; such a move bumps KVStorage.move_epoch, and the publish then orders its readback after the schedule stream, or re-reads the held send's ids.
    • A request whose row a streaming session keeps ends its transfers when it is released.
    • The static storage answers every new call as a no-op.
  • Quiescence of a failed receive (disaggregation/decode.py): a move that cannot avoid a failed receive's rows waits by the deferred release's rule. Once the request is held for release, the hold's acknowledgement count and deadline apply. Before the hold, a destination that was sent is owed an acknowledgement by every bootstrap peer, whether or not the abort was notified yet, so the abort is notified there; the deadline starts at that first sight, and the hold keeps it (one timeout clock). A destination never sent is done at once, and so is every failed receive without deferred release. FIXME comments mark the places that do not prove the remote side stopped: the receive side (_failed_receive_quiescent through _receive_done, at a deadline or on an immediate release) and the send side (prefill._send_done treats a failed or cleared room as done while the engine may still read it).
  • disagg_transfers_in_flight and the scheduler's pin registration are removed, with what only the band-wide pin read: the prefill's pending-chunk set (disagg_prefill_pending_chunk_rids, clear_pending_chunk_send), Band.moves and DecodeKVCacheOffloadManager.has_inflight_device_transfer.
  • Tests:
    • new test/registered/unit/disaggregation/test_unified_transfer_bookkeeping.py: send completion and the per-room record (a send finished after its room was cleared, a late report after the room started anew), the waiter (GIL released, every rank returns in the same round, one flag per rank however it lists the transfers, a receive finishing after 180 s within a 300 s timeout, a watchdog heartbeat every round), two ranks whose backups end at different times waiting on one network transfer after a compaction (TestRankSkewedWaitAfterCompaction), receive completion (a sent failure waits for every acknowledgement, one deadline, never-sent and no-deferred-release failures done at once), and a recurrent state's one-slot entry;
    • new test_pd_receive_lifecycle.py (a static pool takes both queues' waiters; staggered timeouts agree across ranks; unified memory refuses staging buffers for prefill and decode, and starts without them); test_unified_page_writability.py::TestFencesSplitByReaders;
    • test_unified_memory_move_gate.py replaces the pin-source tests with network-transfer cases (pricing unchanged, a read row moves and its old row waits, only a needed move takes a written row, releasing the row ends the transfer), and TestTransfersBelongToTheRequestNotItsRid: two requests with one rid and different rooms, either one ending first, keep the other's receive (a compaction leaves its page, a forced move still waits for it on the host) and the new one's unpublished hold;
    • test_unified_transfer_ordering.py (CUDA): a float move waits on the host for a receive that writes a moved page, and a move without a waiter refuses;
    • test_unified_page_writability.py drives the network hazard through the ledger, and a cancelled reservation fences the copy on it;
    • test_decode_queue_cleanup.py: deferred and held publishes hold their rows and re-read them after a move;
    • managers/test_scheduler_chunked_abort_race.py::TestPrefillAbortRetiresSendRecord: an aborted pending chunk and an aborted prefill result retire the room's send record, with a real sender and manager, while a deferred acknowledgement stays owed;
    • tests that pinned a band hold its live pages instead (hold_every_band).

Behaviour changes

  • Under --enable-unified-memory on a PD node, pages compact and move while PD transfers are in flight; before, the whole pool stayed in place.
  • Startup refusal: --enable-unified-memory with PD disaggregation and SGLANG_DISAGG_STAGING_BUFFER=1 now fails at startup ("heterogeneous-TP staging is not supported with unified memory; unset SGLANG_DISAGG_STAGING_BUFFER."). Before, it started, and with SGLANG_ENABLE_NV_MEGA_RUNTIME_OPTIMIZATION=1 its decode side read destinations back without blocking.
  • A move that cannot avoid the rows of a receive that was sent and then failed waits on the host for every prefill peer's abort acknowledgement, or for the deferred release timeout (SGLANG_DISAGGREGATION_DEFERRED_DECODE_KV_RELEASE_TIMEOUT, 30 s by default).
  • Mooncake send counting runs for every pool; a cleared room keeps no record (this also applies with unified memory off).
  • No other change without --enable-unified-memory: the static storage records nothing, and deferred release and queue cleanup are unchanged.

Accuracy Tests

This stack is validated at its top, on main a4b8801197: the affected unit tests at the default and strict invariant levels, the CPU unit suite, the page-safety stress run and sweep, and serving accuracy and speed against main, all reported in #48014.

Checklist

  • Format with pre-commit on the changed files.
  • Unit tests added and updated.

CI States

Latest PR Test (Base): ⏳ Run #42606595339
Latest PR Test (Extra): ⏳ Run #42606595374
Latest PR Test (AMD ROCm 10): ⏳ Run #42606595462

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@github-actions github-actions Bot added hicache Hierarchical Caching for SGLang unified-radix-cache labels Nov 3, 2026
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-window-rails branch from 0e9aae3 to 8df6f60 Compare November 4, 2026 06:18
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-page-ledger branch from 5134760 to 7b372ac Compare November 4, 2026 06:18
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-window-rails branch from 8df6f60 to 4af2ce8 Compare November 4, 2026 07:42
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-page-ledger branch from 7b372ac to 64a142d Compare November 4, 2026 07:42
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-window-rails branch from 4af2ce8 to 7e1cf2d Compare November 4, 2026 08:02
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-page-ledger branch from 64a142d to 8650182 Compare November 4, 2026 08:02
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-window-rails branch from 7e1cf2d to 11c2779 Compare November 4, 2026 09:14
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-page-ledger branch from 8650182 to b620c98 Compare November 4, 2026 09:14
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-window-rails branch from 11c2779 to 8262d14 Compare November 4, 2026 09:31
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-page-ledger branch from b620c98 to 93db0fd Compare November 4, 2026 09:31
This was referenced Nov 4, 2026
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-window-rails branch from a94e5d7 to e6dadd0 Compare November 5, 2026 11:24
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-page-ledger branch from 9efeaa4 to ea0a16c Compare November 5, 2026 11:24
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-window-rails branch from e6dadd0 to 0b14d62 Compare November 5, 2026 22:15
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-page-ledger branch from ea0a16c to 35d4c63 Compare November 5, 2026 22:15
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-window-rails branch from 0b14d62 to c86cf82 Compare November 6, 2026 00:00
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-page-ledger branch from 35d4c63 to 0185108 Compare November 6, 2026 00:00
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-window-rails branch from c86cf82 to 9277df7 Compare November 6, 2026 01:16
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-page-ledger branch from 0185108 to ed6c74d Compare November 6, 2026 01:16
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-window-rails branch from 9277df7 to 72f4463 Compare November 6, 2026 03:37
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-page-ledger branch from ed6c74d to 965972b Compare November 6, 2026 03:37
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-window-rails branch from 72f4463 to dd8bc46 Compare November 6, 2026 06:33
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-page-ledger branch from 965972b to cc62158 Compare November 6, 2026 06:34
@github-actions

This comment has been minimized.

@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-window-rails branch from dd8bc46 to 8e4c606 Compare November 6, 2026 10:43
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-page-ledger branch from cc62158 to 2c9b8ec Compare November 6, 2026 10:43
@github-actions

This comment has been minimized.

@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-window-rails branch from 8e4c606 to 6b06dfb Compare November 6, 2026 12:31
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-page-ledger branch from 2c9b8ec to 66fc9a0 Compare November 6, 2026 12:31
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-window-rails branch from 6b06dfb to 5b1b6fa Compare November 6, 2026 13:40
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-page-ledger branch from 66fc9a0 to 5f68220 Compare November 6, 2026 13:40
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-window-rails branch from 5b1b6fa to 22dc693 Compare November 6, 2026 21:21
@ch-wan
ch-wan force-pushed the cheng/refactor/unified-kv-page-ledger branch from 5f68220 to 9d0d417 Compare November 6, 2026 21:21
…se their pages only once quiescent

Under unified memory a PD node kept every band of the pool in place while
any transfer might be in flight, through one pin source over every
sub-pool, so under steady PD load nothing compacted or moved, and every
capacity query re-read the predicate.

Each send and each receive is now its own network transfer, recorded on
the physical rows it reads or writes in the per-band page ledger. A copy
of a row a transfer writes waits for it; a row it reads may move, and the
bytes it vacates are reused only after its release. The engine runs
outside every CUDA stream, so these waits happen on the host, through a
waiter that MIN-reduces each rank's answer, so every rank returns in the
same round, and sleeps with the GIL released. Decisions read releases
only, alike on every rank.

A send is done when Mooncake's transfer worker finished it; each room's
sends are counted in one record that a cleared or restarted room drops,
so a late report counts nothing. A segment's page indices are computed
once for the send and the ledger. A receive ends when its KV is
committed or its row released. A failed receive is quiescent by the
deferred release's rule: a destination sent to the peers is owed every
bootstrap peer's acknowledgement whether or not the abort was notified,
within one deadline the release hold keeps. Destinations published later
hold their rows until sent; a move meanwhile makes the publish read the
ids again.

The pin sources, disagg_transfers_in_flight and the scheduler's pin
registration are removed. Static pools record nothing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hicache Hierarchical Caching for SGLang mooncake unified-radix-cache

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant