Repository navigation
Disaggregated Inference: End2End - #6675
Merged
wdykas merged 82 commits intoOct 16, 2026
Merged
Conversation
Signed-off-by: William Dykas <wdykas@nvidia.com>
Signed-off-by: William Dykas <wdykas@nvidia.com>
Signed-off-by: William Dykas <wdykas@nvidia.com>
Signed-off-by: William Dykas <wdykas@nvidia.com>
Signed-off-by: William Dykas <wdykas@nvidia.com>
…agg-e2e-main-restack-20260819
Signed-off-by: William Dykas <wdykas@nvidia.com>
Contributor
Author
|
/claude strict-review |
Contributor
Author
|
@nvcsathe I am going to try to get it all cleaned up in here. If you could see what the heck is going on for dynamo I will work on the other clean up. Not sure why it added like 2k extra lines in the rebase... |
This comment was marked as resolved.
This comment was marked as resolved.
Signed-off-by: William Dykas <wdykas@nvidia.com>
Contributor
Author
|
/claude strict-review |
Signed-off-by: wdykas <wdykas@nvidia.com>
Signed-off-by: wdykas <wdykas@nvidia.com>
Signed-off-by: wdykas <wdykas@nvidia.com>
Contributor
Author
|
/ok to test a2e9402 |
Signed-off-by: wdykas <wdykas@nvidia.com>
Contributor
Author
|
/ok to test 098fafb |
Contributor
Author
|
thanks for the feedback @tdene ! |
tdene
reviewed
Oct 14, 2026
Signed-off-by: wdykas <wdykas@nvidia.com>
Signed-off-by: wdykas <wdykas@nvidia.com>
Contributor
Author
|
/ok to test f192b94 |
Signed-off-by: wdykas <wdykas@nvidia.com>
Contributor
Author
|
/ok to test 5458fb3 |
chtruong814
approved these changes
Oct 14, 2026
tdene
approved these changes
Oct 14, 2026
Contributor
Author
|
/ok to test 5458fb3 |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/38757286826 |
Signed-off-by: wdykas <wdykas@nvidia.com>
Forward the already-finalized request through the handoff override, preserving pre-release output capture and exactly-once record merging. Extend the existing native/external handoff regression to cover both completion paths. Signed-off-by: wdykas <wdykas@nvidia.com>
Contributor
Author
|
/ok to test e962afe |
Contributor
Author
|
/ok to test e962afe |
|
🔄 Merge queue validation started! You can track the progress here: https://github.com/NVIDIA/Megatron-LM/actions/runs/38955783253 |
1 of 7 tasks
This was referenced Oct 20, 2026
Closed
This branch was previously deployed
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 MR completes end-to-end prefill/decode disaggregation for Megatron dynamic inference. Prefill and decode run as dedicated, independently parallelized shards. A coordinator routes requests and manages capacity and ownership, while KV and SSM tensors move directly between GPU workers through NCCL or NIXL. The coordinator carries request metadata and lifecycle messages only; it is not in the tensor data path.
Native coordinator request flow
sequenceDiagram autonumber participant U as Client / RL rollout participant C as Coordinator participant P as Prefill shard participant D as Decode shard P->>C: REGISTER_ROLE(prefill, capacity, transfer metadata) D->>C: REGISTER_ROLE(decode, capacity, transfer metadata) C-->>P: REGISTER_ROLE_ACK C-->>D: REGISTER_ROLE_ACK U->>C: Submit prompt and sampling parameters C->>P: Route using prefix affinity and available capacity P->>P: Execute prompt P->>P: Produce first token and optional MTP proposals P->>P: Pin prompt KV and exact final live SSM state P-->>C: Prefill result and handoff metadata C->>D: SUBMIT_REQUEST_WITH_KV D->>D: Match contiguous locally cached KV prefix D->>D: Reserve missing KV, continuation blocks, and a live SSM request slot alt NIXL P-->>D: One-sided read initiated by decode else NCCL D-->>C: KV_TRANSFER_READY C-->>P: SEND_KV P->>D: Send uncached KV suffix and SSM state end D->>D: Aggregate completion across model-parallel ranks D->>D: Broadcast KV_HANDOFF_COMPLETE within the MP group D->>D: Register imported complete-block hashes D->>D: Admit directly into decode without prompt replay D-->>C: KV_READ_DONE C-->>P: RELEASE_KV P->>P: Release pinned KV and SSM storage D-->>C: Generated tokens / final result C-->>U: Generated tokens / final resultRequest lifecycle
Role registration
Each engine registers as either a prefill or decode instance. Registration includes its request capacity, transport backend, KV layout, and hybrid SSM layout when present. The coordinator validates that paired engines have compatible model geometry.
Prefill routing
The coordinator selects a prefill instance using prefix affinity, available capacity, and current load. The prefill engine executes the prompt and captures everything required to continue decoding.
Source-state retention
When prefill finishes, its prompt KV blocks are temporarily retained so the allocator cannot reuse them during transfer. For hybrid models, the exact final live SSM slot is detached from the completed request and retained in the same way.
Decode-side cache reuse
The coordinator selects a decode instance using prefix affinity, available capacity, and current load. Decode recomputes the prompt's complete-block hash chain and finds the longest contiguous prefix already present in its local cache. Only the uncached KV suffix is allocated and transferred. Complete blocks are hash-indexed for reuse; a partial final prompt block is transferred but remains request-owned rather than being registered as a reusable prefix. Concurrent imports reserve their hashes so two requests cannot independently import and register the same prefix.
State transfer
NIXL performs decode-initiated one-sided reads. NCCL uses matching receives and sends: decode first commits its destination storage and reports
KV_TRANSFER_READY, after which the coordinator tells prefill to post its sends. Different prefill and decode TP, PP, EP, and expert-TP layouts are supported by the KV and SSM re-sharding planners.Decode admission
Decode waits until every model-parallel rank has completed the transfer, then admits the request directly into the active decode batch. It does not replay any prompt tokens. The handoff includes the sampled first token and any MTP proposals so decoding starts at the exact continuation point. These continuation tokens have not passed through the base model yet, so decode produces their KV locally and allocates continuation blocks only when they cross a block boundary.
Source release
Once decode no longer reads prefill storage, it reports
KV_READ_DONE. The coordinator sendsRELEASE_KV, allowing prefill to release its temporary KV references and retained SSM slot. NCCL sources remain pinned until their local send handles are also complete.Control plane and data plane
The coordinator carries request and control metadata:
The GPU workers transfer model state directly:
Large KV and SSM tensors are never serialized through the coordinator.
Key design decisions
max_requestsfor EP dummy forwards. Real requests and retained handoffs cannot consume it, so an idle rank can still participate in expert collectives when every request-owned slot is occupied. The slot is reused between dummy steps, and its memory is included when sizing the recurrent-state and KV buffers.RL checkpoint loading and refit
Each role-tagged RL inference shard is an independent checkpoint and refit destination. Checkpoint loading therefore uses the shard's process group rather than the global world group. Refit performs one collective pass for each disjoint destination pool: source ranks participate in every pass, while only ranks belonging to that pool materialize the destination weights.
CUDA graph-aware prefill scheduling
When
--inference-cuda-graph-all-prefillsis enabled, the scheduler treats each captured(token count, prefill count, decode count)shape as capacity rather than requiring the real batch to land exactly on its token boundary. For example, a 128-token graph can execute a 100-token chunk with padding, so the scheduler uses the full 100-token budget instead of shrinking the chunk to the next smaller captured size. This reduces the number of prompt chunks and avoids unnecessary eager execution.The same graph-coverage check applies to both initial and continuation chunks. If the current resident batch prevents a compatible shape, the queue-head request waits while that finite batch drains and changes shape. Hybrid models use strict matching because captured prefill and decode SSM slots are not interchangeable; attention-only models can reuse unused request capacity more flexibly. Graph admission is a local CPU scan and does not add a model-parallel collective.
If an idle engine cannot cover a new request, it reports a configuration error instead of silently ignoring all-prefill graph mode. The only eager fallback is a lone continuation that has already started and cannot match any captured shape; without other resident work, deferring it could never change the batch and would deadlock progress.
Disaggregation protocol headers
These messages form the control plane. KV and SSM tensors are transferred directly through NCCL or NIXL and are never serialized through the coordinator.
Disaggregation-specific headers
REGISTER_ROLEREGISTER_ROLE_ACKSUBMIT_REQUEST_WITH_KVKV_TRANSFER_READYSEND_KVKV_READ_DONERELEASE_KVKV_HANDOFF_COMPLETENIXL does not use
KV_TRANSFER_READYorSEND_KV; decode initiates direct reads after allocating its destination storage.Existing headers reused by disaggregation
CONNECT/CONNECT_ACKSUBMIT_REQUESTENGINE_REPLYENGINE_REPLY_PARTIALABORT_REQUESTREQUEST_ABORTEDREQUEST_ERRORDISCONNECTSHUTDOWNTP_BROADCASTKV_HANDOFF_COMPLETE, but it is not specific to disaggregation.PAUSE,UNPAUSE,SUSPEND,RESUME,SET_GENERATION_EPOCH,STOPSTART_CUDA_PROFILER,STOP_CUDA_PROFILERCurrent limitations
Configuration
A native deployment is described using role-tagged inference shards, for example:
--inference-shards "tp=1,dp=2,role=prefill+tp=1,dp=2,role=decode" --disagg-kv-transport-backend ncclEach role can use its own supported TP, PP, DP, EP, and expert-TP configuration.