Repository navigation
perf(pd): negotiated P/D early handoff, overlap the P->D KV transfer with prefill - #3773
ZhangLirong-amd wants to merge 10 commits into
Conversation
🏷️ CI GuideRuns automatically on every eligible PR before approval:
Heavy model tests:
Path scope:
|
There was a problem hiding this comment.
🟡 Changes recommended
Early handoff can deadlock prefill/decode admission until timeout recovery and abort pipeline-parallel prefills because the dispatch rank is not recorded.
2 open issues
What changed in this PR
Adds opt-in early handoff to Mooncake prefill/decode disaggregation, allowing decode-side allocation and KV transfer to overlap prefill without changing the router.
Changes:
- Returns transfer metadata once the producer’s data-parallel rank is known, while prefill continues in the background.
- Adds the default-off
ATOM_PD_EARLY_HANDOFFswitch and uses the existing chunked-transfer path. - Adds CPU coverage for transfer timing, request cleanup, rank reporting, and legacy fallbacks.
| File | Description |
|---|---|
tests/test_pd_early_handoff.py |
Tests early responses, transfer ordering, cleanup, and fallbacks. |
atom/utils/envs.py |
Registers and documents the opt-in environment flag. |
atom/model_engine/engine_core_mgr.py |
Records dispatched data-parallel ranks for handoff metadata. |
atom/kv_transfer/disaggregation/mooncake/mooncake_connector.py |
Enables chunked transfer and bypasses decode-readiness gating for early requests. |
atom/entrypoints/openai/api_server.py |
Selects eligible requests, returns early metadata, and drains detached prefills. |
Review effort: Balanced
valar-cop
left a comment
There was a problem hiding this comment.
some changes needed..
test/run with pp>1 on the P side and the flag on? and evidence for opposite admission order?
ci green.
…OM#3773) on single-prefill points via a runtime patch
|
Thanks for the review. Pushed 05a96aa. PP>1 on P with the flag on: it was broken: the PP branch never recorded a rank, so every early prefill failed closed. Fixed by recording rank 0 (a PP pipeline is one DP rank; D reaches every stage via Opposite admission order: reproduced on CPU with the real P/D schedulers and transfer workers (one prompt per side, D admits B first): the previous head made no progress in either the page-limited or the byte-limited variant. Early requests now keep the D-first admission gate, so P admits in D's order; the probe and the new Regression vs merge base: identical pass/fail lists (2,457 passed / 21 failed in test_pd*, test_kv*, test_scheduler*, test_engine*, test_dp*, test_mooncake*, test_envs*; 3,451 passed / 21 failed in entrypoints + related). The failures are the same container-environment ones on both sides. Black clean; ruff findings only pre-existing ones in engine_core_mgr.py. |
There was a problem hiding this comment.
🟡 Changes recommended
The new test file lacks required copyright lines, and the topology documentation omits decode-side prerequisites whose violation causes HTTP 400 errors rather than legacy-transfer fallback.
2 open issues
2 resolved since last review
Review effort: Balanced
There was a problem hiding this comment.
🔵 Needs a closer look
Human review is needed because GPU results cover the superseded ungated revision, leaving the revised P/D admission timing and PP producer early handoff unvalidated on GPU.
No open issues 🎉
2 resolved since last review
Review effort: Balanced
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (5)
-
Replace the attribute probes with declared fields and an explicit gate.
atom/entrypoints/openai/api_server.py:913:getattr(pc, "is_multinode_dp", False).ParallelConfig.is_multinode_dpalways exists (atom/config.py:1128), and your test fake sets it too. Usepc.is_multinode_dp.api_server.py:1055:getattr(seq, "pd_routed_dp_rank", None). Declarepd_routed_dp_rank: int | None = Noneas a class-level default onSequence. That adds nothing to the pickle, and the read can be direct.api_server.py:912:hasattr(engine.core_mgr, "_add_prepared_requests"). This probe also gets the class wrong.DisaggCoreManager(RapidServe,engine_core_mgr.py:2596) inherits_add_prepared_requests, so it passes, but it overridesadd_request(:2796) and never records the rank. With RapidServe + a Mooncake producer + the flag, every P/D prefill would then take the fail-closed 500 atapi_server.py:1056-1063instead of the legacy path.- Gate explicitly instead, e.g. a
reports_dp_rankclass attribute that is True onCoreManagerand False onDisaggCoreManager/RemoteCoreManager. It is cached, so there is no per-request cost.
-
Share one helper for the producer endpoint.
_early_handoff_endpoint(api_server.py:915-929) copieskv_transfer_info(api_server.py:3762-3778): the sameiter_connector_configsloop, the same mooncake/kv_producer predicate and the sameproducer_endpoint(...)call. Use one helper, e.g._mooncake_producer_endpoint(cfg). -
Document what the legacy router relay now does differently. The doc row says "The router and D are unchanged". The protocol is unchanged, but:
- the router drops P's load guard as soon as P answers (
atom/mesh/src/routers/http_pd_router.rs:1174-1175), so with several P its load accounting no longer covers P's queued prefill; - a P failure after the early 200 (engine reject, P crash, expiry) is invisible to the router, and D only learns of it through its own timeouts.
State both in the
ATOM_PD_EARLY_HANDOFFrow, as the PR body's Risks section already partly does. - the router drops P's load guard as soon as P answers (
-
Re-measure on this head. Revision 2 adds the D-first gate, so P now waits for the router→D→P hop. The A/B and C1 tables are from the ungated revision 1. Post an off/on A/B on 0a952da (plus the C1 idle table) before merge.
-
Nit:
mooncake_connector.py:498storesself.early_handoffbut uses it only on the next line. Make it a local.
Note for the combined recipe (#3759, owner #3777): with ATOM_DP_IDLE_WHEN_BLOCKED also on, an early request held at the D-first admission gate makes has_forward_work() vote "work", so P runs back-to-back DP dummies until D reserves. That is tracked on #3777.
Checked, no change needed: with the flag off, nothing changes apart from storing the rank after the frame is pickled. Also checked: the rank is recorded correctly on every dispatch path (DP, single engine, PP head, failed send); the drain task releases io_processor state; an expired early request is aborted and reclaimed; the router relay renames dp_rank and D takes the first token from the handoff; the CI lane ran all 25 tests.
Reviewed at 0a952da (Deep; 2 independent passes + cross-PR interaction pass). Already fixed: PP>1 rank, D-first gate (deadlock), doc row incl. D receive limits, PP/_dispatch_to_dp_ranks tests, real /kv_transfer_info test, header.
|
ci triage for 11cc7e4:
|
|
@valarLip thanks. Pushed 52c282f.
On the #3777 note: #3777 now treats a request held at the D-first admission gate as blocked ( CPU checks (v3 container): |
There was a problem hiding this comment.
🔵 Needs a closer look
Human review is needed because the gated revision’s distributed admission and PP-producer early handoff lack GPU progress and latency validation, while published GPU results cover only the superseded ungated revision.
No open issues 🎉
Review effort: Balanced
52c282f to
254d6da
Compare
|
Normalized commit authors (force-push); no code change, the tree is identical to the previous head 52c282f. |
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (1)
- Re-measure on this head (round-1 item 4, still open). The A/B and C1 idle tables in the description are still from the ungated revision 1 (
pr_body"GPU numbers are from revision 1"). Revision 2 makes P wait for the router→D→P hop. Post an off/on A/B and the C1 idle table on 254d6da before merge.
Everything else from round 1 is fixed at head:
pc.is_multinode_dp(api_server.py:938) andseq.pd_routed_dp_rank(:1066) are read directly. The class default (sequence.py:268) keeps an unset rank out of__getstate__.reports_dp_rankis True onCoreManagerand False onDisaggCoreManagerandRemoteCoreManager. Those are the onlycore_mgrtypes the API server sees, and the new test pins all three._mooncake_producer_endpoint(api_server.py:901-924) is shared. Withadvertised_only=True,/kv_transfer_inforeturns exactly what main returns.- The doc row states the dropped router load guard and the P failures the router cannot see (
http_pd_router.rs:1174-1175). early_handoffis a local.
Cross-PR with #3777 (d3145cb): a request held at the D-first gate is now voted blocked. The idle drain still ships chunked_admissions and polls pd_admission_ready, so P wakes within about 1-1.5 ms of D's reservation. Expiry or failure aborts the request and the group wakes. Confirmed with a probe on the merged tree.
Please also resolve the 4 valar-cop threads. They are fixed at head.
Reviewed at 254d6da (round 2; delta pass + prior asks, CoreManager sibling enumeration, /kv_transfer_info contract check, cross-PR merge probe). Already fixed: attribute probes, explicit rank gate, shared producer helper, router-relay doc, local nit.
254d6da to
992400a
Compare
|
@valarLip thanks. Pushed dbf30c7 (normal push on 5c28c71).
Items 2 (split out Tests (CPU container |
Review round 6, item 3: drop `take_sources_to_abort` (connector base, Multi fan-out, the scheduler loop and the fake patches). The `pd_admission_ready` branch of `process_pd_completions` now marks a retired early source `SequenceStatus.ABORTED`, as it already does for a retired waiting request. An allocated early source holds a send claim, so it is never preempted and is running; `Scheduler.abort_request` marks a running request the same way and the step's postprocess finishes it. Also add a flag-off test for main's router-chunked mode: a save for a retired transfer there is only the cancellation of a request that never got a source; the worker reports it safe once and the scheduler, which holds no claim for it, changes nothing else.
|
@valarLip thanks for round 6. We would like to keep both pieces you asked to split out in this PR. This comment covers item 2; items 3 and 4 come in a separate comment with the next push. 2.
|
|
This answers the Copilot overview note on non-streaming early handoff (load tracking released too early, prefill failures and disconnect cancellation lost while P is still prefilling). The behaviour is intended, and P's load is not released early.
No code change for this point. |
|
@valarLip items 3 and 4 of round 6. Pushed 17eb360 (normal push on dbf30c7). 4. Worker-side retired-transfer change: we keep it in this PR
3.
Tests (Windows CPU venv; the same 4.4k-test set of pd/kv/mooncake/scheduler/engine/dp/multi_connector/offload/lmcache/state_checkpoint files on dbf30c7 and on this head):
|
The router asks for early handoff per pair (P offers early_handoff, D declares chunked_receive, D TP a multiple of P TP), so an incompatible D keeps the legacy relay with the default on and no deployment needs an opt-out. Measured 1P1D c256: TTFT mean 543 -> 495 ms (-8.8%), ITL and throughput flat. ATOM_PD_EARLY_HANDOFF=0 turns it off.
|
@valarLip Why it is safe on by default:
Measured: 1P1D on one node at c256, TTFT mean 543 -> 495 ms (-8.8%), with ITL and throughput flat. An earlier revision measured about -19% TTFT on 4P8D at c256.
|
There was a problem hiding this comment.
🟡 Changes recommended
The router drops the worker outcome when a 200 response has malformed data, premature EOF, or a body-read error, misclassifying genuine failures as cancellations and preventing circuit-breaker and worker-error accounting.
1 open issue
Review effort: Balanced
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (4)
Thanks. Items 1, 3 and 5 are done:
_forget_early_sourcekeeps early-source state behind_speculative, andtests/test_pd_source_claim.pypasses at head.process_pd_completionsmarks a retired early sourceABORTED, which is whatScheduler.abort_requestdoes for a running request. The base method, the Multi fan-out, the scheduler loop and the three fake patches are gone. Removing the mark failstest_failed_report_for_an_allocated_early_source_aborts_itand the c2048 stall test.- The nits are fixed.
Item 4 is withdrawn. Your argument holds. With the worker branch reverted to main's silent continue, test_p_stall_past_the_lookup_timeout_releases_the_early_source[False/True] fails even though the scheduler-side abort is kept. So that branch is half of this PR's own leak fix. test_flag_off_router_chunked_retired_transfer_releases_only_its_own_claim covers what it does to main's router-chunked mode.
-
ATOM_PD_EARLY_HANDOFF_AT_SCHEDULE: please still split it out. On your question: the P/D-owned hook would fix the shared-class footprint, which is still at head (send_early_handoff_answersatengine_core.py:90,701,1343andpp_engine_core.py:179,take_early_answersatbase.py:231andmulti_connector.py:988,PD_EARLY_SCHEDULED_KEYatrequest.py:10, and the fake patches). It does not fix the rest. The flag has no measured gain yet (489 vs 495 ms), and the run that could show one (4P8D c512/c768) is still pending. The dependency runs one way: the flag needs this PR's admission rule, and the rule does not need the flag. So a follow-up on top of this PR can bring the flag, its gate answer, the deadlock tests and the hook together, with the 4P8D numbers. -
Keep
ATOM_PD_EARLY_HANDOFFat 0 here (9b58679 flips it to 1). Negotiation makes default-on safe for incompatible pairs, but whether it pays is still unmeasured.- The previous env comment set the gate: "Default 0 until the GPU A/B in the docs row passes" (1P1D c256, 4P8D c512, c768 multi-P).
- The only data is one 1P1D c256 run per arm, taken before the rebase. In that run TTFT p99 got worse: 3218 -> 3821 ms (+19%).
- Default on, every Mooncake P takes the NDJSON relay and allocation before D under the admission rule. That is the multi-P load where the c2048 wedge came from.
Please flip the default in a follow-up with a post-rebase A/B on those configs, or post that A/B here and explain the p99.
-
Answer the open Copilot thread at
http_pd_router.rs:1542, then resolve it. It is right. When line 1 is malformed, or P's body ends or fails before the handoff, the early-handoff branch returns 502 and dropslineswithout finishing itsWorkerOutcome. On a 200 response,WorkerOutcome::droptreats that as a cancellation, so a P that keeps failing this way never records a failure in its circuit breaker or the worker-error metric. Everyprefill_donepath callsfinish(false). Please calllines.outcome.finish(false)before returning the parse error, and add a router test. -
Nit: the squash text is stale. The title says "(opt-in)" and the body says "Default: off", which no longer matches head (or will match again after item 2). The body also still says the declaration and the 400 "cannot drift", and it describes leak fix (a) as
take_sources_to_abort.
Root cause vs patch
Root problem: P could not know whether the chosen D can take a chunked receive, so a default-on flag needed per-model opt-outs. Per-pair negotiation built from D's own acceptance check, with an automatic legacy fallback, is the root fix. Verdict: root fix. The patch-like parts left are an opt-in, unmeasured mode carried in the engine loops (item 1) and a default flipped ahead of its own gate (item 2).
Prior asks: round 6 #1, #3 and #5 are fixed. #4 is withdrawn (see above). #2 is open. Rounds 1-5 still hold.
Reviewed at 9b58679 (round 7, passes A+B; true delta = old head replayed on e5c559a vs head; mutants for the ABORTED mark and the worker retired-transfer branch; Rust outcome path read only (no cargo); CPU tests: test_pd_source_claim 16 passed, early-handoff/chunked/lmcache/metrics/checkpoint 844 passed, the rest are local uvicorn/jsonschema import errors). Already fixed: _early_sources guard, take_sources_to_abort, nits, Kimi-K3 (by negotiation).
|
@valarLip on round 7 item 2. 1. The published ladder ran with early handoff on. All nine points in 2. A/Bs (all on one node, 1P1D P DEP4 + D DEP4, c256, 900 s window, one run per arm):
In the g51 run, p50 is −14%, p90 −8.5%, ITL +0.5% and throughput +0.1% (ON vs OFF). Correction: my earlier comment called the −19% run "4P8D". It was this single-node DEP4+DEP4 setup. 3. The p99 in the g51 run (per-request aiperf exports, A n=10,159, B n=10,176):
So the +19% reflects where requests landed in one burst. It is not a consistent tail cost. We cannot rule out a burst-only effect of up to about 0.6 s (+12% at the burst's p90) from binding every burst request to D at dispatch. If it is real, it touches about 1–2% of requests in this trace, while the rest are about 55 ms faster each. 4. Safety (already accepted in this review): per-pair negotiation with automatic legacy fallback, the admission rule over state slots and usable pages, and the leak fix (a)+(b) with Off switch: Not covered: no post-rebase GPU A/B, and no ON/OFF A/B at 4P8D c512/c768 or with multiple P instances (the ladder at c512/c768 is ON only and has no multi-P point). With several P instances behind one router, the router's view of P load is known to be wrong, as the recipe notes. |
Review round 7 (#3773), item 1. The flag has no measured gain yet and is where the engine-loop footprint came from; the dependency runs one way (it needs this PR's admission rule, the rule does not need it), so it returns in its own PR on top of this one, through a P/D-owned hook. Removed with it, all used by the flag alone: - send_early_handoff_answers and its calls in the EngineCore step, the DP idle drain and the PP head loop; - take_early_answers on KVConnectorSchedulerBase, MultiConnectorScheduler and MooncakeConnectorScheduler (with _answer_early, _answer_at_schedule, _early_answers, _answered); - PD_EARLY_SCHEDULED_KEY (request.py) and the api_server wait for it; - PrefillScheduler.kv_connector = None; - the env, its docs row, its tests and the fake patches in test_dp_sync_interval, test_engine_loop_idle_accounting, test_engine_core_kv_wait, test_lmcache_offload_connector, test_scheduler_metrics and test_pd_source_claim. Kept: the admission rule's gate. An early request that may not allocate before D still waits for D's write request (admission_ready returns _may_allocate_before_d), and default early handoff answers at DP dispatch as before.
Review round 7 (#3773), item 3 (Copilot thread at http_pd_router.rs:1542). When P answers 200 with the early-handoff header but line 1 is malformed, or its body ends or fails before line 1, atom_prefill_kv returned 502 and dropped the response's WorkerOutcome unfinished. On a 200 response WorkerOutcome::drop treats that as a cancellation, so a P failing this way never reached its circuit breaker or the worker-error metric. The branch now calls lines.outcome.finish(false) first, as every prefill_done path does. Test: early_handoff_line_one_failure_is_recorded_as_a_prefill_failure (malformed / eof / cut: 502, one circuit-breaker failure, no success, P's load released).
|
@valarLip thanks. Head is 11cc7e4. 1.
2. Default stays on. Item 2 is answered with the existing evidence in #3773 (comment) (the published ladder ran with it on, the earlier A/Bs, and a p99 analysis of the existing per-request data). 3. Router (11cc7e4).
4. Title and body updated.
Tests, against 9b58679:
|
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (2)
Thanks. Items 1, 3 and 4 are done:
ATOM_PD_EARLY_HANDOFF_AT_SCHEDULEis gone.engine_core.py,pp_engine_core.py,request.py,scheduler.py, the connector base,MultiConnectorSchedulerand the five patched fakes now match the merge base, and nothing in the tree refers to the flag. The gate inadmission_readyis now just_may_allocate_before_d. That is safe because the answer always goes out at DP dispatch, so D learns of every gated request. Reverting the line toreturn Truefails 12 tests intest_pd_early_handoff.py.- The router's line-1 failure now calls
finish(false), andearly_handoff_line_one_failure_is_recorded_as_a_prefill_failurecovers malformed, EOF and broken bodies. - The title and body match the head.
On item 2, the p99 analysis is accepted, and part of the ask is withdrawn. The burst explanation holds up, and a 4P8D or multi-P perf A/B is no longer required. Two things still block the default flip to 1:
-
The default-on path has never run on GPU where it used to wedge. The published ladder ran ON only up to c768, on an older revision. c1024 and above ran with
0because of the state-slot leak this PR fixes, and leak fix (a)+(b) has only CPU tests. A default reaches every Mooncake P/D deployment, including those concurrencies. Please either keep the default at0here and flip it in the follow-up with the AT_SCHEDULE PR, or post one run of this head with early handoff ON:- 1P1D at c1024, plus c2048 if possible, for the recipe's duration;
- 0 errors and no stall;
- after the drain, P's pinned-early pages, state slots and early sources are back to 0.
This is a safety check, not a perf A/B.
-
The recipe on main now gives the wrong advice for default on.
recipes/DeepSeek-V4.1-Flash-PD.mdsays:- "
ATOM_PD_EARLY_HANDOFFis for one P instance only … Leave it unset when more than one P serves a router" (:2741). With the default at 1, leaving it unset turns it on. - "Use
0at c1024 and above until the fix lands" (:107,:157). - "Use only with a single P instance" (
:2464).
The PR body says the router now keeps P's load guard until line 2, but your round-7 reply still calls multi-P load "known to be wrong, as the recipe notes". Please say which of these still holds at this head and update the recipe in this PR. If multi-P load accounting is still wrong, the default has to stay
0, because the default reaches multi-P deployments too. - "
Also reply to and resolve the outdated Copilot thread at api_server.py:1234. The flag it mentions was removed in ea043bf.
Root cause vs patch
Root problem: P could not know whether the chosen D can take a chunked receive, so a default-on flag needed per-model opt-outs. Per-pair negotiation built from D's own acceptance check, with an automatic legacy fallback, is the root fix, and the engine loops no longer carry the opt-in mode. Verdict: root fix. What is left is a default flipped before the regime it once broke has been run (item 2).
Prior asks: round 7 #1, #3 and #4 are fixed. #2 is narrowed to the two points above. Rounds 1-6 still hold.
Reviewed at 11cc7e4 (round 8, passes A+B; true delta = 9b58679..head, merge base unchanged; mutant for the admission gate; Rust read only (no cargo); CPU tests: pd_early_handoff/source_claim/chunked/pp/envs 462 passed, the rest are local uvicorn/jsonschema import errors). Already fixed: AT_SCHEDULE split, router line-1 outcome, squash text, _early_sources guard, ABORTED mark, Kimi-K3 (by negotiation).
… by in-flight prefill load The recipe still said early handoff is for one P instance only, to leave it unset with several P instances, and to use 0 at c1024 and above. With the default on, leaving it unset turns it on. Rewrite those lines for the head: - The ladder ran an older revision with EH=1 on one P instance, c1-c768. c1024 and above used 0 because of the old state-slot leak. - The leak fix is in this PR. - Early handoff is negotiated per (P, D) pair. - The router holds P's load guard, prefill tokens included, until P's line 2. No GPU result is claimed for c1024+ or multi-P. Router test atom_early_handoff_multi_prefill_routes_by_in_flight_prefill_load: two P instances and cache_aware with the recipe's thresholds. While an early-handoff request whose D already answered is still prefilling on P1, the next request with the same prefix goes to the idle P2. Line 2 then releases P1.
|
@valarLip thanks. Changes are in 55968ae. 1. Recipe (updated in this PR). These are the lines in
They now say:
I claim no GPU result for c1024 and above or for multi-P. The recipe says these are covered by CPU and router tests only. 2. Multi-P load accounting is correct at this head. My round-7 reply was wrong on this point: "known to be wrong, as the recipe notes" described the old design. In the old design P's guard was released at the early answer, so a P that was still prefilling looked idle. The c1536 imbalance (P waiting 19 vs 477) came from that design. At head:
Existing tests:
New test, since none had two Ps: 3. Copilot thread Default. It stays CPU tests (rocm/atom-dev, head vs 11cc7e4):
|
There was a problem hiding this comment.
🔵 Needs a closer look
Human assessment is needed because an unpublished finding shows that malformed early-handoff transfer metadata can be treated as cancellation, hiding failures from circuit-breaker and worker-error tracking.
No open issues 🎉
1 resolved since last review
Review effort: Balanced



Summary
P/D (Mooncake) early handoff as a negotiated, per-request feature. The KV transfer from P to D overlaps with P's prefill only when the chosen (P, D) pair can do it. Every other pair keeps today's relay, so no model or deployment needs an opt-out.
This replaces the earlier revision of this PR, which had a global
ATOM_PD_EARLY_HANDOFF=1default plus per-model opt-outs. That revision is kept at branchlirzhang/pd-early-handoff-old-20261127.Default: on.
ATOM_PD_EARLY_HANDOFF=1. P offers early handoff, and the router asks for it only for a pair that negotiates it; every other pair keeps the legacy relay on its own.ATOM_PD_EARLY_HANDOFF=0on P (orATOMESH_ATOM_PD_EARLY_HANDOFF=0on the router) turns it off, and then nothing changes from main.Design
1. Negotiation (wire contract v1)
GET /kv_transfer_info"early_handoff": {"version": 1}ATOM_PD_EARLY_HANDOFF=1(the default), the connector is a Mooncake producer, DP is single-node,CoreManager.reports_dp_rankholds, and router-chunked mode (enable_chunked_transfer) is off. Router-chunked mode takes precedence.GET /kv_transfer_info"chunked_receive": {"version": 1, "accepts", "tp_size", "pp_size", "dcp_size", "reason"}acceptsis built bychunked_receive_capability(cfg). Only its DCP clause is shared with D's own 400 check (_validate_chunked_receive, through_per_request_state_under_dcp). The PP rule is checked there inchunked_topology_supported's form, and the TP rule is restated in the router (atom.rs), so those two are kept alike by hand.kv_transfer_params.early_handoff = trueearly_handoff; Daccepts;D tp % P tp == 0; the request can chunk (no media, n=1, single prompt); P does not advertisechunked_transfer; andATOMESH_ATOM_PD_EARLY_HANDOFFis not0. Unknown D (old ATOM, non-ATOM, failed fetch) means legacy.200,x-atom-pd-early-handoff: 1,application/x-ndjsonkv_transfer_paramswithchunked_transfer=true,transfer_id,dp_rank, endpoint), sent at DP dispatch. Line 2 is{"atom_pd_prefill_done": {"ok": bool, "finish_reason": ...}}, sent at the prefill's end. In every other case P answers plain JSON.Compatibility:
accepts=true.Kimi-K3 (
kimi_linear+ DCP decode), a D with PP>1, and a D TP that is not a multiple of P TP all fall back to legacy automatically. The recipe and the benchmark YAML need no changes.2. Router load accounting and failure visibility
WorkerLoadGuard, including the prefill-token charge, until P's line 2, which is the prefill's end.ok=false, a broken body, or EOF fails the request with 502prefill_errorand drops D.prefill_parse_errorand records a failure in P's circuit breaker and the worker-error metric (WorkerOutcome::finish(false)), like every line-2 failure path.send_decode_during_early_prefill) serves the serial relay and main's concurrent late-kv dispatch (--atom-pd-concurrent, [atomesh] Dispatch the ATOM decode leg concurrently with prefill (--atom-pd-concurrent, default off) #3874). On late-kv, P's line 1 becomes D's kv line, and P stays charged until line 2. On D's 404 fallback, P's prefill keeps running and the relay resends.3. P's admission rule (no fixed cap, no new timeout)
An early request may allocate its source before D's write request arrives only if:
pinned-early pages + this request's prompt pages + max(prompt pages of the other registered, unallocated chunked requests) ≤ the allocator's usable pagesA request with a per-request state slot also needs state-slot headroom. Otherwise it waits for D (the existing D-first gate).
Why this cannot deadlock:
The remaining edge case is a later, larger request that D reorders ahead of an already-pinned one. It ends in a bounded abort through the worker's existing
PREFILL_LOOKUP_TIMEOUT, and a test keeps that path visible.4. Leak fixes for early sources
pd_admission_ready(False)was ignored for an already-allocated source. Implementation: thepd_admission_readybranch ofMooncakeConnectorScheduler.process_pd_completionsmarks the retired early sourceSequenceStatus.ABORTED, as it already does for a retired waiting request (whatScheduler.abort_requestdoes for a running one). No connector-base method and no scheduler loop is added.pd_source_safeinstead of being skipped. This releases its blocks and state slot. Late metadata for a source that already reported safe still cannot resurrect it.5. Split out:
ATOM_PD_EARLY_HANDOFF_AT_SCHEDULEAnswering the router when P first schedules the request (instead of at DP dispatch) is no longer part of this PR. It needs this PR's admission rule, and the rule does not need it. It will come back in its own follow-up PR on top of this one, delivered through a P/D-owned hook rather than the engine loops, together with its gate answer, its deadlock tests and 4P8D numbers. This PR adds no engine-loop code for it:
EngineCore,PPEngineCoreProc,request.py, the connector base andMultiConnectorSchedulerare as on main.Env
ATOM_PD_EARLY_HANDOFF/kv_transfer_info; a pair the router does not ask for keeps the legacy relay.0never offers it.ATOM_PD_EARLY_HANDOFF_SPECULATIVE0always waits for D; kept for A/B only.ATOMESH_ATOM_PD_EARLY_HANDOFF(router)0never asks P for early handoff.Tests (CPU)
tests/test_pd_early_handoff.py, 51 test functions (the 12 answer-at-schedule cases moved to the follow-up with the flag):test_failed_report_for_an_allocated_early_source_aborts_it).ABORTEDmark, the worker retired-transfer branch) makes at least one test fail.atom/mesh):GPU A/B
g51, 1P1D = P DEP4 + D DEP4 on one node, c256, 1230 s window, one run per arm:
Measured before the rebase onto main. The router binary was built from the generic router commit, before the late-kv merge.