Repository navigation
[PD] Share one KV staging/landing transport across transfer plans - #3306
Conversation
🏷️ CI GuideRuns automatically on every eligible PR before approval:
Heavy model tests:
|
valar-cop
left a comment
There was a problem hiding this comment.
a few small things..
e2e gpu/mooncake p dcp=1 -> d dcp>1 run on this exact head?
ci green.
Jasen2201
left a comment
There was a problem hiding this comment.
Reviewed 0a56a99891ae5d2f1db6a5a105bf4b86c9c95133 against its parent 373a27fbf. I found no blocking issues in this refactor.
I checked the DCP ownership mapping independently of TP size, PP region mapping, partial-page tails, destination MR boundaries, staging reservations, credit exhaustion, and the READY/write-done lifecycle. The failure handling is a useful improvement: an uncertain staged write retains its source slot and disables staging; blocked waiters wake, and a waiter whose write was never submitted returns its own landing credit. Subsequent requests take the direct path without overwriting the retained source buffer.
Validation on Linux / MI308X with Python 3.12 and ROCm PyTorch 2.10:
- 575 passed across all seven test files changed or added by this PR, including the GPU gather, scatter, and buffer-allocation cases.
- 260 additional review checks passed outside the checkout: 256 deterministic combinations of block size, DCP rank/interleave, TP size, mixed region widths, fragmented pages, MR boundaries, and READY offsets; plus error/exception fallback, a failed writer with a blocked slot waiter, and an actual two-chunk staging transfer.
- The initial missing-
jsonschemaand device-mask failures reproduced unchanged on the parent. Correcting only the isolated test environment produced the fully passing result above.
For follow-up coverage, I recommend adding the concurrent failed-writer/blocked-waiter case and staged two-chunk destination-cursor case to the repository tests.
The GPU tests exercise real gather/scatter kernels with simulated NIC writes. Full-model P/D Mooncake RDMA and GSM8K accuracy evidence remains the earlier ff2b3a6e5 validation documented in the PR; those results are separate from the tests I ran on this head.
|
ci triage for bc8b9b8:
|
Withdrawing my approval to complete the requested review of code size and simplification opportunities.
Jasen2201
left a comment
There was a problem hiding this comment.
There is concrete scope to reduce this refactor. I recommend the four simplifications below: remove the obsolete descriptor/fallback APIs, carry only region indices, hoist the common bounds calculation, and use one per-operation write-outcome flag.
I built an isolated prototype against 0a56a9989: 56 fewer production lines (36 fewer lines including the test migration). The existing byte-equivalence and MR-boundary assertions now exercise TransferPlan.direct_descriptors(). 574 repository tests and 260 additional review checks passed on the MI308X setup; the one removed test covered the deleted, unused first_units option. GPU gather/scatter kernels were exercised with the tests' simulated NIC.
The GatherLayout stride/head-slice fields and topology/layout separation should stay: the stacked #2846 already uses them for real PAGE/head gathering. The reduction above preserves that reuse and the failed-write lifetime guarantees.
This follow-up is a COMMENT review; my earlier approval has been dismissed.
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (6)
- Don't let one uncertain staged write disable staging for good and fail unrelated requests.
mooncake_connector.py:3478-3482(_write_staging_slotfinally) sets_kv_staging_failedand callsSlotPool.fail. A singleFalsefrom_rdma_write(a decode restart or a Mooncake timeout) moves every later DCP transfer from this prefill, to any decode, onto the per-token path for the life of the process. Requests already waiting for a slot raisestaging row unavailable. Probeprobes/probe_staging_failure.py: the same transfer goes from 12 to 156 descriptors, and a concurrent request to a healthy decode fails. On main the slot was released. Instead, hold only the failed row, time-bounded byATOM_PD_FAILED_WRITE_HOLD_SasLandingCredits.quarantinealready does atlanding.py:117, keep the pool alive, and log at WARNING when staging capacity drops. - Restore the deadline error logs (valar-cop, unaddressed).
_write_staging_slot:3435and:3441returnNonesilently, and the probe shows zero WARNING+ records. main logged"%s write for req %s passed its %.0fs transfer deadline". - Use
self.tp_sizedirectly._make_staging_plan:3285,3287usesgetattr(self, "tp_size", 1), a getattr defense for test-built objects in product code.tp_sizeis always set in__init__. If tests need it, set it in the test helper. - Delete the dead code this refactor leaves behind (Jasen2201, unaddressed).
DCPShardPlan.staged_page_runs(sharded_transfer.py:137) andpack_slots(first_units=)(:187) now have only test callers. Move their byte and MR-boundary tests ontoTransferPlan.direct_descriptors. Also:staged_token_regionsshould belist[int](:3188/3217). Hoistplan.source_units.max()out of the per-region loop (:3299). Makesubmitted/settledone flag (:3417-3480). Drop the destination-cursor check (:3307-3312): both callers pass exactly that slice, so it can never fire. Inready_items(:3393),_transfer_dst_offsetis always 0 because landing is never offered on chunked transfers. - Fix the docs and comments the rename broke.
envs.py:142still says "see mla_landing.py" (valar-cop). The 55-line credit and READY protocol docstring ofmla_landing.pybecame 5 lines inlanding.py:1-9. Restore the failure-semantics and slot-ownership paragraphs. Restore theTrue/False/Nonereturn contract on_write_staging_slot. Fix "MLA staging pool" at:174,:1336,:3946and the hard-coded "8 MiB" in the_build_landinglog (:1652). Restore the type hints the three new methods dropped. - Run P DCP1 → D DCP>1 end to end on this head and post transfer numbers. The PR says this head never ran on a GPU (valar-cop asked too). The GLM-5.2 numbers are from
ff2b3a6e5, before the rebase and split. This rewrites the production MLA staging/landing send path, so post GSM8K plus staged/landed throughput or TTFT against main on this exact sha. Add CPU tests for the new "PAGE wider than the landing slot" branch (:3322-3330, untested) and for a second transfer after a failed write.
Non-blocking: TransferTopology.source_tp/target_tp/target_tp_rank and GatherLayout's strided fields are only validated here; they are for the stacked #2846 (open, based on this branch). Full list: result.json.
Reviewed at 0a56a99. Already fixed: none (first valarLip review).
|
@atom-bot review |
|
aiter-bot — queued behind 1 review(s); expect to start in about 50 min. The box reviews one PR at a time. |
aiter-bot
left a comment
There was a problem hiding this comment.
ATOM PR #3306 — [PD] Share one KV staging/landing transport across transfer plans
Consolidates the Mooncake P/D MLA staging and landing send path into one shared KV transport: a new transfer plan resolves DCP token ownership and per-region byte layouts, a byte-gather fills a GPU staging slot, and a single gather→slot→RDMA→READY lifecycle serves both the landed and the staged-per-page paths.
Review:
Validation (deterministic): NOT RUN — no exact-head validation report exists (auto-validation disabled) and I ran no test myself; the PR's only full-model evidence (GLM-5.2 GSM8K 93.48%) is from pre-split runtime ff2b3a6, and the PR body states this head has never run on a GPU.
_execute_staged_transfer/_write_staging_slot in mooncake_connector.py replace _execute_mla_regions/_execute_staged_mla_regions/_write_mla_slot) and its only full-model evidence is from pre-split, pre-rebase runtime ff2b3a6 — with an earlier anomalous 80.52% run (CI 42192702736) the PR body itself calls unresolved — so a regression in the rewritten path would reach production uncaught by the unit tests. Author must run the P DCP1 → D DCP>1 end-to-end (GSM8K plus staged/landed throughput) on this exact head and post the numbers.
DCPShardPlan.staged_page_runs and pack_slots(first_units=) now have only test callers (both production callers were deleted in this diff), the destination-cursor check in _make_staging_plan compares a slice against the very dst_block_ids list both callers sliced it from so it can never fire, ready_items' page_offset is always 0 because landing offers are never attached to chunked transfers, and staged_token_regions carries (region_idx, dst_base, bpb) tuples of which only region_idx is read — future readers cannot tell live code from dead, and the byte/MR-boundary tests still exercise the dead staged_page_runs instead of TransferPlan.direct_descriptors. Author must delete the dead paths and move their tests onto the live primitives.
3 finding(s) posted inline, on the lines they are about:
atom/kv_transfer/disaggregation/mooncake/mooncake_connector.py:3477-3484— mooncake_connector.py:3477-3484atom/kv_transfer/disaggregation/mooncake/landing.py:1-10— The rename guts the protocol documentation and leaves stale names: mla_landing.py's 55-line credit/READY…atom/kv_transfer/disaggregation/mooncake/mooncake_connector.py:3285—_make_staging_planusesgetattr(self, "tp_size", 1)twice (mooncake_connector.py:3285, 3287)
_Independent refutation: 5 judged, 0 killed, 5 defended — same-family (claude reviewed its own output). Step 7.6 above
… retired #3306 now hands a transfer that wanted a staging slot after an uncertain write `_StagingRetired`. The head-cut staging path catches it and falls through to the direct head-slice descriptors instead of failing. Co-authored-by: Cursor <[email protected]>
0a56a99 to
51f94be
Compare
… retired #3306 now hands a transfer that wanted a staging slot after an uncertain write `_StagingRetired`. The head-cut staging path catches it and falls through to the direct head-slice descriptors instead of failing. Co-authored-by: Cursor <[email protected]>
#3306 replaced retiring the KV staging pool with a per-slot hold: a transfer that wants a staging slot while every slot sits out an uncertain write's hold gets `_StagingUnavailable`. The head-cut staging path catches that instead of `_StagingRetired` and falls through to the direct head-slice descriptors.
Both callers pass the very slice of dst_block_ids the check compared against, chunked transfers included, so it could never fire (#3306 review). `_transfer_dst_offset` stays: chunked PAGE landing still needs it for the READY page offsets.
#3306 now returns a KV staging slot after a failed write, as main does, so the pool is never retired and no transfer gets _StagingUnavailable. The head-cut staging path returns the staged transfer's result directly again.
51f94be to
2096c55
Compare
valar-cop
left a comment
There was a problem hiding this comment.
LGTM
ci Run non-GPU unit tests (Pre Checkin) failed — not sure yet (low): The saved log is empty, so the failure cannot be attributed; the same job on main failed in the two nearest runs (2026-11-16 03:32 and 04:29), which suggests it is not PR-specific, but that is unconfirmed.
next: Re-run the job and attach its log; if it reproduces only on this head, inspect the new P/D staging/landing tests under tests/. https://github.com/ROCm/ATOM/actions/runs/43811804219/job/133114889942
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (3)
- Re-run GLM-5.2 GSM8K at the final head and add a staged/landed throughput number against main. Both GSM8K runs in the description (43795323850, 43799028653) ran on
3a51f4ee2, which sits on51f94bead. That is before the last two commits, which change_execute_staged_transfer/_write_staging_slotagain. One of the two runs missed the 0.92 gate (91.89%), and the main control never started. This rewrites the production MLA staging/landing send path, so post GSM8K and one P TP1 → D DCP4 TTFT or transfer-GB/s comparison against main for2096c5567. A relative number is fine. - Update the PR description to match the code. The first "Behavior changes" bullet still describes the retired pool: "keeps its source slot until connector teardown … turns staging off … send their token rows per token".
2096c5567reverted that to main's rule: the slot goes back after the write returns, and only a failed landed write's credit is quarantined (mooncake_connector.py:3446-3458,:3527). Also drop "on this head" from the GSM8K section and the stale test count. - Delete the passthrough and fix the leftover wording.
staging_config.py:75-76staging_reserve_bytesonly callspd_producer.mla_staging_reserve_bytes; import the real one or move it.pd_producer.py:203still says "MLA staging pools".landing.py:7-9says the staged path sends "one RDMA descriptor per destination page", but it coalesces runs (transfer_plan.py:92-115).
Non-blocking: TransferTopology.source_tp/target_tp/target_tp_rank, GatherLayout's strided fields and units_per_page != block_size exist only for the stacked #2846. The PR also adds two class-level defaults for connectors that tests build without __init__ (mooncake_connector.py:1332-1334); please set them in the test helper instead. The moved getattr(config, "decode_context_parallel_size", 1) (staging_config.py:37, copied from main) could become a direct read. Non-GPU unit test failures (2× test_mxfp4_apply_hands_the_shared_output_to_fused_experts) also fail on main d2d5a6bbb. Full list: result.json.
Re-reviewed at 2096c55. Already fixed: permanent staging retirement (back to main's per-write release + credit quarantine; valar-cop's bounded-hold ask is moot), deadline error logs (_passed_deadline :3530), self.tp_size direct, staged_page_runs / pack_slots(first_units=) deleted and tests moved to direct_descriptors, staged_token_regions: list[int], hoisted source_units.max, destination-cursor check dropped, envs.py:142 reference, landing protocol docstring restored, True/False/None contract, "8 MiB" log, PAGE-wider-than-landing-slot and write-after-failure tests.
… retired #3306 now hands a transfer that wanted a staging slot after an uncertain write `_StagingRetired`. The head-cut staging path catches it and falls through to the direct head-slice descriptors instead of failing. Co-authored-by: Cursor <[email protected]>
Revert "[PD] Share the KV staging and landing test fakes". The duplicated helpers it removes are already on main, so sharing them rewrites main's test call sites and doubles this PR's test diff without touching the transport it changes. A follow-up PR carries it.
The send worker synced the request's landing partition a second time; main adopts it once, in the write listener. A request queued before a decode restart then rolled the target back to the old epoch, and the restarted decode's next request rebuilt the new epoch with its in-flight slots free, so two writers could land in one slot. Without the worker-time sync such a request finds no credit under its epoch and stages straight to the pages. Also log once per decode rank when its landing slot is narrower than a destination PAGE, pin the wire-layout check with a test, say that gather_units refuses GatherLayout's strided slices, and set _kv_staging_reserve and _landing_spec in the tests that build connectors without __init__ instead of on the class.
The staged path sends one RDMA descriptor per run of adjacent destination pages within a memory region, not one per page; say so in the landing module and the ATOM_PD_MLA_STAGING comment. plain_mla_model re-imported get_hf_text_config locally under a comment about importing transformers early, but staging_config already imports it at module level. Import the attention selector there too.
It writes one RDMA descriptor per run of adjacent destination pages, so "staged per-page" in the ATOM_PD_MLA_LANDING docs and comment and in two landing log lines described it wrongly.
With the per-token fallback gone, add_token_runs had one caller left and did what _dcp_token_descriptors already does on main; call that instead, as main's block transfer does.
00b6881 to
93b5dcf
Compare
|
Thanks, @Jasen2201. Both inline suggestions are in 49b21fd (replied on each). The test setup cleanup is in #3424, at the top of this stack (after #2846). Most of the duplicated setup was already on main, so sharing it here rewrote main's test call sites and doubled this PR's test diff without touching the transport this PR changes; on its own it is easier to review. It moves the fake NIC and stream, source regions, producer connector, write request, transfer call, the CUDA stream patch every connector test repeated, and the MLA producer config the staging tests imported from |
|
Thanks, @valarLip. Status at 93b5dcf, rebased onto
Non-blocking, all in dcdba9d: the PAGE-wider-than-the-landing-slot fallback logs once per decode rank; The rebase picks up #3069's DCP helpers: a staged region only validates through |
There was a problem hiding this comment.
Re-reviewed at 93b5dcf (on main 19c292f). No blocking issues. The landed path's credit release and quarantine, its seq and the manifest-before-READY order match main's; LandingCredits.sync is back to the write listener only; the direct descriptors write the bytes staged_page_runs did and still stop at destination MR boundaries; and the staging pool is sized from the same reserve the KV budget held back.
What is left is mostly code for cases that cannot occur. Inline: two such branches, and the startup log hints. Two more of the first kind:
_execute_staged_transferand_write_staging_slotenter the stream throughtorch.cuda.stream(stream) if ... else nullcontext()(:3505,:3613). Staging is always on CUDA (_build_kv_stagingadmits only CUDA views), the tests already patchtorch.cuda.stream, and main entered the stream unconditionally. Please drop both conditionals._make_staging_planchecks again what_block_planalready validated. Its role check (:3435) repeats_block_plan's pairing, and #2846 then has to switch it off for unit layouts (check_roles).token_contiguous(:3444,transfer_plan.py:49,168) is derived from the role after_dcp_token_unithas refused every non-MLA region, so it is always True where it is checked. Please drop the role check, the field and its check.
Still open from earlier rounds:
- The throughput or TTFT comparison against main (valarLip's item 2). When it runs, please rerun the GLM-5.2 GSM8K case on the same head too. The last accuracy run was on 5f6cd29 (now b889a03); dcdba9d and 93b5dcf changed the send path since.
- The scatter thread is still named
mooncake-mla-landing(landing.py:421).
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (3)
- Post the staged/landed throughput or TTFT comparison against main, and rerun GLM-5.2 GSM8K on the same head (asked three rounds now). You said it has not run yet. This PR rewrites the production MLA staging/landing send path. The last GSM8K run was on
5f6cd29d1(nowb889a0372), and since thendcdba9db6and93b5dcf25changed_execute_staged_transferand the per-token branch. One P TP1 → D DCP4 (or GLM PP4 → DCP4) run on93b5dcf25is enough, TTFT or transfer GB/s, staging on vs main. A relative number is fine. - Fix the startup logs this PR rewrote (Jasen2201's inline notes).
mooncake_connector.py:1733-1735logs "PAGE exceeds the reserved pool; using direct writes", but without a poolstages_token_unitsis False and MLA rows go per token through_dcp_token_descriptors. The log should say "goes per token" and give the slot and reserve sizes, as main did. The staging line (:1744-1749) and the landing line (:1777-1783) also drop main's "set ATOM_PD_MLA_STAGING=0 if no decode runs DCP" / "set ATOM_PD_MLA_LANDING=0 if none does" hints and the send-worker count. Both pools are on by default and come out of the KV budget on every plain-MLA instance, so the log is the only runtime pointer to the switch. Please restore them. - Make the description and the leftover name match this PR. The first "Behavior changes" bullet presents the PAGE-wider-than-landing-slot and region-wider-than-staging-slot fallbacks as behavior of this PR. Neither can trigger here (an MLA PAGE is far below the 8 MiB slots, and
slot_bytes = max(widest, ...)). Say that #2846 enables them. Also rename the scatter threadname="mooncake-mla-landing"(landing.py:421) to match the renamed module (aiter-bot).
Non-blocking: when #2846 makes the PAGE-wider fallback reachable, have that stage report landed_slots=None rather than [] (:3491, aiter-bot), otherwise the decode never takes the partition back. staging_reserve_bytes (staging_config.py:113) is still a one-line wrapper; that is fine if #2846 makes it the MLA+MHA sum as you said. The docs (landing.py:23, environment_variables.md ATOM_PD_MLA_LANDING row) omit the max(1, ...) floor on the per-PP-stage share (landing.py:440). make_zmq_path is rebuilt per landed slot inside the loop (:3540); hoist it. Full list: result.json.
Re-reviewed at 93b5dcf. Already fixed: the worker-time LandingCredits.sync is gone, so a partition is adopted only on request receipt (:2459), and a CPU probe confirms that an old-epoch request now gets no credit and the in-flight slot is not handed out again. Also fixed: the duplicate get_hf_text_config import, the landing.py/envs.py "per page" wording, the GSM8K "this head" label, the wire-layout test, the PAGE-wider log, and the class-level test defaults. Pre Checkin incl. non-GPU unit tests is green; heavy CI did not run.
|
Re aiter-bot review #3306 (review): renamed the scatter thread to |
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (3)
- Post the staged/landed throughput or TTFT comparison against main, and rerun GLM-5.2 GSM8K on the current head (asked four rounds now). Nothing new has been posted since your "not run yet" reply. The description still says "No performance run was made for this head" and "GSM8K has not been rerun since"
5f6cd29d1(nowb889a0372). Since then,dcdba9db6and93b5dcf25changed_execute_staged_transferand the per-token branch. One P TP1 → D DCP4 (or GLM PP4 → DCP4) run on8c7bb73a6is enough: TTFT or transfer GB/s, staging on vs main. A relative number is fine. - Fix the startup logs (asked last round, unchanged).
mooncake_connector.py:1733-1735still says "PAGE exceeds the reserved pool; using direct writes". With no pool, MLA rows actually go per token through_dcp_token_descriptors. Jasen2201 shows this branch cannot trigger, so delete it or reword it to main's "go per token" with sizes. The staging line (:1744-1749) and the landing line (:1777-1782) still drop main's "set ATOM_PD_MLA_STAGING=0 if no decode runs DCP" and "set ATOM_PD_MLA_LANDING=0 if none does" hints, and the send-worker count (main:1737,:1801-1810). Please restore them. - Make the description match this PR and answer Jasen2201's dead-branch notes. "Behavior changes" bullet 1 still presents the PAGE-wider-than-landing-slot and region-wider-than-staging-slot fallbacks as behavior of this PR. Neither can trigger here (
slot_bytes = max(widest, ...)at:1728; an MLA PAGE is far below 8 MiB). Jasen2201 asked you to delete them (:3335bpb <= slotcheck,:3486-3495fallback,_log_page_wider_than_landing), and also thenullcontextstream conditionals (:3505,:3613) and the redundant role check /token_contiguous(:3435,:3444,transfer_plan.py:49,168). These have no reply yet. Delete them, or say why they stay. Either way, the bullet should say that #2846 enables these fallbacks.
Non-blocking: the comment at :3337-3338 ("staging sends page runs, and per-token arrays ... would dominate") no longer holds, because _make_staging_plan builds plan.source_units per token. make_zmq_path is still rebuilt per landed slot (:3540). int(landing["epoch"]) is recomputed inside the slot loop (:3512, :3564, :3569). 24 * spec.table_segments (staging_config.py:122) needs a name or comment (3 int64 tables). The max(1, ...) share floor (landing.py:440) is still missing from the docs. Full list: result.json.
Re-reviewed at 8c7bb73. Already fixed: the scatter thread is now mooncake-landing (landing.py:421, aiter-bot); the landed_slots=None note moved to #2846 (ba1652f). Pre Checkin incl. non-GPU unit tests is green; heavy CI did not run. Local CPU run: 573 passed, 3 env-only failures (missing jsonschema), the same as main.
…artup hints Branches no MLA transfer can reach: - _build_kv_staging no longer handles zero slots. An MLA slot is at most 8 MiB and the reserve is min(workers * 8 MiB, 256 MiB), so staging_slot_count returns at least one. - _execute_block_transfer no longer checks bpb against the slot width: slot_bytes is at least the widest eligible region. - The PAGE-wider-than-the-landing-slot fallback and its once-per-rank log are gone, along with TransferPlan.minimum_slot_bytes. An MLA PAGE is far below the 8 MiB landing slot, and pack_slots raises if one ever is not. - _make_staging_plan no longer checks region roles (_block_plan already pairs them), and RegionLayout loses token_contiguous: _dcp_token_unit refuses every non-MLA region before a plan is built. - Both staging gathers enter the send worker's stream unconditionally, as main did; the pool is only ever built on CUDA. The staging and landing startup lines again say how to give the HBM back (ATOM_PD_MLA_STAGING=0 / ATOM_PD_MLA_LANDING=0) and how many send workers share the pool, as main's did. Also: the landing epoch and notify path are read once per transfer, not per slot; landing_reserve_bytes spells out the [3, segments] int64 table; the landing docs state the max(1, ...) floor on a stage's share.
valarLip
left a comment
There was a problem hiding this comment.
⚠️ Action required before merge (2)
- Post the staged/landed throughput or TTFT comparison against main, and rerun GLM-5.2 GSM8K on the final head (asked five rounds now). Nothing has been posted since your "not run yet" reply. The description still says "No performance run was made for this head" and that GSM8K "has not been rerun since"
5f6cd29d1. Since then,dcdba9db6,93b5dcf25and nowbc8b9b807(landingslot_bytesand epoch handling, stream entry) changed_execute_staged_transfer. One P TP1 → D DCP4 (or GLM PP4 → DCP4) run onbc8b9b807is enough: TTFT or transfer GB/s, staging on vs main. A relative number is fine. - Update the description to match
bc8b9b807. "Behavior changes" bullet 1 now describes code this PR deleted: there is no PAGE-wider-than-landing-slot fallback (_log_page_wider_than_landing,minimum_slot_bytesand thelanding = Nonebranch are gone), and no region-wider-than-staging-slot path (thebpb <= slotcheck is gone). Drop the bullet, or say that a PAGE wider than the slot now raises inpack_slotsand cannot happen for MLA. Also: the "CPU unit tests on this head … adds 24 passing tests" line is from before this commit, which removed a test (two parametrized cases). And the "GLM-5.2 shared MLA/DCP accuracy validation" section should say up front that it ran atff2b3a6e5, not on this head.
Non-blocking: _build_kv_staging now has no guard for slots == 0. The case cannot happen (it needs an MLA PAGE over 8 MiB), but if it ever did, SlotPool(0).acquire() would block the send worker forever. A one-line assert slots (mooncake_connector.py:1715) would turn that into a startup error. The _build_kv_staging docstring (:1697) says "every eligible byte-layout adapter", but only MLA_KV_ROLE regions are eligible. landing_spec, staging_reserve_bytes, landing_reserve_bytes (staging_config.py:103,113,117) and gather_units (gather.py:61) have no return annotations. Full list: result.json.
Re-reviewed at bc8b9b8. Already fixed in bc8b9b8 (Jasen2201's inline notes and the last round's items 2-3): the unreachable zero-slot branch with its "direct writes" log, the bpb <= slot check, the PAGE-wider fallback with its log, the role check, token_contiguous and both nullcontext stream conditionals are deleted. The startup lines again carry the ATOM_PD_MLA_STAGING=0 / ATOM_PD_MLA_LANDING=0 hints and the send-worker count (:1726-1733, :1764-1769). Also fixed: the stale "page runs" comment (:3320), epoch/make_zmq_path hoisted out of the slot loop (:3476), 3 * 8 * table_segments (staging_config.py:127), and the max(1, ...) floor in the docs. Pre Checkin incl. non-GPU unit tests is green; heavy CI did not run. Local CPU: 571 passed, 3 env-only failures (jsonschema), the same as main.
|
Thanks, @Jasen2201. Everything from your review at 93b5dcf is in bc8b9b8; the three inline notes are answered on each.
From earlier rounds: the scatter thread has been named #2846 (539c3b6) and #3424 (3e34cdb) are restacked on bc8b9b8. |
|
Thanks, @valarLip. Status at bc8b9b8, covering your reviews at 93b5dcf, 8c7bb73 and bc8b9b8:
Non-blocking items from your 8c7bb73 review, all in bc8b9b8:
Non-blocking items from your bc8b9b8 review:
Tests: on bc8b9b8 the CPU suites show no failure that main 19c292f does not also show. bc8b9b8 removed one test (two parametrized cases), so this PR now adds 22 passing tests instead of 24. The #2846 staging/landing test files pass on 539c3b6 (799 passed, 30 skipped). GPU unit tests have not been rerun on this head. |
…PP_MAX_INFLIGHT) (#3070) * feat(pp): PAGE-backed Kimi-K3 state checkpoints under PP Stages agree on one joint checkpoint spec over the PP group, so a PAGE store or restore op names the same unit ids on every stage. Prompt-end anchors and demand checkpoints are floored onto the LMCache chunk grid, a PAGE checkpoint is filed when its chunk is scheduled, and the NUMA binding uses the PP-aware GPU index that ModelRunner picks its device by. Co-authored-by: Cursor <[email protected]> * feat(pp): Kimi-K3 LMCache state tier under PP, with a producer fence on state stores Each PP stage builds its own state tier, keyed by its PP-aware worker id, and state stores wait on an event recorded on the compute stream at dispatch. Qwen layouts keep refusing the tier under PP. K3's default bound on outstanding saves is multiplied by the pipeline depth. Co-authored-by: Cursor <[email protected]> * feat(pd): Kimi-K3 KV and KDA state from a PP prefill to a DCP x TP decode The K3 builder places MLA rows and KDA slots by module layer and publishes each slot region's TP segments, and the producer writes the consumer rank's share, ReplaySSM records included. A decode TP that is not a multiple of the prefill TP, a consumer outside the producer's head group and a chunked receive by a DCP decode of a stateful model are refused. PP stages 1..7 drop a request's producer entry once its write completes. Co-authored-by: Cursor <[email protected]> * perf(pd): MLA staging for a DCP consumer, and more PP batches in flight An unsharded producer gathers a DCP consumer rank's MLA tokens into staging pages on a per-slot side stream and writes one descriptor per destination page (ATOM_PD_MLA_STAGING_CHUNK_PAGES, off by default, held back from the KV cache budget). Each slot's gather stream takes ATOM_PD_MLA_STAGING_STREAM_PRIORITY and is warmed at startup. The PP head keeps up to ATOM_PP_MAX_INFLIGHT batches in flight (0 = stage count). Co-authored-by: Cursor <[email protected]> * fix(pd): refuse a sparse MLA model under PP disaggregation by name Co-authored-by: Cursor <[email protected]> * docs(offload): Kimi-K3's default save bound scales with pipeline stages Co-authored-by: Cursor <[email protected]> * fix(pd): staged MLA writes stop at destination MR chunks; review follow-ups Co-authored-by: Cursor <[email protected]> * perf(offload): split the PP state budget by image so every stage keeps the same count Each PP stage capped its state tier at OFFLOAD_STATE_CPU_SIZE over its own image, so a stage with a smaller image kept images the largest-image stage had already evicted, while the head bounded its index by the largest image. Pool the stages' budgets and split them in proportion to image bytes, as scale_cpu_size_for_pp does for the KV pool: every stage keeps budget * stages // joint image bytes, and the head bounds its index by the same count. The total across stages is unchanged. pipeline_image_bytes only fed the old bound, so it goes. Co-authored-by: Cursor <[email protected]> * refactor(pp): agree the PP checkpoint spec at one call site Every stage now reaches `_agree_pipeline_checkpoint_spec` through one call, a stage without recurrent state passing None, and PP without initialized distributed groups raises instead of skipping the agreement. The local spec is built by `_local_checkpoint_spec`. Also restate why demand checkpoints floor onto the LMCache chunk grid. The chunk covering a fork holds tokens past it, so the next fork's lookup stops at the chunk floor and an off-grid demand cannot be reached once the prefix leaves HBM. The old reason, `hbm_off_chunk_grid`, no longer exists. Co-authored-by: Cursor <[email protected]> * fix(offload): keep anchors and demands that flooring would remove Flooring the prompt-end anchor onto the LMCache chunk grid turned any anchor below one chunk into 0, so a short prompt kept no checkpoint at all. With a 128-token hash block and 1024-token chunks, an 896-token prompt lost its 768-token HBM reuse. This applied whenever the hash block is finer than the chunk, not only under PP. Such an anchor now stays where it was. No whole chunk of it reaches the CPU tier either way. A demand whose floor lands at or below the hit was dropped for the same reason. It now keeps its own position and serves HBM. Co-authored-by: Cursor <[email protected]> * test(v41): give the index-layout connector fake the new slot-region attributes #2809's test_pd_checks_physical_layout_before_writing builds the Mooncake connector as a SimpleNamespace, so it needs the three slot-region attributes this PR reads, set to None as in the other connector fakes. Co-authored-by: Cursor <[email protected]> * Scale the default pending-save bound with PP on Kimi-K3 only QwenOffloadScheduler inherits KimiK3OffloadScheduler.__init__, so Qwen under PP also took the PP-scaled default max_pending_saves (2 -> 16 at PP8 with one copy worker) and could pin more source blocks for its KV saves. Only K3 has been run with the scaled default, and the docs and the PR describe it as K3's. Gate the multiplier on a class attribute that Qwen turns off, and cover both layouts at PP8. Co-authored-by: Cursor <[email protected]> * test(mha-pp): give the MHA PP producer fake the new slot-region attributes Co-authored-by: Cursor <[email protected]> * refactor(k3-offload): one async save contract for dense KV and K3 state The dense KV save and the Kimi-K3 state store both copy device memory a forward wrote, from a thread of their own, and each carried its own copy of the fence and of the release/terminal bookkeeping. Write the contract once in `_offload_common.py` (and the offload README) and share the code: - `record_save_fence` records one event per step on the current stream; it is now the record site of both `DenseOffloadConnector.start_load_kv` and `KimiK3OffloadConnector._start_state_stores`. - `wait_save_fence` is the host wait of both `_do_save_req` and `StateOffloadTier._do_store`, and fails closed on a missing fence. - `SaveLifecycle` emits a save's source release at most once and its terminal exactly once; `_do_store` uses it for the early D2H release and the end-of-store backstop. No behaviour change: same record point, same host wait from #3155, KV chunk packing and state image packing stay separate. The KV save keeps its terminal on `_do_save_req`/`_guard`: its source release is per staging group under early block release and is the terminal itself on Kimi-K3. Tests cover both paths in one step (fence recorded before each submit, carried into the KV store and the state store, waited on before the KV store reads), a raising KV fence and a raising KV store each reporting one failed terminal, a state store with no fence failing before it reads, and `SaveLifecycle` itself. Co-authored-by: Cursor <[email protected]> * Address review: direct fence and publish calls, PP state-tier tests - wait_save_fence calls event.synchronize() directly; the dense save takes producer_event as a required keyword, waits on it unconditionally and always forwards it to store(). - publish_idle_state_work calls the scheduler's _publish_state_loads and _publish_state_stores directly; the scheduler doubles carry both. - state_tier_spans_pipeline() is the one list of layouts that keep the state tier under PP: state_tier_capability and KimiK3OffloadScheduler's pending-saves default both read it, so QwenOffloadScheduler needs no override of its own. - Test that Qwen hosts no state tier under PP, and that the PP head's shutdown drain publishes no state work. - The removal of the unused pipeline_image_bytes moves to the next PR in the stack, to keep this one within 15 files. Co-authored-by: Cursor <[email protected]> * Remove the unused pipeline_image_bytes The previous PR in the stack splits the stages' CPU state budget by pipeline_op_bytes (state_tier_cpu_entries), so nothing reads the largest stage image any more. Drop the field, its wire key and its checks, and the argument model_runner passed for it. Co-authored-by: Cursor <[email protected]> * Address review: placement and TP-split tests, one DCP relayout helper - Tests: a PP stage's MLA rows, KDA slots, ReplaySSM records and cursor placed by layer number; the KDA slot regions' TP segments; the sparse MLA refusal under PP; the per-request-state block ratio on a full transfer; and the stateful transfer from an unsharded PP stage to a DCP x TP consumer (token relayout, the TP split with its replicated cursor, and the out-of-group, non-multiple-TP and unsplittable refusals). - `_consumer_dcp_plan` and `_dcp_token_descriptors` serve both `_execute_block_transfer` and `_execute_block_slot_transfer`. - `has_mla_indexer` and `pipeline_parallel_size` are read directly. - The placement comments describe `consumer_region_indices` as it is: group-major from the stage's `start_layer`, in groups of its layer count. Co-authored-by: Cursor <[email protected]> * Address review: stage K3's MLA pages through the existing MLA staging Drop the second staging pool (MLAShardStaging, _build_kv_staging, _execute_staged_kv_transfer, mla_shard_staging_reserve_bytes and the ATOM_PD_MLA_STAGING_CHUNK_PAGES / _STREAM_PRIORITY settings). Instead: - _build_mla_staging no longer skips a producer with slot regions: an MLA hybrid's MLA pages are staged like a plain MLA model's. - mla_staging_reserve_bytes holds the pool back for every MLA family (mla_staging_model), not only plain MLA. Landing stays plain-MLA only. - _execute_block_slot_transfer takes the request's KV ready event and, for a DCP consumer, hands its MLA regions to _execute_mla_regions, as the block-only path does; the slot state still goes whole after them. Co-authored-by: Cursor <[email protected]> * Pass the largest stage image in the PP state budget test for_pipeline still takes the largest stage image on this branch; #3069 drops it with the rest of pipeline_image_bytes. Co-authored-by: Cursor <[email protected]> * State the placement fallback as consumer_region_indices computes it Layer l of group g goes to g * (peer regions / groups) + start_layer + l. Co-authored-by: Cursor <[email protected]> * Drop the largest stage image from the PP state budget test for_pipeline no longer takes it. Co-authored-by: Cursor <[email protected]> * Test the K3 worker tier under PP and document the pooled state budget Build each stage's tier of a PP2 x TP2 run at TP rank 0: the stages key under different worker ids and both keep the image count the engine's index mirrors. A Qwen PP worker now logs that its layout keeps no state tier under PP instead of blaming a missing layout id. State that OFFLOAD_STATE_CPU_SIZE is the stages' average under PP, in state_tier_cpu_bytes and the Kimi-K3 AgentX recipe, and that the scheduler's state-tier stores take the connector's pending-save bound. Co-authored-by: Cursor <[email protected]> * Give the PP tier test the spec fields the tier reads The tier reads only layout_id, image_bytes and pipeline_op_bytes, so the test no longer depends on PagedStateCheckpointSpec.for_pipeline's signature, which #3069 changes. Co-authored-by: Cursor <[email protected]> * Stage MLA pages only for models without a sparse indexer glm5_next_text is Family.KIMI_MLA, so a GLM-5.3-Flash producer reserved and allocated the 128 MiB staging pool, which it can never use: a DCP consumer cannot take its indexer region per token. mla_staging_model now names plain MLA and the KIMI_MLA hybrids without an indexer, and _build_mla_staging allocates only for a model it names, so the pool and its reserve agree. ATOM_PP_MAX_INFLIGHT's row said a middle prefill chunk does not count; every launched batch counts until the last stage completes it. The slot loop skips building per-token descriptors for a staged MLA region. Tests: a zero reserve for a sparse hybrid; _build_mla_staging over Kimi-K3's and GLM-5.3-Flash's published views; the head filling a cap above the stage count and the cap's env reader; and a PP stage that stages its MLA pages while writing its state. Co-authored-by: Cursor <[email protected]> * Refuse a TP split before any page moves Check the consumer's TP part and every slot region's split before Phase 1, so a refused transfer leaves no MLA page on the peer. Test the DCP refusal in _validate_chunked_receive and a drafter's MLA row on the last stage, and say that replicated regions ignore their segments. Co-authored-by: Cursor <[email protected]> * Name the stage the shared CPU pool has to be sized for The state tier splits its budget by image bytes while scale_cpu_size_for_pp splits LMCACHE_MAX_LOCAL_CPU_SIZE by layer count, so the stage with the most state per layer sets the pool size: stage 0 of Kimi-K3 at PP8. Co-authored-by: Cursor <[email protected]> * Give stage 0's share of pp_size x LMCACHE_MAX_LOCAL_CPU_SIZE in the K3 recipe Co-authored-by: Cursor <[email protected]> * Read the KDA segment units from slot_indexed_caches The SSM and ReplaySSM record units were read off caches named again here. Take them from the list state_slot_regions publishes from, so the two stay in step. Co-authored-by: Cursor <[email protected]> * Test that a PP stage past 0 drops its producer entry once served Co-authored-by: Cursor <[email protected]> * Choose MLA staging before building per-token DCP descriptors _execute_block_transfer built every region's per-token source, destination and length arrays before checking whether the region goes through MLA staging, so a staged region allocated arrays it never used. Split the role/size validation into _dcp_token_unit, run only that for staged regions, and build the descriptors for the per-token path alone. A regression test fails if a staged region calls the descriptor builder. Co-authored-by: Cursor <[email protected]> * Validate staged MLA regions in the block-plus-slot transfer too The block-only path checks a staged region's role and per-token width before handing it to staging; the block-plus-slot path skipped that check. Run _dcp_token_unit there as well, so both paths refuse the same regions. Co-authored-by: Cursor <[email protected]> * Test the asymmetric-DCP gate on the slot transfer path _execute_transfer lets an unsharded (DCP1) producer send slot data to a DCP decode, and still refuses a sharded producer of another DCP size. No test reached that gate with slot data: test_pd_pp.py called _execute_block_slot_transfer directly. The new test drives _execute_transfer for DCP1 to DCP2, DCP1 to DCP8 and DCP2 to DCP4; reverting the gate to `self.dcp_size != consumer_dcp_size` fails the first two. Co-authored-by: Cursor <[email protected]> * Annotate the KDA segment and DCP plan helpers; rename the DCP admission test _kda_slot_tp_segments returns list[tuple[int, ...] | None] and _consumer_dcp_plan a DCPShardPlan. The admission test also covers the deepseek_v3 accept case, so it is renamed to test_a_dcp_decode_refuses_chunked_receive_only_for_a_stateful_model. Co-authored-by: Cursor <[email protected]> * Rename the PP producer-entry test and annotate _dcp_token_descriptors The producer-entry test checks that stage 0 keeps its entry and stage 1 drops it, so name it after the stage that drops. Give token_runs the array-triple annotation the other DCP helpers carry. Co-authored-by: Cursor <[email protected]> * Keep this PR to ATOM_PP_MAX_INFLIGHT Drop the Kimi-K3 MLA staging (mla_staging_model, the slot loop's staged MLA regions, the reserve and their tests and doc row). It moves to a later PR built on #3306's shared staging transport, which replaces the interfaces it used. The in-flight cap, its tests and doc, and the two Co-authored-by: Cursor <[email protected]> #3069 nits (test name, _dcp_token_descriptors annotation) stay. * Validate ATOM_PP_MAX_INFLIGHT with _optional_int_env envs.py now rejects a negative value through the shared validator, so pp_max_inflight only falls back to the stage count. The envs.py comment is wrapped and says the default is the stage count. Co-authored-by: Cursor <[email protected]> --------- Co-authored-by: Cursor <[email protected]>
|
@zhuyuhua-v pls help merge the pr thanks |
* [PD] Drop transfer-plan and gather checks their only caller rules out build_transfer_plan and gather_units are called only from _make_staging_plan and _write_staging_slot, which never pass what these checks refused: - Producer DCP / consumer without DCP: _execute_block_transfer stages only in its branch for a non-DCP producer and a DCP consumer. - Positive sizes and target ranks: the token plan passed in comes from _consumer_dcp_plan, whose build_dcp_shard_plan already rejects a non-positive block or DCP size and a DCP rank outside its group. The TP sizes and TP rank are read by nothing else here. - Negative PAGE indices: both block lists are scheduler block tables. - Unequal source/target PAGEs: _block_plan already refuses a byte-width mismatch in either of its branches. - PAGE width not divisible by block_size: _dcp_token_unit refuses it before the region is staged. - gather_units' dtype, contiguity and size checks: _build_kv_staging admits only contiguous CUDA uint8 views (each a whole number of PAGEs), the staging pool is contiguous uint8, and pack_slots keeps each item inside its slot with one unit per index. - Whole-unit check: build_transfer_plan only builds whole-unit layouts. The tests that only exercised these refusals go with them; the docstrings now state what callers must pass. * [PD] MiniMax PP-to-TP PAGE staging and landing Behind ATOM_PD_MHA_LANDING (default off, set on P and D), a MiniMax TP1 prefill stage gathers each TP decode rank's heads of every PAGE into a staging slot and writes it to that rank's landing pool, which scatters it into the paged KV. The planner cuts heads from the unit layout's head runs, and only on the PAGE path asks for a TP1 producer. Chunked transfers land too: the decode checks every stage's handoff before completing. Co-authored-by: Cursor <[email protected]> * [PD] Write head slices directly when a waiting transfer finds staging retired #3306 now hands a transfer that wanted a staging slot after an uncertain write `_StagingRetired`. The head-cut staging path catches it and falls through to the direct head-slice descriptors instead of failing. Co-authored-by: Cursor <[email protected]> * [PD] Write head slices directly when every staging slot is held back #3306 replaced retiring the KV staging pool with a per-slot hold: a transfer that wants a staging slot while every slot sits out an uncertain write's hold gets `_StagingUnavailable`. The head-cut staging path catches that instead of `_StagingRetired` and falls through to the direct head-slice descriptors. * [PD] Drop the KV staging destination cursor check Both callers pass the very slice of dst_block_ids the check compared against, chunked transfers included, so it could never fire (#3306 review). `_transfer_dst_offset` stays: chunked PAGE landing still needs it for the READY page offsets. * [PD] Drop the head-cut fallback for a retired staging pool #3306 now returns a KV staging slot after a failed write, as main does, so the pool is never retired and no transfer gets _StagingUnavailable. The head-cut staging path returns the staged transfer's result directly again. * [PD] Follow #3306's staged-path cleanup in the MHA landing tests #3306 dropped the PAGE-wider-than-the-landing-slot fallback: a MiniMax PAGE is a few KiB against an 8 MiB landing slot, and pack_slots raises if one ever does not fit. The capacity test no longer forces a narrow landing slot; the source-slot case, which this PR's head-cut path handles, stays. The send worker now enters its stream unconditionally, so the CPU harness patches torch.cuda.stream for its stand-in stream, as the MLA staging tests do. * [PD] Stage MiniMax head cuts from the unit plan's validated cuts `_block_plan` already validates the consumer's unit layout and caches each region's head cuts in `plan.cuts`, which the direct head-slice writes use. The staged path decoded the layout a second time (`_target_head_runs`, which also read a `consumer_head_major_runs` field nothing writes) and recut the heads in `_page_gather`, so the two paths each held their own copy of the ownership result (Jasen2201, valarLip review). `_make_page_plan` now turns the cached cuts into each region's gather with `GatherLayout.from_slices`, the constructor #3471 extends to runs of named widths, and `page_transfer_plan` pairs the block lists. The connector picks PAGE or token units once, at its two call sites, and `build_transfer_plan` is back to the DCP token plan alone. Both staged plans share the source bounds check. Gone with it: `_target_head_runs`, `RegionLayout`'s head runs, `_page_gather` and its equal-TP branch (equal TP sizes produce no cuts), its TP1-producer and nonuniform-run refusals (`_unit_plan` and `consumer_head_slices` make them), the combined token/head refusal and the PAGE count check (callers never pass those), and `TransferTopology`'s TP sizes, TP rank and producer DCP, which nothing reads now. The head-cut path no longer falls back to direct descriptors when a slot cannot hold one destination PAGE (`minimum_slot_bytes`): a MiniMax head slice is tens of KiB against an 8 MiB slot, and `pack_slots` raises before any slot or RDMA is taken if one ever does not fit, as for the landing-slot fallback #3306 dropped. The PAGE wire id becomes `page_units_v1`, matching `token_rows_v1`. `mha_pages_v1` never reached main; a P and D on different ids fail the request with "KV landing wire layout mismatch" before any write. Tests: head ownership is built through the new path, byte-exact as before. The refusal test and the source-slot-too-small capacity case go; the DCP test of a replicated plane drops its TP parameters, which the topology no longer takes. * [PD] Share the prefill handoff check between direct and landing receives `_record_write_done` checked a chunked receive's handoff twice: in the landing branch this PR added and in main's direct branch, on two dict shapes told apart only by a `landing_nonce` key (Jasen2201, valarLip). `_PendingHandoff` is that state, and `fold` validates one stage's handoff, compares it with the stages before and accumulates the failure, for both paths. Each keeps its own completion: the direct path counts stages in the write-done tables; the landing path counts them here, before it tells `LandingReceiver`, which completes only once the landed slots are scattered. The landing branch no longer reaches `_pending_handoffs` through `getattr`; `__init__` always sets it. The MLA landing tests' `_consumer`, which built a connector without it, sets it and the completion lock. `_complete_recv` is back to main's. A stage whose handoff does not fold reports itself failed to the receiver, so the receive already arrives failed; one that arrives unfailed folded every stage's handoff, so its metadata is set. A failed direct stage's handoff is no longer kept as the metadata; the receive is failed then, and `_complete_recv` does not read it. * [PD] Gate MiniMax page staging on Mooncake's producer rule, named for MiniMax `mha_staging_reserve_bytes` took `kv_role` in ("kv_producer", "kv_both") as the producer, but Mooncake makes a missing role a producer and `kv_both` a consumer (`is_producer`). A `kv_both` decode held back a staging pool nothing used; a producer that omits `kv_role` reserved nothing and silently fell back to direct head slices (Jasen2201). `minimax_page_staging` now asks `mooncake_producer_connectors`, as the MLA reserve does, and the reserve sums over those entries. The connector reads that predicate instead of inferring `_page_staging_enabled` from a nonzero reserve, and the gate is named for what it admits, MiniMax-M3 only (Jasen2201): - ATOM_PD_MHA_LANDING -> ATOM_PD_MINIMAX_LANDING - mha_landing_model -> minimax_landing_admitted - mha_staging_reserve_bytes -> minimax_page_staging + minimax_staging_reserve_bytes - mha_landing_configured -> minimax_landing_configured - MHA_SCATTER_SEGMENTS -> MINIMAX_SCATTER_SEGMENTS The variable never reached main, and no recipe or CI cell sets it. The PAGE plan and wire layout stay model-neutral; admitting another head-major MHA model is a change to this gate alone. The reserve test covers a role left out and `kv_both`. * [PD] Load the strided KV gather's Triton kernel only where it runs `gather.py` guarded its Triton import with `try/except ImportError` and kept a CPU loop for the strided layout, both only for CPU tests: production gathers from CUDA source views (`_build_kv_staging` admits no other) and always has Triton (Jasen2201, valarLip). The kernel moves to `gather_kernels.py`, and `gather_units` imports it in the strided branch, the one only GPU callers take. The whole-unit `index_select` path and every import of `gather` keep running without Triton, which the non-GPU CI job (CPU torch, no Triton) needs to collect the plan and connector tests at all; a strided gather of host tensors now fails in Triton instead of falling back. The CPU loop moves to the tests as `reference_gather_units`. `test_kv_transfer_plan` gathers strided host layouts with it, and the MHA landing harness patches it in for CPU devices, as it already patches `torch.cuda.stream`. The CUDA cases still run the kernel. --------- Co-authored-by: Cursor <[email protected]>
…decode On the slot path a non-DCP prefill sent each MLA row to a DCP decode as its own descriptor, and each KDA state shard as ~225 strided direct writes per decode rank (TP1 -> TP8, DSpark4, ReplaySSM). - MLA rows: Kimi-K3 with a per-token indexer (`kimi_mla_admitted`) gets the token-row staging pool from #3306 over its `mla.kv` regions; phase 1 sets the rows aside and sends them via `_make_staging_plan` with the consumer's PAGE bases. No ready event keeps the per-token path; consumer DCP 1 keeps whole blocks. - KDA state: a separate `kv.state_staging` pool (12 MiB per send worker, capped at 256 MiB). `plan_state_shard` packs a decode rank's TP shard in destination order; `copy_state_pieces` gathers it in one Triton launch over a cached segment table, then one descriptor per region is written. A shard over 12 MiB, consumer DCP 1 or no ready event keeps the direct writes. Both reserves are held back before the KV cache is sized; the KV pool is sized from `kv_staging_reserve_bytes` alone. Co-Authored-By: Claude <[email protected]>
Part 1 of 2, split from #2846. #2846 (MiniMax PP-to-TP PAGE staging and landing) is stacked on this PR.
This PR enables no new topology. It moves the existing MLA staging and landing to a DCP decode onto one shared transport, which #2846 then reuses. The peer topology selects the KV each decode rank owns, the region layout selects the bytes, and one lifecycle sends them: gather into a staging slot, RDMA, then READY.
What changes
transfer_plan.py(new): takes aTransferTopologyand theRegionLayouts and returns aTransferPlan. The plan carries DCP token ownership, slot packing, READY items, and direct-write descriptors that stop at destination MR boundaries. A TP-replicated plane is owned by token, whatever the P and D TP sizes.gather.py(new): byte gather of whole units (token rows) into a staging slot.mooncake_connector.py: one source pool (_kv_staging) and one send path (_execute_staged_transfer,_write_staging_slot) replace_execute_mla_regions,_execute_staged_mla_regions,_write_mla_slotand the MLA token views. When credits run out, or a transfer is too small to land, the gathered slot is written straight to the decode pages.mooncake/landing.py(renamed frommla_landing.py): the receiver and credit protocol takeunits_per_pageandregion_indicesinstead ofblock_sizeand the MLA regions. The config gates and reserves move tostaging_config.py.pd_producer.py: the staging constants drop theMLA_prefix.staging_slot_count(..., reserve_bytes=)sizes the pool from what the KV budget actually reserved.sharded_transfer.py:DCPShardPlan.staged_page_runsandpack_slots(first_units=)lose their last production callers and are removed; their tests run onTransferPlan.direct_descriptors.Behavior changes
main. The staging slot is sized to at least the widest staged PAGE, and an MLA PAGE is far below the 8 MiB landing slot, so for MLA neither slot can be narrower than one PAGE. If a PAGE ever did not fit,pack_slotsraises and the transfer is reported to the decode as failed.mla_landingstays the request field, and an offer without a layout id still means token rows. Log labels change fromstaged-mla/landed-mlatostaged-kv/landed-kv. The registered regions change frommla.kv_staging/mla.landingtokv.staging/kv.landing.Failure handling is unchanged: a staging slot returns to the pool once its write returns, and a failed landed write's credit is quarantined for
ATOM_PD_FAILED_WRITE_HOLD_S, as onmain.Before the split, #2846's planner refused staging whenever the prefill was not TP1 and the P and D TP sizes differed, for example P TP4 → D TP8/DCP8.
main's MLA staging accepts that case. Here the token path does not look at TP; #2846 applies the TP1 rule only where it cuts heads.Validation
CPU unit tests on this head (rebased on
main19c292f) cover the P/D, KV-transfer and offload test files, run once withaiter.diststubbed and once without aiter (as CI runs). Neither run shows a failure thatmaindoes not also show on the same machine; this PR adds 22 passing tests.On 51f94be, GPU unit tests on one MI355X (
rocm/atom-dev:nightly_202611110332, real aiter and Triton) ran the same P/D test files, including the on-device staged gather and landing scatter: 676 passed, with the same 4 failures asmain(image aiter older thanmain). They have not been rerun on this head.GLM-5.2 GSM8K 20-shot (P PP4/TP1 to D TP4/DCP4,
ATOM_PD_MLA_STAGING=1,ATOM_PD_MLA_LANDING=1, real MTP3, all 1319 questions), each from a validation-only branch that adds only the accuracy case:mengqing/pr3306-glm-gsm8k-5f6cd29d1for 5f6cd29 (onpit2-p03-g23), andmengqing/pr3306-glm-gsm8k-20261116for 51f94be, the head before failure handling went back tomain's (onpit2-p03-g52). All runs usedrocm/atom-dev:nightly_202611151511. The 5f6cd29 run logs four P staging pools, four D landing pools and no failed transfer; the 51f94be logs show four P staging pools, D landing traffic and no staging shutdown:The two runs of 51f94be differ by 26 questions (stderr 0.7 pt). A same-day control on main with the same case (43799025838) did not start, because its node failed the GPU-idle preflight, and was not rerun. Since 5f6cd29 the stack was rebased onto
main19c292f (5f6cd29 is now b889a03), dcdba9d stopped the send worker from adopting a landing partition a second time, the per-token DCP path now writes through #3069's descriptor helpers, and bc8b9b8 removed the unreachable width fallbacks, reads the landing epoch once per transfer and enters the send stream unconditionally; GSM8K has not been rerun since. No performance run was made for this head. The earlier results below are from #2846 before the rebase and the split, at runtimeff2b3a6e5.GLM-5.2 shared MLA/DCP accuracy validation
Full-model validation in CI 42337229149 passed with the shared staging/landing path and real MTP3 enabled. No GLM-5.2 accuracy regression was observed in this validated configuration: GSM8K 20-shot flexible exact match was 93.48%, above the 92% acceptance threshold and consistent with the pre-refactor control passing the same gate.
The tested PR runtime is
ff2b3a6e55da6a4fc098ea4b06ec158924fb8e93. The CI checkout was295e2f40933709084774fb87c25a395a5f8457ae; itsatom/code is identical to that PR commit. The only source difference is CI submitter handling for occupied GPUs and node exclusions. No runtime fix was needed to obtain this passing result.pit2-p03-g1520,20,20,18, eager executionblock_size=16,ATOM_MLA_PAGE_SIZE=1ATOM_PD_MLA_STAGING=1,ATOM_PD_MLA_LANDING=1on P and D; Mooncake RDMA, no Store/LMCachemax-num-batched-tokens=8192/2048;max-model-len=16384; prefix caching enabledrocm/atom-dev:nightly_202610261558, digestsha256:57477e7a4b5156fcc7b21bab082eba98577752465f58479ac2ead8514f882a61All three evaluations used the same 1,319 questions, prompts and targets, verified by per-sample hashes, with scores recomputed from the sample JSONL. The independent repeat ran on automatically allocated
pit2-p03-g34, also with runtime identical toff2b3a6e5. Both current-code runs exceeded the 92% gate; these measurements do not establish an accuracy improvement over the control.For CI 42337229149, logs confirm four P shared staging pools, four D
token_rows_v1landing pools (16 units/PAGE), and actual landing/scatter traffic. Real MTP3 acceptance was 70.88%. The CI completed successfully; no decode traceback was found. The known P-side cleanup tracebacks occurred after evaluation during SIGTERM teardown. The independent repeat also exercised actual landing/scatter traffic, with 71.37% MTP3 acceptance.An earlier full-configuration run, 42192702736, scored 80.52%. That anomaly was not reproduced in the two current-code validations, and its root cause remains unresolved. The evidence supports no observed GLM-5.2 accuracy regression in the tested configuration; it does not establish that the historical anomaly was fixed or exclude an intermittent issue.
Feature tracking: https://github.com/wuhuikx/LLM-Booster/issues/368
Related work: https://github.com/wuhuikx/LLM-Booster/issues/318