Skip to content

refactor(tbo): stage, publish and finish attention metadata once per micro-batch - #3136

Merged
valarLip merged 4 commits into
mainfrom
refactor/tbo-stage-publish-metadata
Nov 9, 2026
Merged

valarLip merged 4 commits into
mainfrom
refactor/tbo-stage-publish-metadata

Conversation

@valarLip

@valarLip valarLip commented Nov 9, 2026

Copy link
Copy Markdown
Collaborator

Summary

Every attention builder's per-step work is split into host staging, one H2D publish and GPU finish, and TBO micro-batches go through the same three steps instead of a parallel ubatch path.

  • TBO cut: a prefill splits at the token midpoint (token graphs), a decode by request in halves (request graphs). The cut is made once a step and handed to every consumer. UBatchSlice carries token_slice / scheduled_token_slice / running_bs; a split decode's tokens run in micro-batch order.
  • Metadata: the per-micro-batch ub{i}_ buffers are declared once in the base builder (kv_indptr / kv_indices / persistent work buffers included) and published as one ub{i}_metadata group. Per-request H2D tags are renamed to seq_metadata. The MHA / MLA / V4 / V4.1 / GDN / Kimi / Qwen4 builders follow the base hooks.
  • Ragged decode queries: refused only where a layer's kernel is rectangular (persistent MLA, MHA layers whose dispatch cannot read ragged queries). Verified on GPU against the kernels: pa_fwd_asm and the non-persistent MLA asm read ragged queries; persistent PA / MLA do not.
  • Config: the TBO support checks and the RCCL auto-disable live in Config (resolved before the PP check). Decode TBO rounds max_num_seqs down to an even number. Removed ATOM_H2D_BACKEND and ATOM_TBO_PREFILL_TOKEN_SPLIT.
  • MTP top-k index share: a capturable pack_row_selections (one program a sequence, no spin, no epoch) replaces the spinning epoch pack.
  • PCP+TBO prefill: each micro-batch reports its own token count. The PCP sparse reindex plans from the persistent all-ones / arange buffers instead of allocating them every step.

Test plan

  • CI-scope unit tests (pytest tests/ --ignore=tests/plugin --ignore=tests/entrypoints/test_openai_server.py): no failure that main does not also have locally
  • GPU-gated H2D publication + sparse MLA tests (RUN_H2D_GPU_TESTS=1): 203 passed
  • DeepSeek-V4.1-Flash DSpark GSM8K (--level 0): 0.9181, no fault
  • CI accuracy / TBO jobs

…micro-batch

Split every attention builder's per-step work into host staging, one H2D
publish and GPU finish, and run TBO micro-batches through the same three
steps instead of a parallel ubatch path.

- TBO cut: a prefill splits at the token midpoint (token graphs), a decode by
  request in halves (request graphs), cut once a step and handed to every
  consumer. `UBatchSlice` carries `token_slice` / `scheduled_token_slice` /
  `running_bs`; a split decode's tokens run in micro-batch order.
- Metadata: per-micro-batch `ub{i}_` buffers declared once in the base builder
  and published as one `ub{i}_metadata` group; per-request H2D tags renamed to
  `seq_metadata`. MHA / MLA / V4 / V4.1 / GDN / Kimi / Qwen4 builders follow
  the base hooks.
- Ragged decode queries: refused only where a layer's kernel is rectangular
  (persistent MLA, MHA layers whose dispatch cannot read ragged queries).
- Config: TBO support checks and the RCCL auto-disable live in Config;
  decode TBO rounds max_num_seqs down to an even number. Removed
  ATOM_H2D_BACKEND and ATOM_TBO_PREFILL_TOKEN_SPLIT.
- MTP top-k index share: a capturable `pack_row_selections` replaces the
  spinning epoch pack.
- PCP+TBO prefill reports each micro-batch's own token count; the PCP sparse
  reindex plans from the persistent all-ones / arange buffers.
@github-actions

github-actions Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

🏷️ CI Guide

Runs automatically on every eligible PR before approval:

  • ✅ Pre Checkin: Black, Ruff, catalog schema validation, non-GPU unit tests

Heavy model tests:

  • ✅ Run after the PR is approved and Pre Checkin passes
  • ✅ Run immediately when an approval review is submitted
  • ✅ Can be requested before approval with labels
Label Tests
ci:full Run all heavy PR model tests: native ATOM, vLLM, and SGLang
ci:atom Run native ATOM model accuracy tests
ci:vllm Run ATOM vLLM OOT model accuracy tests
ci:sglang Run ATOM SGLang model accuracy tests

Heavy jobs are skipped when the PR is not approved and no matching ci:* label is present.
Add labels via the sidebar or gh pr edit 3136 --add-label <label>

@valar-cop valar-cop left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some changes needed..

accuracy run for a tbo-enabled non-v4.1 family (kimi-k3/gdn, qwen)?

ci Run non-GPU unit tests failed — not sure yet (low): The job log under .valar/ci is empty (0 lines), so neither the failure nor its cause can be determined from the context. The same job on main had 7 successes and 1 failure in the window, consistent with an intermittent/infra issue.

(log file job_129245694440.log contains 0 lines)
next: Re-run the job; if it reproduces, capture the failing test name and decide pr_bug vs flaky. https://github.com/ROCm/ATOM/actions/runs/42642134270/job/129245694440

# begin_step publishes them. Derive members from producer groups.
return {
"v41_metadata": tuple(
def h2d_group_members(self) -> dict[str, tuple[str, ...]]:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

h2d_group_members is a method now, but v41_core_overrides.py:87 still calls it as a dict -> AttributeError on vllm path. fix that call too

Load PackedCopy only when a group packs, guard the tests that need the MLA
builder, the drafter or the selection pack Triton kernel with import_guard,
stub selection_pack in the LMCache builder fixture, and keep CPU-only
CpuGpuBuffers unpinned.
backends only annotates with it; importing pcp_utils at load pulls AITER's
parallel_state, which the non-GPU unit run does not have.
The API server imports it at startup (tool_parser -> kimi_k3_grammar ->
structured_output.schema), so an install without the structured-output
extra could not start the server.
@valarLip
valarLip merged commit bf65756 into main Nov 9, 2026
@valarLip
valarLip deleted the refactor/tbo-stage-publish-metadata branch November 9, 2026 17:12
rbrugaro-amd added a commit to rbrugaro-amd/ATOM that referenced this pull request Nov 9, 2026
Brings in ROCm#3136 (stage, publish and finish attention metadata once per
micro-batch), which changes the H2D publication API: producers record
counts by name with `PublicationGroup.set_counts`, `publish()` takes no
counts, and `prepare_sample` always gets the runner's `token_inputs`
group and no longer publishes (`prepare_input_ids` does).

Conflicts:

- atom/model_engine/model_runner.py (prepare_sample): took main's
  `publication_group.set_counts({...})` for the sampling inputs and
  dropped our `group.counts[...]` writes and the `publish(counts)`
  fallback, which main removed. `lossless.stage(...)` now runs right
  after main's set_counts, on `publication_group`, with the same
  arguments (dummy and align-only forwards claim no q; verify bases only
  when the forward verifies). The flag-off path equals main's.
- atom/spec_decode/dspark_proposer.py (_stage_anchors): took main's pad
  rows (zeroed, real rows written at [:scheduled_bs], as the kernel
  does) in place of our tail repeat, and kept staging through `pass_`,
  the greedy or sampled pass.
- tests/test_output_transfer_runner.py: the postprocess batch keeps our
  `any_logprobs=False` and main's `num_spec_step`.
- tests/test_sampler_scalar_filters.py: main's `runner_with_buffers`
  without a transport and `group.publish()`; kept our `bs` and
  `keep_ties` parametrization.

Lossless staging under the new API: `DSparkLossless.stage` records
draft_seed / draft_q_row_base / draft_verify_q_row_base through
`group.set_counts`, so they ride the same single `token_inputs` upload
as the other sampling inputs, and an unknown member name raises. The
prepare_sample and staging tests now use a real `PublicationGroup`
instead of a counts/indices stand-in, and assert stage gets the
publication group itself.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
rbrugaro-amd added a commit to rbrugaro-amd/ATOM that referenced this pull request Nov 9, 2026
ROCm#3136 moved each attention builder's per-step work onto stage / publish /
finish hooks and removed Kimi's prepare_prefill / prepare_decode overrides.
The DSpark GQA draft's context slots follow GDN's state slots onto them:
`_KimiMLAGDNCommon` stages `draft_ctx_slots` in `stage_prefill` /
`stage_decode`, counts it into the phase's group, and lists it in
`h2d_group_members` for both phases, so it goes up with the attention
metadata instead of in its own upload. The slot tests drive the staging
hook, and test_h2d_attention_publication checks the slots ride Kimi's
decode upload.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
rbrugaro-amd added a commit to rbrugaro-amd/ATOM that referenced this pull request Nov 9, 2026
ROCm#3136's request-less dummy_execution (an idle DP rank in its group's
prefill) is no longer an is_dummy_run batch, so compute_draft_kv runs over
its running_tokens padding rows. stage_prefill counted draft_ctx_slots
only to the scheduled tokens (0 there), leaving the previous step's slots
in the rows the draft then writes. Stage them -1 out to running_tokens,
the width the target's slot_mapping goes up at, as stage_decode does.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
rdoshi-amd added a commit to rdoshi-amd/ATOM that referenced this pull request Nov 9, 2026
Brings in main through bf65756 (ROCm#3136, attention metadata staged,
published and finished once per micro-batch). Conflicts resolved on
main's structure:

- model_runner.py: the verify head's ids follow main's running-token
  hidden states (the LM head runs the running tokens, postprocess cuts).
- deepseek_v41/backend.py: the routing decision (served_by_round) is
  taken before the step is staged into main's step_metadata group; lean
  steps stage no compress plans; the decode round sees the step after
  its publication and micro-batches. Dummy steps stay unserved.
- deepseek_v41/cache.py: main's begin_step signature; a lean step (the
  builder's lean=) keeps no plans or planners.
- utils/h2d.py: HostArenaReader and read_host_arena beside main's
  after_publish and count-driven publish.
- tests/test_packed_h2d.py, tests/attentions/deepseek_v41/test_metadata.py:
  main's helpers (_publish, use_packed, stage_query_layout); the
  host-arena tests on them.

Adapted to main:

- The hi prologue reads the step_metadata publication (was
  v41_metadata) and the step's running_tokens (was width).
- The hi gate no longer reads ATOM_H2D_BACKEND (removed by ROCm#3136: every
  eligible group packs) and refuses an FP4 index layout the hi
  programs do not address.
- The hi index sources read and write ATOM's FP4 index plane in either
  gfx950 layout: preshuffle (unchanged programs) or mfma, the OPUS
  scorer's 64-row groups that ROCm#2809 makes the default; the layout comes
  from Config.index_cache_layout and is checked against the cache's.
ganyi1996ppo added a commit that referenced this pull request Nov 10, 2026
Conflicts came from #3136 (TBO metadata staged/finished once per micro-batch):
- backends.py / model_runner.py: take main's build() signature
  (is_prefill, ubatch_slices, pcp_groups); keep our use_cudagraph kwarg;
  drop _ubatch_split_bs (removed on main).
- aiter_attention.py: re-apply the MXFP4 index work map onto main's
  finish_decode / finish_ubatch; allocate the per-ubatch maps in an
  _allocate_ubatch_buffers override, split at max_bs // 2 as
  cut_decode_ubatches does.
- attention_mha.py: follow main in not forcing use_triton_attn in the
  sparse impl.
- tests/test_minimax_m3_mxfp4_decode_batch.py: follow the moved ubatch API.

Co-Authored-By: Claude <[email protected]>
Jasen2201 added a commit that referenced this pull request Nov 10, 2026
Resolve against #3136's per-micro-batch prefill metadata: the concat-group
helpers read the prefix set's buffers, and ubatch_concat_keys goes, since a
TBO micro-batch now builds its own groups.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
yitingw1 added a commit that referenced this pull request Nov 10, 2026
Conflict in atom/config.py: main (#3136) dropped the decode-TBO + spec +
DCP refusal; keep that, and keep the mailbox + decode-TBO refusal. The
mailbox wiring tests now hand _dcp_decode / _dcp_sparse_prefill a
metadata carrying dcp_owned_counts, which main reads from attn_metadata.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
yitingw1 added a commit that referenced this pull request Nov 10, 2026
…inish split

Port the per-rank paged-prefill build onto main's stage_prefill /
finish_prefill structure (#3136):
- Under PCP, stage_prefill stages this rank's own rows (pcp_split) and
  finish_prefill reindexes them; pad query segments get length 0 and the
  per-step indptr/indices fill and reindex helpers are gone.
- Under PCP+TBO each group stages and finishes its own ub{i}_ inputs
  (_stage_pcp_group / _finish_pcp_group) with group-rebased cu_seqlens_q,
  block_tables and replay ranges.
- _pcp_split_rows takes scheduled and running token counts separately.
- Move shared comm helpers into atom/distributed/comm_utils.py.
- Tests: rank segments with running > scheduled, PP relay _aux_blocks in
  the DSpark drafter stubs.

gsm8k 5-shot 200q, V4-Pro -tp 1 -pcp 8: 0.965, +TBO prefill 0.970,
DSpark k=5 0.975 (acceptance 63.76%).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
valarLip added a commit that referenced this pull request Nov 10, 2026
…rows (#3167)

A prefill uploads running_bs block-table rows for the drafter (#3136), but
QSA's seq_lens count only the scheduled requests, so a prefill padded to a
larger graph bucket (14 requests in a 16 bucket) failed
qsa_paged_mqa_logits' row check. Slice the table to the same requests.

Fixes #3160
ZLkanyo009 added a commit that referenced this pull request Nov 10, 2026
…qwen38-lmcache

Brings in #3027's merge of main 4d45f25 (after #3155), which includes
#3136's stage/finish metadata refactor and #3167, and #3027's a7a23f1
(let an answered async miss through the restore-slot gate).

One conflict, in the imports of atom/model_ops/attentions/qwen4_exp_attn.py:
this branch's select_policy, qsa_cache_rules and envs imports are kept;
ScheduledBatch and block_table_state are dropped as on main, since #3136
removed their last uses.

Co-authored-by: Cursor <[email protected]>
valarLip pushed a commit that referenced this pull request Nov 11, 2026
…he drafter's ids (#3177) (#3185)

The gfx1250 DeepSeek-V4.1 single-launch step (#3109, step_override) runs the
whole decode step, drafts included, and returns no hidden states. #3136 sliced
the drafter's input ids by hidden_states.shape[0], so postprocess crashed on
the first served step. ModelRunner._draft_input_ids keeps the hidden states'
rows where there are any (a PCP rank's shard on a pure middle chunk) and takes
the step's running_tokens otherwise, at all three call sites. #3091's served
rounds return hidden states and are unaffected.

Co-authored-by: Claude Opus 5.5 <[email protected]>
PerryZhang01 pushed a commit that referenced this pull request Nov 11, 2026
Review on #3189: forcing the dummy's step to non-verifying also makes it
a prefill step (`BatchStep.decode`), so it runs the prefill FFN rather
than `decode_ffn`. That is how it ran before #3136 and is intended: dummy
batches only feed eager forwards whose output is discarded, while the
batches captures record are not dummies and stay verifying. Docstring
only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
valarLip pushed a commit that referenced this pull request Nov 11, 2026
…#3189)

* vllm plugin: call h2d_group_members, now a method, for V4.1

#3136 made AttentionMetadataBuilder.h2d_group_members a method, but the
V4.1 publication wrapper in the plugin still read it as a dict, so every
DeepSeek-V4.1 serve on the vLLM plugin failed in profile_run:

    v41_core_overrides.py:87, in publish
        for name, names in self.h2d_group_members.items():
    AttributeError: 'function' object has no attribute 'items'

The wrapper only needs the groups V4.1 publishes by name outside TBO
(step_metadata from the builder, the producer groups from the buffers),
which the method returns.

The new test checks the plugin source, since the non-GPU unit run cannot
import the module that broke.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* vllm plugin: keep V4.1 dummy verify buckets non-verifying

#3136 changed native `_prepare_step` from
`verifying = tentative and not batch.is_dummy_run and bool(spans)` to
`verifying = tentative and bool(spans)`: native capture batches are not
dummies. The plugin's warmup before a DSpark capture is: its dummy batch
is fabricated on private scratch with every request at position 0, and
`_v41_prepare_kwargs` marks a uniform verify-width batch tentative so the
plan keeps the verify write grid. `begin_step` now refuses that step and
every DeepSeek-V4.1 DSpark serve on the plugin fails at capture:

    ValueError: Tentative verification needs a prefix and sufficient
    window slack

Begin that one step as non-verifying, as before #3136; the plan still
gets the verify write grid from `tentative`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* vllm plugin: say that a V4.1 dummy verify bucket runs the prefill FFN

Review on #3189: forcing the dummy's step to non-verifying also makes it
a prefill step (`BatchStep.decode`), so it runs the prefill FFN rather
than `decode_ffn`. That is how it ran before #3136 and is intended: dummy
batches only feed eager forwards whose output is discarded, while the
batches captures record are not dummies and stay verifying. Docstring
only.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: perzhang <[email protected]>
Co-authored-by: Claude Opus 5.5 <[email protected]>
whx-sjtu added a commit that referenced this pull request Nov 12, 2026
Bring #3042 and #3099 into whx/k31-perf for recipe F8

Implements wuhuikx/LLM-Booster#496.

Merges #3099 at 945cf21 and #3042 at 0b27b59 into
whx/k31-perf, so prefill tasks measure on the code recipe F8 runs. The OPUS
FP4 indexer cache is selected with --index-cache-layout mfma and needs an
aiter with ROCm/aiter#7798.

Conflict resolution:
- kimi_mla_gdn_attn.py build_kv_cache_tensor keeps #3042's
  index_scale alongside both sides' index_cache.
- sparse_indexer_fp4.py assert_fp4_indexer_supported takes #3042's
  packed_writer without prefill_ubatching, which #3136 removed.
- test_lmcache_mp_native_scheduler.py keeps #3136's _shipped_tokens
  and #3042's block_ids assertion.
- test_lmcache_mp_builder_views.py drops a stale atom.utils.tbo stub.
- test_dsa_indexer_fp4_layout.py skips the HIP writer test through
  import_guard where Triton or AITER is absent.

GSM8K 5-shot on recipe F8 (without --spec-decode-acceptance-length), n=1319:
flexible-extract 0.9727, strict-match 0.9719 (stderr 0.0045).
vgokhale added a commit to vgokhale/ATOM that referenced this pull request Nov 12, 2026
- attention_mha: drop gluon_pa_decode_supported() and the gluon choice.
  pa_decode_gluon_supports_arch() is False on gfx1250, so over_gluon
  already sends those shapes to unified. Drop the two routing tests.
- fused_recurrent: drop the second PAD_SLOT_ID guard; ROCm#3136 covers it.
- test: on gfx1250 Mxfp4MoEMethod interleaves with and without MXFP8
  activations.
Jasen2201 added a commit that referenced this pull request Nov 13, 2026
Resolve against #3136's per-micro-batch prefill metadata: the concat-group
helpers read the prefix set's buffers, and ubatch_concat_keys goes, since a
TBO micro-batch now builds its own groups.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
valarLip pushed a commit that referenced this pull request Nov 14, 2026
* [PCP] Fewer prefill collectives per layer, no reindex readback

Each V4 attention layer under PCP prefill issued 3-5 separate all-gathers
(main compressor input, indexer compressor input, extend K -- two under fp8
KV -- and positions), each through torch.distributed. Now it issues two:

- `pcp_allgather_rerange_many` gathers several tensors in one grouped
  `all_gatherv` and restores token order per tensor. One-byte dtypes travel
  as uint8, since past aiter's custom all-gather limit the call falls back to
  PyNCCL, which has no fp8 dtype.
- The extend K is gathered together with the positions its SWA write
  addresses the ring by. Positions are gathered rather than read off the
  forward context: an MTP draft pass runs at the target's positions + 1.
- `_launch_compressors` projects both compressors' inputs and gathers them in
  one collective; `Compressor.forward(combined=)` takes the result.

V4-Pro (30 CSA + 31 HCA layers): 397 -> 245 collectives per prefill step.

`pcp_reindex_ragged` sized its output with a blocking `.item()`, four times
per prefill step (sixteen under PCP+TBO). The builder already computes the
four prefill indptrs in numpy; it now keeps them on the metadata
(`paged_prefill_indptr_cpu`) and each rank's local indptr is computed on the
host (`pcp_local_indptr`), in both the full-batch and the per-request-group
paths.

`pcp_round_robin_split` returns unit strides: `.contiguous()` leaves a
one-row shard at row stride pcp_size, which aiter's cached-positions RoPE
rejects.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [PCP] DSpark: project context KV on each rank's own rows

After a PCP prefill the aux hooks hold only this rank's round-robin rows.
`compute_draft_kv` all-gathered the three aux hidden states (~42 KiB a row)
and every rank then projected all rows into window KV, the same work on
every rank. The projection (main_proj + norm, then per stage wqkv_a + norm +
RoPE + fake-quant) works row by row, so project only the local rows at their
own positions, gather the projected KV rows (1 KiB a row a stage, one
grouped collective for all stages), and write them as before.

`DSparkLayer.write_context_kv` is split into `context_kv_rows` and
`write_context_kv_rows`. A draft opts in with `context_kv_by_rows`; only V4
DSpark does, and any other draft keeps gathering the aux states.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [PCP] Grouped gather: fall back off aiter's 2/4/8 ranks; check row counts

aiter's custom all-reduce, which `all_gatherv` tries first, runs at 6
ranks, but its all-gatherv kernel exists for 2, 4 and 8 only and throws
otherwise. The attention-side gathers went through torch.distributed before
the grouped gather, so PCP 6 worked; take one tensor at a time there again.

Also assert that the grouped inputs share a row count (a mismatch threw on
the custom path but passed on PyNCCL), and fix two review nits.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* fix(config): key the compile cache on the KV cache dtype

The DSpark drafter branches on the KV cache dtype while tracing
(`dspark_fp8_planned`), but `Config.compute_hash` left it out -- the known
limitation #2566 deferred. A DSV4-Pro DSpark run with `--kv-cache-dtype
bf16` after an fp8 one in the same container hashed to the same directory,
loaded the fp8 drafter graph and died in warmup on every rank
(`IndexError: list index out of range` on the split graph's outputs).

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [PCP] TBO: hold comm-stream gather outputs until the compute stream reads them

Under TBO a PCP gather runs on the comm stream, so its output is allocated
there, while the compute stream reads it. When the forward frees it, the
caching allocator hands the memory straight back to the comm stream, and the
comm stream waits only on its own ubatch's compute: the other ubatch's next
collective can overwrite it before this ubatch's kernels have read it.

On main this corrupts the gathered extend K. DSV4-Pro, pcp8 + `--enable-tbo`,
gsm8k (200 q): main 0.69 / 0.675 on two nodes. With only the extend-K gathers
on the main code path: 0.71 (K alone: 0.70, positions alone: 0.975); the same
plus `record_stream` on the gathered tensors: 0.965. The grouped gathers of
this branch have the same shape, and score 0.96 only by timing.

`tbo_mark_used_on_compute` records the compute stream on such tensors after
`tbo_switch_to_compute_sync`, for the attention-side gathers (extend K and
positions, the compressor inputs) and FusedMoE's PCP routed-rows gather and
reduce-scatter. The DP and mori TBO paths have the same shape and are left
alone here.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [PCP] TBO: run the PCP comm phases through tbo_on_comm

The previous commit marked the comm-stream outputs by hand at four call
sites, and nothing would notice one going missing: this branch scores 0.96
under TBO with or without the marks. `tbo_on_comm(fn, *args)` makes the
comm phase one call -- yield, `fn` on the comm stream, switch back, hold
every tensor it returns -- so a phase cannot skip the hold, and a test
fails if V4 attention or `FusedMoE._run_experts` writes a phase out by hand.

`tbo_mark_used_on_compute` now takes the compute stream from the TBO
context instead of the current stream, so it no longer depends on being
called after the switch back. `pcp_aux_rows` documents that it describes the
base layer-hook capture; EAGLE3 strips aux off the target's output instead.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [PCP] TBO: hold every comm-stream output; one wire format for grouped gathers

Review follow-ups on #2789:
- tbo_all_reduce and FusedMoE's DP gather / reduce-scatter run through
  tbo_on_comm, like the PCP comm phases, so their comm-stream outputs are
  held for the compute stream; the hold walks nested lists and tuples.
  Mori is unchanged: it returns views of its own per-ubatch buffers.
- Under a graph the V4 compressors read their PCP-gathered inputs on side
  streams; hold them for those streams.
- gather_rows moves to pcp_utils and carries one-byte dtypes as uint8 and
  the rest as is (aiter's all_gatherv copies bytes; only its PyNCCL
  fallback lacks fp8 / e8m0). MoE's DP, PCP and comm-fused gathers and the
  PCP grouped gather share it.
- The allocator-reuse positive control skips under expandable_segments.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* test(tbo): stub aiter's communication_op in the TP all-reduce test

tbo_all_reduce imports it ahead of the TBO branch, and the non-GPU CI's
aiter has no aiter.dist.communication_op.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* [PCP] Grouped gather: drop the 6-rank special case, rely on aiter

ROCm/aiter#7149 makes custom_all_gatherv decline group sizes it has no
kernel for, so all_gatherv falls back to NCCL there. The grouped gather
now takes the one-collective path at every PCP size, 6 included.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* test(h2d): give the PCP reindex test the host prefill indptr

_apply_pcp_reindex now derives each rank's indptr from the host copy the
builder publishes (paged_prefill_indptr_cpu); the test builds its metadata
by hand, so it sets that copy beside kv_indptr_extend.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* test(h2d): bring the V4 indexer publication GPU test up to date

The file failed 20 of 22 cases on main with RUN_H2D_GPU_TESTS=1, all from
fixtures that fell behind the code:
- set_pcp patched pcp_round_robin_query_indices (removed in #2688); the
  builder reads get_pcp_rank.
- make_runner lacked forward_vars["batch_info"], config.max_num_seqs and
  the builder's csa_layers, max_model_len_idx, _local_heads and
  index_logits_workspace.
- The padded decode case modelled the bucket width through
  UBatchWrapper._decode_ub_running_bs; since #2692 the split comes from
  _prepare_ubatch_decode's split_bs, so the test passes the bucket.
- prepare_prefill was called with a total_tokens_num the fake batch lacks.

22/22 pass on this branch and on its merge base.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>

* DSV4 PCP: assert host and GPU paged-prefill indptrs agree in length

Both PCP reindex paths (rank and PCP+TBO group) compute local offsets from
the host copy and reindex the GPU copy; a length mismatch would silently
reindex against a different query set. Clarify that after either reindex
both copies describe the same rank- or group-local queries.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* DSV4 PCP: stage only this rank's paged-prefill rows on main's stage/finish split

Port the per-rank paged-prefill build onto main's stage_prefill /
finish_prefill structure (#3136):
- Under PCP, stage_prefill stages this rank's own rows (pcp_split) and
  finish_prefill reindexes them; pad query segments get length 0 and the
  per-step indptr/indices fill and reindex helpers are gone.
- Under PCP+TBO each group stages and finishes its own ub{i}_ inputs
  (_stage_pcp_group / _finish_pcp_group) with group-rebased cu_seqlens_q,
  block_tables and replay ranges.
- _pcp_split_rows takes scheduled and running token counts separately.
- Move shared comm helpers into atom/distributed/comm_utils.py.
- Tests: rank segments with running > scheduled, PP relay _aux_blocks in
  the DSpark drafter stubs.

gsm8k 5-shot 200q, V4-Pro -tp 1 -pcp 8: 0.965, +TBO prefill 0.970,
DSpark k=5 0.975 (acceptance 63.76%).

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* Drop the duplicate kv_cache_dtype compile-hash factor left by the main merge

main's #3072 keys the compile cache on kv_cache_dtype as this branch's
222feeb did; the merge kept both, repeating the keyword in two test
fixtures (SyntaxError at collection) and the hash factor in Config.
Keep main's version.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(spec_decode): check target_pcp_split before PCP world size in pcp_aux_rows

Non-PCP steps no longer query the PCP group, which is a MagicMock under the
aiter stub and broke test_deepseek_v41_mono_hi_served_step in CI.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* fix(v4 attn): make _apply_pcp_reindex take cu_q / block_tables explicitly

The 1110 port defaulted cu_q_per_seq_gpu and block_tables_gpu to the
whole batch's, so a PCP+TBO group caller that forgot them would build
indices from the wrong rows without an error. Make both keyword-only
and required; the whole-batch caller passes its own rows. Also note in
pcp_aux_rows that target_pcp_split implies PCP is enabled.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* test(comm-fused-moe): ids travel as int32, drop the no-op view

`gather_rows` passes int32 through unchanged since it moved to
`comm_utils`; the float-carrier comment and its `.view` were stale.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

* dspark(v4.1): drop the unreachable PCP branch from write_context_kv

V4.1 refuses context parallel at startup, so the proposer never passes it
`pcp_num_tokens`. Restore main's signature, drop its split test, and keep
it out of the override scan.

Co-Authored-By: Claude Opus 5.5 <[email protected]>

---------

Co-authored-by: Claude Opus 5.5 (1M context) <[email protected]>
ganyi1996ppo added a commit that referenced this pull request Nov 15, 2026
Main landed the MXFP4 index cache (#2962, #3104: IndexScoreBuffers, index_scorer,
FP4 FlyDSL scorers), the padded-batch sparse decode metadata (#2992) and the TBO
metadata refactor (#3136) in the files this PR rewrites. Both intents are kept:
an fp8 index cache scores through the FlyDSL scorers on this PR's persistent
work map (index_score_work_map, built over the padded batch like main's
index_scorer); an fp4 cache takes main's MXFP4 path unchanged; bf16 stays refused.

- index_topk: main's flydsl_ops() / _small_k_selector() replace _flydsl(name),
  _topk_small_k() and the guarded score_prefill_flydsl import (direct attribute
  access on aiter.ops.flydsl, which re-exports minimax_m3_index_score_prefill_flydsl);
  the Triton decode scorer stays deleted; the Triton prefill scorer is main's
  _triton_prefill_score (with its gfx1250 launch config), the tests' reference.
- aiter_attention: main's builder with this PR's fp8 work-map buffers re-applied
  (step and per-ubatch, capacity-sized); bf16 refusal moves into _index_cache_spec.
- tests: the refusal and deferral tests follow the renamed seams; main's
  "bf16/fp8 need no FlyDSL" test now says fp8 does.

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants