Repository navigation
[Refactor] disaggregation: Track unified PD transfers per row and reuse their pages only once quiescent - #48009
Merged
Merged
Conversation
ch-wan
force-pushed
the
cheng/refactor/unified-kv-window-rails
branch
from
November 4, 2026 06:18
0e9aae3 to
8df6f60
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 4, 2026 06:18
5134760 to
7b372ac
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-window-rails
branch
from
November 4, 2026 07:42
8df6f60 to
4af2ce8
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 4, 2026 07:42
7b372ac to
64a142d
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-window-rails
branch
from
November 4, 2026 08:02
4af2ce8 to
7e1cf2d
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 4, 2026 08:02
64a142d to
8650182
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-window-rails
branch
from
November 4, 2026 09:14
7e1cf2d to
11c2779
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 4, 2026 09:14
8650182 to
b620c98
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-window-rails
branch
from
November 4, 2026 09:31
11c2779 to
8262d14
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 4, 2026 09:31
b620c98 to
93db0fd
Compare
This was referenced Nov 4, 2026
Merged
Merged
Merged
Merged
ch-wan
force-pushed
the
cheng/refactor/unified-kv-window-rails
branch
from
November 5, 2026 11:24
a94e5d7 to
e6dadd0
Compare
ch-wan
requested review from
Fridge003,
Jialin,
Qiaolin-Yu,
hebiao064 and
yuan-luo
as code owners
November 5, 2026 11:24
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 5, 2026 11:24
9efeaa4 to
ea0a16c
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-window-rails
branch
from
November 5, 2026 22:15
e6dadd0 to
0b14d62
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 5, 2026 22:15
ea0a16c to
35d4c63
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-window-rails
branch
from
November 6, 2026 00:00
0b14d62 to
c86cf82
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 6, 2026 00:00
35d4c63 to
0185108
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-window-rails
branch
from
November 6, 2026 01:16
c86cf82 to
9277df7
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 6, 2026 01:16
0185108 to
ed6c74d
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-window-rails
branch
from
November 6, 2026 03:37
9277df7 to
72f4463
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 6, 2026 03:37
ed6c74d to
965972b
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-window-rails
branch
from
November 6, 2026 06:33
72f4463 to
dd8bc46
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 6, 2026 06:34
965972b to
cc62158
Compare
This comment has been minimized.
This comment has been minimized.
4 of 5 tasks
ch-wan
force-pushed
the
cheng/refactor/unified-kv-window-rails
branch
from
November 6, 2026 10:43
dd8bc46 to
8e4c606
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 6, 2026 10:43
cc62158 to
2c9b8ec
Compare
This comment has been minimized.
This comment has been minimized.
ch-wan
force-pushed
the
cheng/refactor/unified-kv-window-rails
branch
from
November 6, 2026 12:31
8e4c606 to
6b06dfb
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 6, 2026 12:31
2c9b8ec to
66fc9a0
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-window-rails
branch
from
November 6, 2026 13:40
6b06dfb to
5b1b6fa
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 6, 2026 13:40
66fc9a0 to
5f68220
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-window-rails
branch
from
November 6, 2026 21:21
5b1b6fa to
22dc693
Compare
ch-wan
force-pushed
the
cheng/refactor/unified-kv-page-ledger
branch
from
November 6, 2026 21:21
5f68220 to
9d0d417
Compare
…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.
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.
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
kv/alloc/signals.py,kv/alloc/page_usage.py,kv/alloc/band.py):NetworkTransferis one send or receive, released where its owner observes its end on every rank;ReceiveHoldholds 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).PageUsage.transfer_ended), so every rank makes the same ones.Band.network_waiter,ChainAllocator.set_network_waiter); with no waiter installed, a move that must wait raises instead of waiting on the GPU.record_transfer(release=, unit_tokens=)), which stay right whatever moves later.add_pin_source,pinned_by_source) are removed;moves_blockedis 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.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):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.arg_groups/kv_cache_hook.py):SGLANG_DISAGG_STAGING_BUFFER=1with--enable-unified-memoryand 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.rid(KVStorage._lifetime): a retry may reuse aridwhile 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_transferandrelease_rowall key by it.KVStorage.move_epoch, and the publish then orders its readback after the schedule stream, or re-reads the held send's ids.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_quiescentthrough_receive_done, at a deadline or on an immediate release) and the send side (prefill._send_donetreats a failed or cleared room as done while the engine may still read it).disagg_transfers_in_flightand 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.movesandDecodeKVCacheOffloadManager.has_inflight_device_transfer.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;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.pyreplaces 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), andTestTransfersBelongToTheRequestNotItsRid: two requests with oneridand 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.pydrives 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;hold_every_band).Behaviour changes
--enable-unified-memoryon a PD node, pages compact and move while PD transfers are in flight; before, the whole pool stayed in place.--enable-unified-memorywith PD disaggregation andSGLANG_DISAGG_STAGING_BUFFER=1now fails at startup ("heterogeneous-TP staging is not supported with unified memory; unset SGLANG_DISAGG_STAGING_BUFFER."). Before, it started, and withSGLANG_ENABLE_NV_MEGA_RUNTIME_OPTIMIZATION=1its decode side read destinations back without blocking.SGLANG_DISAGGREGATION_DEFERRED_DECODE_KV_RELEASE_TIMEOUT, 30 s by default).--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
maina4b8801197: 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 againstmain, all reported in #48014.Checklist
pre-commiton the changed files.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-testto run the tests your change touches, or copy this prompt for an agent: