Skip to content

[None][perf] Helix CP: MLA V up-projection before the all-to-all, O(prompt/cp) prompt partition, FIFO all-to-all sender fence, Helix test harness fix - #20939

Merged
longlee0622 merged 5 commits into
NVIDIA:mainfrom
longlee0622:user/jonasl/k3-pr-helix
Oct 28, 2026
Merged

longlee0622 merged 5 commits into
NVIDIA:mainfrom
longlee0622:user/jonasl/k3-pr-helix

Conversation

@longlee0622

@longlee0622 longlee0622 commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Dev Engineer Review

  • Request.get_input_token_ids_array() exposes an owning NumPy array of prompt token IDs. partition_context_for_helix now accepts that array and uses NumPy indexing instead of padded Torch tensors.
  • Helix MLA can apply the BF16 V up-projection before the context-parallel exchange. This reduces exchanged data, changes floating-point operation order, and retains the post-exchange path as a fallback.
  • The FIFO kernel adds asynchronous shared-memory fences around buffer reuse and receiver reads. The Helix test harness runs worker checks inside an NCCL window-tensor scope.
  • Review severity counts are unavailable. The PR description reports 58 passing tests, but also reports a failed downstream L0 merge-request pipeline. These results were not independently verified here.

QA Engineer Review

  • Modified tests cover MLA V-weight preparation and projection, communication modes, CUDA-graph overlap, FIFO results for dense and zero-KV-row inputs, prompt partitioning, request-array ownership, and test-fixture setup.
  • The changed test filenames were not found in the inspected tests/integration/test_lists/test-db/ or tests/integration/test_lists/qa/ files. The supplied evidence does not establish whether these unit tests require list entries.
  • Coverage verdict: needs follow-up. The reported test run is not independently verified, and the PR description reports a downstream L0 pipeline failure.

Per-File QA Perspective

  • cpp/tensorrt_llm/kernels/helixAllToAll.cu — Verify that the new fences correctly order shared-memory writes, buffer reuse, and receiver reads during asynchronous transfers.
  • cpp/tensorrt_llm/nanobind/executor/request.cpp — Verify that get_input_token_ids_array() returns a contiguous copy that remains valid after the request is deleted.
  • tensorrt_llm/_torch/attention/attention.py — The docstring clarifies the dimension used when MLA applies V projection before exchange. No runtime change is reported.
  • tensorrt_llm/_torch/attention/mla.py — Verify the BF16 V-up path, supported weight layouts, fallback behavior, and numerical accuracy after the projection moves before exchange.
  • tensorrt_llm/_torch/pyexecutor/request_utils.py — Verify NumPy-based block selection, padding lengths, and empty-rank behavior. The function input type changed to np.ndarray.
  • tests/unittest/_torch/attention/multi_gpu/helix_test_utils.py — The utility runs Helix worker functions inside an NCCL window-tensor scope. Its filename was not found in the inspected CI or manual-QA lists.
  • tests/unittest/_torch/attention/multi_gpu/test_mla_helix.py — Tests cover V-weight preparation, projection/combine behavior, communication modes, and CUDA-graph overlap. The filename was not found in the inspected CI or manual-QA lists.
  • tests/unittest/_torch/attention/test_helix_alltoall_fifo.py — The parameterized test checks FIFO results for dense and zero-KV-row inputs. The filename was not found in the inspected CI or manual-QA lists.
  • tests/unittest/_torch/executor/test_request_utils.py — Tests cover prompt partitioning and request-array values and ownership. The filename was not found in the inspected CI or manual-QA lists.
  • tests/unittest/_torch/attention/test_mla_locality_domain.py — The fixture now initializes mla.mapping; verify the locality-domain test setup with this mapping.
  • tests/unittest/_torch/executor/test_model_loader_mx.py — The MLA idempotence test now initializes Mapping before weight transformation; verify this setup against the updated transform lifecycle.

Description

This PR is part of a series that lands Kimi-K3 optimizations, re-implemented for production use (wave 1 of 8 PRs). It applies on main by itself and does not depend on the other wave-1 PRs (serving runtime, spec decode, KDA/DWDP, low-M GEMM).

It has 4 commits. Each commit message gives the full rationale, measurements and tests. None of the changes adds a switch: all of them are always on when Helix CP is used.

  1. [fix] Helix FIFO all-to-all: fence the sender's shared memory before the next bulk load. The sender writes each entry's shared memory with generic-proxy stores (zero-KV sanitize, protoPack). It then loads the next entry into the same buffer with cp.async.bulk, which goes through the async proxy, and only __syncwarp() sat between the two. This adds fence.proxy.async.shared::cta (fence_view_async_shared) on the sender side. The receiver side already has this fence. Without the fence, Kimi-K3 GSM8K with Helix CP16 and the V-up path below dropped to 0.9075, vs 0.9613 with it. This affects all SM90+ paths of the shared kernel and has no measurable cost.

  2. [perf] Helix CP: partition a new request's prompt in O(prompt / cp_size). partition_context_for_helix now gathers only the positions of the blocks this rank owns, from an int32 numpy prompt. The prompt comes from a new nanobind accessor, Request.get_input_token_ids_array(), which makes one memcpy instead of building one Python int per token. Outputs are identical. On the GB300 host, merge_helix_requests went from 12.6 ms to 0.55 ms at 131k tokens, and from 91 ms to 3.9 ms at 996k tokens.

  3. [perf] Helix MLA: apply the V up-projection before the CP all-to-all, for all MLA models. The CP combine is a per-head weighted sum, so it commutes with the per-head V projection. Each rank now projects its partial outputs to v_head_dim (128) before the exchange, instead of exchanging kv_lora_rank (512) values per head. The all-to-all and the combine therefore move 4x less data, and the post-combine V BMM is skipped. MLA builds the BF16 V weight in transform_weights from kv_b_proj:

    • BF16 kv_b_proj: a view, with no extra memory.
    • FP8 block-scale kv_b_proj: one dequantized copy, num_heads_tp * (1 - 1/cp_size) * 128 KiB net per layer and rank on SM100f. Examples: DeepSeek-V3 tp1 at cp2 / cp4 / cp8 needs 488 / 732 / 854 MiB per rank, and DeepSeek-V3-Lite FP8 at tp2 cp2 needs 30 MiB.

    Numerics: the combine and the V projection are reassociated, so results are not bit-exact. Measurements:

    • GB300 K3 moves about 88 MB less per layer and rank at 896 decode tokens.
    • Small-CP micro benchmark (GB300 job 1389995), new time / old time per layer at 1–256 tokens:
      • cp2, 16 heads: 0.71–0.93
      • cp4, 16 heads: 0.72–1.01
      • cp2, 128 heads: 0.63–0.85
      • cp4, 128 heads: 0.52–0.83

    This change needs the sender fence from commit 1 to stay accurate.

  4. [test] Helix test harness: run Helix MLA checks inside an NCCL window-tensor scope. helix_test_utils.run_helix_test ran each rank's check with no NCCL window-tensor scope. With main's default TLLM_NCCL_WINDOW_LIFECYCLE_ASSERT=1, every test_mla_helix_distributed case (an existing test) and the new test_mla_helix_v_up_before_alltoall aborted in the MPI workers after computing correct results (NCCL window lease ... was released by its tensor destructor), and the pytest process then hung in executor.shutdown. The worker now runs the check inside discard_nccl_window_tensor_outputs, the scope the model engine opens around every forward. This affects test_mha_helix.py too, which uses the same harness. Test-only change.

Accuracy on a non-Kimi MLA model. DeepSeek-V3-Lite TestDeepSeekV3Lite::test_auto_dtype_with_helix (registered in l0_dgx_b200) was run on 8x B200, base vs this change. All 4 parametrizations pass on both.

Metric base this change threshold
MMLU 71.39–71.44 71.00–71.25 69.583
GSM8K 64.14–64.48 64.18–64.94 61.537

Whole-series end-to-end results. These numbers are for the full series of 8 PRs, not for this PR alone. Per-PR attribution is in the commit messages.

Setup: GB300 NVL72 (NSC LHR), Kimi-K3 NVFP4 with the DSpark drafter, AgentX agentic traces, the same dev image and autotuner state on both sides. Base is main f298722, compared with main + all 8 PRs. NSC jobs: base 362316–362321, series 361375–361379.

Metric main main + series
ctx_only DWDP16 conc128, req/s 8.25 10.20 (+23.6%)
ctx_only prefix reuse 94.51% 95.62%
ctx_only TTFT p50 16.6 s 14.2 s
gen_only helix8 b8 MTP7, device step p50 29.23 ms 25.79 ms (−11.8%)
gen_only dep16 b16 MTP5, device step p50 80.45 ms 77.48 ms (−3.7%)
GSM8K helix8 / dep16 (5-shot, MTP, forced acceptance off) 96.44 / 96.51 96.29 / 96.59
MTP acceptance length helix8 / dep16 3.635 / 3.389 3.648 / 3.386

Test Coverage

New and changed tests, with where CI picks them up (tests/integration/test_lists/test-db):

Test file Change CI list
tests/unittest/_torch/attention/test_helix_alltoall_fifo.py also runs with a zero-KV mask, so sender stores come before every next bulk load unittest/_torch/attention (l0_b200, l0_b300, l0_h100, l0_cpu, l0_gb300_multi_gpus)
tests/unittest/_torch/executor/test_request_utils.py test_partition_context_for_helix_matches_block_layout, test_request_input_token_ids_array_matches_prompt unittest/_torch/executor (l0_cpu, l0_h100, l0_b300, l0_dgx_b300, l0_gb300_multi_gpus)
tests/unittest/_torch/attention/multi_gpu/helix_test_utils.py run_helix_test runs each rank inside an NCCL window-tensor scope used by test_mla_helix.py / test_mha_helix.py (unittest/_torch/attention directory entry)
tests/unittest/_torch/attention/multi_gpu/test_mla_helix.py test_helix_v_up_commutes_with_combine (1 GPU), test_mla_helix_v_up_before_alltoall (2 GPUs; nccl, fifo_v1, fifo_v2), test_helix_v_up_weight_*, test_helix_alltoall_after_v_up_gemm_in_cuda_graph (sender-fence regression, bitwise over 20 graph replays) no explicit entry; collected only through the unittest/_torch/attention directory entry of the post-merge l0_gb300_multi_gpus stage
tests/integration/defs/accuracy/test_disaggregated_serving.py::TestDeepSeekV3Lite::test_auto_dtype_with_helix unchanged; results above l0_dgx_b200

Results: pytest unittest/_torch/attention/multi_gpu/test_mla_helix.py -vv --timeout=1800, run from tests/ in one pytest process as the CI directory collection runs it, on one GB300 node (NSC LHR):

  • this PR alone (main f298722 image with this PR's Python files and tests laid over it; the C++ of commits 1 and 2 is not in that image), job 366740: 58 passed, exit 0, no hang (26 min).
  • the full series image, job 366741: 58 passed, exit 0, no hang (26 min).

Before the harness fix, the same file aborted in the MPI workers at the first test_mla_helix_distributed[nccl-...] case and hung, on main's image with main's sources too (jobs 365736, 365761, 365789).

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why. If using CodeRabbit's summary, please make sure it makes sense.

  • PR Follows TRT-LLM CODING GUIDELINES to the best of your knowledge.

  • Test cases are provided for new code paths (see test instructions)

  • If PR introduces API changes, an appropriate PR label is added - either api-compatible or api-breaking. For api-breaking, include BREAKING in the PR title.

  • Any new dependencies have been scanned for license and vulnerabilities

  • CODEOWNERS updated if ownership changes

  • Documentation updated as needed

  • Update tava architecture diagram if there is a significant design change in PR.

  • The reviewers assigned automatically/manually are appropriate for the PR.

  • Please check this after reviewing the above items as appropriate for this PR.

GitHub Bot Help

To see a list of available CI bot commands, please comment /bot help.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 598649a and adf0128.

Files selected for processing: 2
  • tests/unittest/_torch/attention/test_mla_locality_domain.py
  • tests/unittest/_torch/executor/test_model_loader_mx.py

Included review availability: This review used your included allowance. Your plan provides up to 12 included reviews per hour; 11 remain after this review.

Walkthrough

The PR adds an optional Helix context-parallel MLA path that projects V partials before exchange, changes Helix request partitioning to use NumPy token arrays, and adds shared-memory fences around FIFO all-to-all transfers. Tests cover projection, partitioning, and FIFO behavior.

Changes

Helix MLA V projection

Layer / File(s) Summary
Prepare the Helix V-projection weight
tensorrt_llm/_torch/attention/mla.py, tests/unittest/_torch/attention/multi_gpu/test_mla_helix.py, tests/unittest/_torch/attention/test_mla_locality_domain.py, tests/unittest/_torch/executor/test_model_loader_mx.py
MLA prepares the Helix V-projection weight for supported BF16 and FP8 layouts. Tests check weight construction and the unsupported packed-scale case.
Project partials before exchange
tensorrt_llm/_torch/attention/mla.py, tensorrt_llm/_torch/attention/attention.py, tests/unittest/_torch/attention/multi_gpu/helix_test_utils.py, tests/unittest/_torch/attention/multi_gpu/test_mla_helix.py
When enabled, MLA projects partial outputs before the Helix exchange and copies the combined result to the output. Tests compare projection order and exercise distributed exchanges across scenarios and communication modes.

Helix request partitioning

Layer / File(s) Summary
Pass token arrays into Helix partitioning
cpp/tensorrt_llm/nanobind/executor/request.cpp, tensorrt_llm/_torch/pyexecutor/request_utils.py, tests/unittest/_torch/executor/test_request_utils.py
The request binding exposes an owned NumPy array of input token IDs. Request merging passes it to a NumPy-based partitioner, which returns tokens and positions with padding length reported separately. Tests check partition results and array ownership.

FIFO all-to-all shared memory

Layer / File(s) Summary
Fence FIFO shared-memory transfers
cpp/tensorrt_llm/kernels/helixAllToAll.cu, tests/unittest/_torch/attention/test_helix_alltoall_fifo.py
The sender and receiver fence shared-memory operations around S2G transfers. FIFO-v2 tests check exact entries for dense inputs and masked zero-KV rows.

Priority: Normal

Estimated code review effort: 4 (Complex) | ~45 minutes

Change: Refactor

Sequence Diagram(s)

sequenceDiagram
  participant Transform as MLA.transform_weights
  participant Forward as MLA._attn_forward_gen
  participant Exchange as _helix_post_process
  participant Output as output
  Transform->>Forward: prepare the Helix V-projection weight
  Forward->>Forward: project partial outputs when enabled
  Forward->>Exchange: pass projected partials with v_head_dim
  Exchange->>Output: return the combined result
Loading
Merge Risk: Minimal · up to adf01

The reviewed test-only changes introduce no identified merge-blocking risk.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title accurately summarizes the main Helix CP performance, correctness, and test-harness changes. It follows the required [None][type] format and is specific, although it is long.
Description check Passed The description follows the required template and clearly explains the motivation, implementation, test coverage, measured results, and checklist. It distinguishes results for this PR from results for…
Docstring Coverage Passed Docstring coverage is inconclusive: files from earlier reviews still need to be rechecked within the check's analysis limits. Not blocking.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description follows the required template and clearly explains the motivation, implementation, test coverage, measured results, and checklist. It distinguishes results for this PR from results for the full series.

Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Comment @coderabbitai help to get the list of available commands.

@yuxianq

yuxianq commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

@yihwang-nv, could you help to review this PR as trt-llm-torch-attention-devs? Thanks~

Assignment explanation
Componentsmodules/mla (60%); runtime/parallelism (20%); integration/attention-tests (15%); unmapped (4%); modules/attention (1%)
Tagsrepresentation:mla (100%); phase:decode (100%); features:context-parallelism (80%); features:quantization (20%); context:llm (100%)
PR effort8 points — The main change restructures existing MLA computation for performance, alongside a FIFO correctness fix. Reviewing projection/combination equivalence, weight lifetime and dequantization, and asynchronous memory ordering warrants 8 points.
ImportanceImportant — MLA now projects partial outputs before distributed combination, changing numerical ordering and the communication shape. BF16/FP8 weight handling adds ownership and layout requirements, while the sender proxy fence addresses sensitive GPU memory ordering.
Affinity (0–1)0.232 component/tag match; 0.174 after PIC preference
Outstanding points at selection39 → 47 (+8)
Points already reserved on this PR0
Effective weight1
Completed review points (preceding 168 hours)18
Combined points after assignment65
Demand-derived target57.00 points (soft share)
Additional fair share before assignment0.00 points
Share explanationWhole PR / qualification or coverage constraint exceeds a soft share; assignment is allowed.
Selection ruleaffinity with 0.3-share guard
Assignment scope (yihwang-nv)all

Affinity and workload are snapshots at selection, not live counters. Existing reservations on this PR are counted once.

@yuxianq
yuxianq requested review from yihwang-nv and removed request for heyuhhh and yunruis October 24, 2026 10:44

@yihwang-nv yihwang-nv left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM for attention changes

@lori-ren lori-ren left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Runtime part LGTM.

@github-actions

Copy link
Copy Markdown

Automatically added "ci: full pre-merge approved" because this PR has satisfied the required GitHub review approvals. Unresolved review conversations and other required checks remain independent merge requirements.

@longlee0622
longlee0622 force-pushed the user/jonasl/k3-pr-helix branch from 4e0a744 to c7162c8 Compare October 27, 2026 05:42
…efore the next bulk load

The fifo all-to-all sender writes each entry's shared memory with ordinary
stores (zero-KV sanitize, protoPack) and reads it with ordinary loads (the
register S2G copy), then loads the next entry into the same shared memory
with cp.async.bulk, an async-proxy write. Only __syncwarp() separated them,
which orders the generic proxy but not the async proxy, so the bulk load
could race with the previous entry's stores. The receiver side already has
this fence after protoUnpack; add the same fence.proxy.async.shared::cta
(tensorrt_llm::common::fence_view_async_shared) before the sender's
end-of-iteration __syncwarp(). Always on, no measurable cost.

Evidence (reference f372e27): Kimi K3 GSM8K with Helix CP16 and the
V-up-before-all-to-all path dropped to 0.9075 (0.9613 with the fences);
the reference test captured the V-up GEMM and the all-to-all in one CUDA
graph and failed before / passed after the fences at 2 and 4 ranks. The
receiver half of that fix landed in base separately; this is the missing
sender half. Platform: N (shared kernel, all SM90+ paths).

Tests: test_helix_alltoall_fifo.py now also runs with a zero-KV mask, so
the sender's generic shared-memory stores precede every next bulk load
under the same shared-memory pressure kernel; masked rows must arrive as
the no-op contribution and all others bit-exact.

Signed-off-by: Jonas Li <[email protected]>
… cp_size)

Every Helix CP rank turns each fetched request into its LlmRequest with
merge_helix_requests. partition_context_for_helix built an int64 tensor of
the whole prompt, split it into per-block tensors and concatenated the
blocks this rank owns, and the prompt came from Request.input_token_ids,
which builds one Python int per token. That cost grows with the full
prompt on every GEN rank, on the critical path of the step that fetches
the request.

The partition now gathers only the positions of the blocks this rank owns
(it takes the prompt as a numpy array; same round-robin layout; the padding
of the last block is never built), so only this rank's tokens become Python
ints, and merge_helix_requests reads the prompt through a new binding
accessor, Request.get_input_token_ids_array(): an int32 numpy array owning
one memcpy'd copy of the tokens. Outputs are identical. Always on.

Evidence (reference 11ff6c8d18, GB300 host): merge_helix_requests 12.6 ms
-> 0.55 ms at 131k tokens and 91 ms -> 3.9 ms at 996k tokens per request;
Kimi K3 16p2d c500 AgentX steps that fetch a request took +9.8 ms p50.
The reference read the prompt by parsing Request.__getstate__() bytes
(also one memcpy); this uses a proper binding accessor instead.
Platform: N (host side).

Tests: test_request_utils.py adds
test_partition_context_for_helix_matches_block_layout (numpy input vs a
block-by-block reference over prompt lengths, cp sizes and block sizes) and
test_request_input_token_ids_array_matches_prompt; the existing
merge_helix_requests tests cover the merged requests. GB300 (OCI AGA) job
1369036.

Signed-off-by: Jonas Li <[email protected]>
…o-all

Under Helix CP every rank exchanges the per-head kv_lora_rank (512) latent
partial outputs of all heads, combines them, and only then applies the
v_head_dim (128) V up-projection of its head chunk. The CP combine is a
per-head weighted sum of the ranks' partials, so it commutes with the
per-head linear V projection.

Whenever Helix CP is on, MLA builds the BF16 V weight of every tp-local head
itself in transform_weights from kv_b_proj: a view of the V rows of a BF16
kv_b_proj, or one dequantized copy of FP8 block-scale codes (12.6 MB per K3
MLA layer), of which this rank's dequantized V chunk becomes a view. This
applies to every BF16/FP8 MLA model under Helix (DeepSeek-V3 included): every
rank runs the V BMM for its num_heads_tp heads, and where v_b_proj_dequant was
absent the FP8 block-scale V BMM becomes a BF16 BMM of the dequantized weight.
Absorbed generation then projects every head's partial output before the
exchange (_helix_project_v_partials, the existing BF16 BMM helper); the
all-to-all and the combine move 128 instead of 512 values per head (the Helix
post-process works on v_head_dim) and the post-combine V BMM is skipped.
Memory per MLA layer and rank: num_heads_tp * v_head_dim * kv_lora_rank * 2
bytes, none for a BF16 kv_b_proj (a view; a copy under the locality-domain
BF16 partition); for FP8 kv_b_proj on SM100f, where the rank's
v_b_proj_dequant becomes a view of it, num_heads_tp * (1 - 1/cp_size) * 128
KiB net: DeepSeek-V3 (61 layers, 128 heads) at tp1 cp2 / cp4 / cp8 488 / 732 /
854 MiB per rank, DeepSeek-V3-Lite FP8 at tp2 cp2 30 MiB, BF16
DeepSeek-V3-Lite none.
Numerics: reassociation of the combine and the V projection (not bit-exact).

Evidence (reference fbd16e3, TRTLLM_HELIX_V_UP_BEFORE_A2A=1, part of
the reference helix GEN env): GB300 K3 at 896 decode tokens moves ~88 MB
less per layer per rank (helixAllToAll ~150 us + combine ~42 us per
layer, ~4.6 ms per step at batch 128 before). Rubin: part of the Tier-0
bundle, helix16 b1 -6.4% device step as a group (773254); not isolated.
Small CP: GB300 micro benchmark of the reordered ops (fifo_v2, CUDA graph, job
1389995), new / old per layer at 1-256 tokens: cp2 16 heads 0.71-0.93, cp4 16
heads 0.72-1.01, cp2 128 heads 0.63-0.85, cp4 128 heads 0.52-0.83 (batch 1:
cp2 16 heads 8.0 -> 7.3 us, cp2 128 heads 13.6 -> 9.4 us).
Accuracy relies on the Helix FIFO all-to-all sender fence (earlier commit
in this series): GSM8K helix CP16 with V-up 0.9075 without it, 0.9613 with it.
Evidence beyond K3: test_mla_helix.py (generic MLA, GB300 job 1387325); the
DeepSeek-V3-Lite Helix accuracy test of l0_dgx_b200 pre-merge
(8x B200, base vs this change, all four parametrizations pass; MMLU /
GSM8K, thresholds 69.583 / 61.537: pp1tp2cp2 overlap off 71.004 / 64.481 vs
71.394 / 64.481, overlap on 71.248 / 64.177 vs 71.442 / 64.139; pp1dp2cp2
overlap off 71.199 / 64.936 vs 71.418 / 64.481, overlap on 71.028 / 64.708 vs
71.442 / 64.481).
Platform: N.

Tests: test_mla_helix.py test_helix_v_up_commutes_with_combine (one GPU, real
combine kernel, declared tolerance 2e-2), test_mla_helix_v_up_before_alltoall
(2 GPUs, nccl / fifo_v1 / fifo_v2 vs the single-rank reference),
test_helix_v_up_weight_{from_fp8_kv_b, views_bf16_kv_b,
needs_loaded_fp8_scales}, and the sender-fence regression test
test_helix_alltoall_after_v_up_gemm_in_cuda_graph (V-up GEMM + fifo_v2
all-to-all in one CUDA graph, bitwise over 20 replays). GB300 (OCI AGA) job
1368987: test_mla_helix.py 50 passed; job 1390083 (MLA Helix suites).

Signed-off-by: Jonas Li <[email protected]>
…window-tensor scope

run_helix_test runs each rank's check function with no NCCL window-tensor
scope. The NCCL collectives of the check (cp_allgather of the reference
output, the NCCL Helix all-to-all) can return NCCL-window tensors, and with
TLLM_NCCL_WINDOW_LIFECYCLE_ASSERT=1 (the default) a lease released by its
tensor destructor instead of a scope aborts the process. Every
test_mla_helix_distributed / test_mla_helix_v_up_before_alltoall case
therefore aborted in its MPI workers after computing the correct result,
the MPIPoolExecutor future never completed, and executor shutdown blocked
the pytest process.

The worker now calls the check function inside
discard_nccl_window_tensor_outputs, the scope the model engine opens
around every forward (run_in_nccl_window_tensor_scope). The scope is
opened on a one-element CUDA tensor, since it only becomes active with a
CUDA tensor among its inputs. The other users of run_single_rank, which
capture plain CUDA graphs of the FIFO all-to-all, are unchanged.

Signed-off-by: Jonas Li <[email protected]>
@longlee0622
longlee0622 force-pushed the user/jonasl/k3-pr-helix branch from c7162c8 to 598649a Compare October 27, 2026 08:13
@longlee0622
longlee0622 enabled auto-merge (squash) October 27, 2026 08:13
@longlee0622

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80845 [ run ] triggered by Bot. Commit: 598649a Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80845 [ run ] completed with state SUCCESS. Commit: 598649a
/LLM/main/L0_MergeRequest_PR pipeline #66574 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

MLA.transform_weights() now builds the Helix V up-projection weight and
reads self.mapping to check for Helix CP. A real MLA always has a
mapping, but the unit-test stubs created with MLA.__new__ did not, so
transform_weights() raised AttributeError. Give these stubs a default
non-CP Mapping, which matches a real non-Helix MLA.

Signed-off-by: Jonas Li <[email protected]>
@longlee0622
longlee0622 force-pushed the user/jonasl/k3-pr-helix branch from 5fb65a2 to adf0128 Compare October 27, 2026 14:21
@longlee0622

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80901 [ run ] triggered by Bot. Commit: adf0128 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80901 [ run ] completed with state SUCCESS. Commit: adf0128
/LLM/main/L0_MergeRequest_PR pipeline #66627 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@longlee0622

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80982 [ run ] triggered by Bot. Commit: adf0128 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #80982 [ run ] completed with state FAILURE. Commit: adf0128
/LLM/main/L0_MergeRequest_PR pipeline #66702 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@longlee0622

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81018 [ run ] triggered by Bot. Commit: adf0128 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81018 [ run ] completed with state SUCCESS. Commit: adf0128
/LLM/main/L0_MergeRequest_PR pipeline #66734 completed with status: 'UNSTABLE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

Link to invocation

@longlee0622

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81026 [ run ] triggered by Bot. Commit: adf0128 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81026 [ run ] completed with state FAILURE. Commit: adf0128
/LLM/main/L0_MergeRequest_PR pipeline #66741 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@longlee0622

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81049 [ run ] triggered by Bot. Commit: adf0128 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81049 [ run ] completed with state FAILURE. Commit: adf0128
/LLM/main/L0_MergeRequest_PR pipeline #66763 completed with status: 'FAILURE'

CI Report

⚠️ Action Required:

  • Please check the failed tests and fix your PR
  • If you cannot view the failures, ask the CI triggerer to share details
  • Once fixed, request an NVIDIA team member to trigger CI again

CI Agent Failure Analysis

Link to invocation

@longlee0622

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81092 [ run ] triggered by Bot. Commit: adf0128 Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #81092 [ run ] completed with state SUCCESS. Commit: adf0128
/LLM/main/L0_MergeRequest_PR pipeline #66808 completed with status: 'SUCCESS'

CI Report

Link to invocation

@longlee0622
longlee0622 merged commit b613fbe into NVIDIA:main Oct 28, 2026
10 checks passed
dc3671 added a commit to dc3671/TensorRT-LLM that referenced this pull request Oct 28, 2026
Signed-off-by: Zhenhuan Chen <[email protected]>

NVIDIA#20939: main's Request.get_input_token_ids_array() replaces our input_token_ids_i32 binding.
NVIDIA#20597: the spec worker takes mapping_for_full_rows() plus our key_exchange.
NVIDIA#21132: the shared eager GDN output buffer is allocated after the fused-verify early returns.
aleozlx pushed a commit to flashinfer-ai/flashinfer that referenced this pull request Nov 16, 2026
… fence the Helix sender before refilling shared memory (#9379)

<!-- .github/pull_request_template.md -->

## 📌 Description

Two fixes to the TRT-LLM-derived communication kernels, from upstream
TensorRT-LLM commits FlashInfer's copies predate.

- **Lamport clear size kept in elements of the writer's dtype**
([NVIDIA/TensorRT-LLM#21283](NVIDIA/TensorRT-LLM#21283)).
`LamportComm` in `trtllm_allreduce_fusion.cuh` and
`trtllm_moe_allreduce_fusion.cuh` recorded `params.size * NRanks`
elements for the next kernel to clear, and that kernel divided by its
own `VEC_SIZE`. Every Lamport kernel on a workspace shares the slot. The
Python wrapper refuses a call whose dtype disagrees with the workspace's
`use_fp32_lamport`, so the mismatch needs a lower-level call that
bypasses that check on a workspace created with `use_fp32_lamport=True`:
a bf16 kernel following an fp32 one then cleared half the bytes and read
stale data, and the reverse over-cleared. Within one dtype the old count
was right; the fix makes the slot's unit independent of the writer. The
slot now counts 16-bit units and readers round up to whole 16-byte
stores. Upstream switched the slot to bytes; FlashInfer cannot, because
the cake kernels on the same workspace
(`csrc/cake_trtllm_moe_allreduce_union/`,
`csrc/cake_moe_finalize_allreduce_fusion/`, 36 generated files) write
bf16 / fp16 element counts and read `clear_size / 8`. Two-byte units
keep bf16 / fp16 bitwise as before, stay compatible with cake, and still
fix fp32. The workspace layout is unchanged (`kernel_flag_ptr[4]`,
initialized to 0); its docstring now names the unit (`5da38d8bc`).
- **Lamport clear stores wrote the clearing kernel's own `-0`**
(FlashInfer-side, found in review). A bf16 / fp16 kernel cleared with
`0x8000` pairs, which an fp32 kernel two calls later reads as
`0x80008000`, not fp32 `-0`, and takes as arrived data. The clear now
writes the fp32 `-0` pattern (`0x80000000` per word) whatever the dtype:
fp32 readers see `-0`, bf16 / fp16 readers (trtllm and cake both test
each 16-bit half) see `0x8000` in the high half. Remaining gap, not
touched here: the cake kernels still clear with bf16 `-0` pairs, so cake
followed by an fp32 trtllm kernel on one workspace is still unsafe; no
caller does that today.
- **Helix all-to-all sender refill ordering**
([NVIDIA/TensorRT-LLM#20939](NVIDIA/TensorRT-LLM#20939),
fence part). In `helixAllToAll.cu` the sender's `protoPack` stores and
the register S2G loads go through the generic proxy, and the next
iteration refills the same shared memory with `cp.async.bulk` (async
proxy) without a fence between them. A `fence.proxy.async.shared::cta`
before the `__syncwarp` orders them, matching the receiver side that
#5172 already fenced.

## 🔍 Related Issues


[NVIDIA/TensorRT-LLM#21283](NVIDIA/TensorRT-LLM#21283),
[NVIDIA/TensorRT-LLM#20939](NVIDIA/TensorRT-LLM#20939).

## 🚀 Pull Request Checklist

Thank you for contributing to FlashInfer! Before we review your pull
request, please make sure the following items are complete.

### ✅ Pre-commit Checks

- [x] I have installed `pre-commit` by running `pip install pre-commit`
(or used your preferred method).
- [x] I have installed the hooks with `pre-commit install`.
- [x] I have run the hooks manually with `pre-commit run --all-files`
and fixed any reported issues.

> If you are unsure about how to set up `pre-commit`, see [the
pre-commit documentation](https://pre-commit.com/).

## 🧪 Tests

- [ ] Tests have been added or updated as needed.
- [ ] All tests are passing (`unittest`, etc.).

The existing multi-rank tests
(`tests/comm/test_trtllm_allreduce_fusion*.py`,
`test_trtllm_moe_allreduce_fusion*.py`, `test_dcp_alltoall.py`) cover
the touched kernels; they need 2+ GPUs, which the development node does
not have, so this PR relies on the GitLab multi-GPU lane. Local: the
`trtllm_comm` and DCP all-to-all JIT modules build on the branch (CUDA
13.0 CI container). `trtllm_comm`, `dcp_alltoall` and
`dcp_alltoall_generated` built on B200 in the CUDA 13.0 CI container.

## 🔬 Experimental Track

<!-- Only for PRs submitted under the experimental policy
(CONTRIBUTING.md → "Experimental APIs and Backends").
     Leave this section untouched for normal PRs. -->

- [ ] This PR is **experimental**: it adds or changes code under
`flashinfer/experimental/` and/or an `@flashinfer_experimental_api`.
Tracking issue: #
- [ ] The tracking issue names an owner, the reason for the experimental
path, and a graduation plan with a target release.
- [ ] Core changes are limited to a thin entry point (signature, shared
validation, feature-gate check, backend selection, handoff).
- [ ] Tests live in `tests/experimental/` and were validated on the
intended hardware; a runnable example is included.
- [ ] Nothing is registered in `flashinfer/aot.py`, and no experimental
backend is reachable from `backend="auto"` without
`FLASHINFER_ALLOW_EXPERIMENTAL_AUTO_BACKENDS=1`. (Calling an
`@flashinfer_experimental_api` or naming a backend explicitly is itself
the opt-in and needs no environment variable.)
- [ ] **Test scope declared below.** The experimental CI lane runs
exactly these targets, so keep them as narrow as the change allows.

<!-- Required for experimental PRs. Replace the commented lines below
with your targets.
Do not delete the fence or change its `experimental-tests` tag — the
experimental-track
watcher reads it verbatim to decide which targets to ask CI for. -->

```experimental-tests
# One target per line: a directory or a file. (A pytest ::selector is not
# supported -- the sharding runner cannot consume one.) Must be under
# tests/experimental/ and must exist. Delete these comment lines and add yours, e.g.
#
#   tests/experimental/test_my_backend.py
#   tests/experimental/my_backend/
#
# Declaring the whole tree (tests/experimental/) is allowed but means every
# experimental PR pays for every other feature's tests, in every matrix cell.
```

## Reviewer Notes

Upstream also moved the clear size to a 64-bit slot in a new workspace
word; FlashInfer keeps the existing `int` slot because `clear_size <=
lamport_comm_size`, which the Python side caps at `MAX_COMM_SIZE`. The
bf16-after-fp32 case needs a workspace used with both dtypes, and the
cake interplay a workspace alternating `backend="trtllm"` / `"cake"`
with different inputs; no existing test does either, and same-input A/B
runs pass even when stale data is read. A mixed-dtype / mixed-backend
case would be the regression test if reviewers want one. The GitLab lane
for the latest push includes `test_cake_moe_allreduce_union.py` and
`test_cake_moe_finalize_allreduce.py`.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved synchronization for data transfers on supported GPUs, helping
ensure copied data is available in the correct order.
* Standardized temporary-buffer clearing across data types, with sizes
rounded to the required alignment.
* **Documentation**
  * Clarified how temporary-buffer clear sizes are measured.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants