Repository navigation
[TRTLLM-17122][feat] Support owner-only MLA KV writes for Helix prefill - #21245
zhaoyuanh-nvidia wants to merge 2 commits into
Conversation
9b6f538 to
347e182
Compare
|
/bot run --disable-fail-fast --extra-stage "GB300-4_GPUs-PyTorch-Post-Merge-1,GB300-4_GPUs-PyTorch-Post-Merge-2,GB300-4_GPUs-PyTorch-Post-Merge-3" |
|
PR_Github #81372 [ run ] triggered by Bot. Commit: |
Map global context positions to rank-local Helix KV slots and suppress persistent writes on non-owning ranks while preserving full-prompt attention preparation. Reuse MLA preprocessing and reject unsupported cached context before cache mutation. Prepare fresh Helix context indptrs even when chunked prefill and block reuse are disabled. Cover the runtime factory default as well as ownership, compact allocation, global-prefix RoPE, and prefill-to-decode handoff. Port independently onto main. Reuse the existing parent-directory CI test selection and exclude feature-branch synchronization and ancestry repair. Signed-off-by: Zhaoyuan He <195028209+zhaoyuanh-nvidia@users.noreply.github.com>
347e182 to
3d3c463
Compare
|
/bot run --disable-fail-fast --stage-list "CPU-Generic-x86-1,CPU-Generic-x86-2" |
|
PR_Github #81414 [ run ] triggered by Bot. Commit: |
|
PR_Github #81372 [ run ] completed with state |
|
PR_Github #81414 [ run ] completed with state |
|
/bot run --disable-fail-fast --stage-list "CPU-Generic-x86-1,CPU-Generic-x86-2" |
👎 Promotion blocked, new vulnerability foundVulnerability report
|
|
@farazkh80, could you help to review this PR as trt-llm-torch-attention-devs? Thanks~ Assignment explanation
Affinity and workload are snapshots at selection, not live counters. Existing reservations on this PR are counted once. |
chienchunhung
left a comment
There was a problem hiding this comment.
Overall LGTM; 1 minor finding (please see inline comment). Thanks!
| if ( | ||
| attn_metadata.helix_context_local_slots is not None | ||
| and attn_metadata.num_ctx_cached_tokens > 0 | ||
| ): |
There was a problem hiding this comment.
With Helix MLA and enable_context_mla_with_cached_kv=False, preparation still sets helix_context_local_slots. This guard then reads num_ctx_cached_tokens, which is initialized only when the flag is enabled, causing AttributeError. The new explicit-disable test checks only the forwarded flag. Consider rejecting this combination early or initializing owner-append metadata independently, and test the preparation lifecycle.
PS: The normal engine default enables the flag; I found no production Helix caller using this override.
There was a problem hiding this comment.
Fixed in bfeea23. Helix MLA now rejects explicit enable_context_mla_with_cached_kv=False before metadata allocation, while other configurations retain the override. Added regression coverage for rejection and the default/explicit-enable preparation lifecycle, including reuse across mixed and decode-only batches.
…tests Reject explicitly disabled cached-KV metadata for Helix MLA before backend allocation: owner-only appends need both cached-token counters and append indptr buffers. Preserve the override for other configurations. Exercise default and explicit-enable preparation through fresh mixed, decode-only, and changed fresh batches on the same metadata object. Retain clear/recompute coverage across non-CP transitions and the global-position/page-sensitive RoPE writer oracle. Signed-off-by: Zhaoyuan He <195028209+zhaoyuanh-nvidia@users.noreply.github.com>
0248247 to
bfeea23
Compare
Description
Helix MLA context-parallel ranks process the prompt for attention, but each rank owns only part of the persistent KV cache. Persist only the compressed KV records assigned to the rank's cache pages while preserving the temporary K/V needed for context attention.
Build a batch-local map from global token positions to rank-local cache slots and pass it through an optional MLA RoPE/append input. Negative slots suppress persistent KV and scale writes without skipping temporary Q/K preparation. Existing callers that omit this input retain their behavior.
Preprocess and append dense MLA context once, then reuse the prepared K/V for attention. Initialize fresh Helix MLA indptrs even when block reuse and chunked prefill are disabled, clear stale slot metadata when leaving the context path, and reject unsupported cached context before cache mutation.
Tracks TRTLLM-17122, part of TRTLLM-16624. This ports the owner-only write work from #20921 onto
main, following the phase-dependent MLA heads merged in #20833. Historical-KV gathering, aggregate request admission/cache allocation, and feature-branch ancestry repair remain separate. This PR does not enable aggregate serving by itself.Design: DCP for Aggregated Workloads
Scope and compatibility
sparse_attn_hooksis enabled) retain their existing head layout. This PR does not establish owner-only prefill or context/output-projection compatibility for those sparse Helix paths; these remain follow-up work. The shared metadata initialization change is not sparse Helix enablement.enable_context_mla_with_cached_kv=Falseis rejected for Helix MLA before metadata allocation: owner-only appends require both cached-token counters and append indptr buffers. The default and explicitTrueremain supported, and explicit-disable behavior is preserved for non-Helix MLA and non-MLA configurations.Test Coverage
tests/unittest/_torch/attention/test_helix_context_slots.py: rank-local slot planning across page boundaries, ragged requests, nonzero prefixes, and CP2/4/8/32; stale-slot reset, generation-metadata preservation, and same-object reuse through decode/non-CP transitions back to changed context lengths and prefixes.tests/unittest/_torch/executor/engine/test_metadata.py: factory defaults and explicit overrides; early Helix MLA explicit-disable rejection before backend construction, with ordinary MLA, non-MLA Helix, and non-Helix CP compatibility controls. Default/explicit-enable lifecycle tests run the real metadata constructor andprepare()with CPU storage replacing CUDA allocation/pinning, checking counters, owner slots, and host/device append indptrs across fresh mixed, decode-only, and changed fresh batches on both CP2 ranks.tests/unittest/_torch/attention/test_attention_mla.py: update the metadata double for the existing SM90/99/100 chunked-prefill dispatch regression.tests/unittest/_torch/modeling/test_kimi_k3_mla.py: distinguish FP8-weight and FP8-cache reference tolerances, including their combined quantization error; retain the weight-only error bound.tests/unittest/_torch/attention/multi_gpu/test_mla_helix_context.py: exact owned writes, untouched non-owned cache, compact allocation, mixed prefill/decode, direct handoff, and a nonzero-prefix writer probe. A global-position/page-sensitive quarter-turn RoPE fixture uses an independent signed-swap oracle; it is not full end-to-end position-varying RoPE lifecycle validation.tests/unittest/_torch/attention/multi_gpu/test_mla_helix.py: retain rank-local history in the disaggregated fixture and a separate unsharded FP8-weight/FP8-cache reference control.Existing attention/executor selections in
l0_cpu.ymlcover the CPU tests. Four-GPU B300/GB300 post-merge attention selections cover the distributed matrix: BF16/FP8 weights and KV with TP1/CP2, TP2/CP2, and TP1/CP4. This matrix does not cover FP4 CP and is not executed by ordinary single-GPU CI.Validation
bfeea235: two DCO-signed commits. Changed-file pre-commit, commit hooks, syntax checks, andgit diff --checkpassed. The full-repository hook run passed the other applicable hooks but could not launch mypy because/bin/bashis unavailable in this Windows environment.3d3c463b: native x86/SBSA builds and all 25 intended named CPU cases passed without skips in the targeted CI run. Those results do not validate the current Python guard or added tests and do not establish full required CI success. The explicit-disable fix changes no C++/CUDA sources; current-head native/GPU validation remains pending.PR Checklist
The description explains the motivation, implementation, scope, and validation limits.
Changes include regression coverage and documented existing CI selections.
The native operator input is optional and backward-compatible; no user-facing serving configuration changes are introduced.
No new dependencies or ownership changes are introduced.
The change fits the existing attention architecture; no architecture-diagram update is needed.
Attention, runtime, disaggregation, and model code owners are assigned as reviewers.
Please check this after reviewing the above items as appropriate for this PR.
GitHub Bot Help
To see the available CI bot commands, comment
/bot help.Dev Engineer Review
QA Engineer Review
The tests cover owner-slot planning and metadata lifecycle, Helix MLA cache writes, compact allocation, prefill-to-decode handoff, and FP8 tolerance behavior. The Helix integration tests and new planner and metadata tests do not appear in the searched CI or manual-QA lists.
test_attention_mla.pyappears in three CI lists, but itstest_attention_mlacase is waived inwaives.txt;test_kimi_k3_mla.pyappears inl0_b200.ymlwith a timeout. Coverage verdict: needs follow-up. Confirm CI coverage for the new tests and validate them on the current head.Per-File QA Perspective
cpp/tensorrt_llm/kernels/mlaKernels.cu: Verify owner-local slot routing and negative-slot write suppression in both KV-copy paths. Confirm null-map fallback behavior.cpp/tensorrt_llm/kernels/mlaKernels.h: The append launcher API gains a local-slot pointer. Verify declaration and implementation signatures match callers.cpp/tensorrt_llm/thop/mlaPreprocessOp.cpp: The operator gains an optional slot tensor with type, rank, length, and device checks. Verify omitted-tensor behavior and dtype dispatch.tensorrt_llm/_torch/attention/backends/trtllm.py: Helix context preparation adds a per-token local-slot tensor. Verify ownership mapping and clearing or recomputation when metadata is reused.tensorrt_llm/_torch/attention/mla.py: The Helix path reuses prepared K/V and rejects cached context. Verify rejection leaves cache state unchanged and ordinary MLA behavior remains intact.tensorrt_llm/_torch/pyexecutor/engine/metadata.py: Metadata defaults change for eligible Helix MLA configurations. Verify explicit overrides and behavior outside those configurations.tests/unittest/_torch/attention/multi_gpu/test_mla_helix.py: Clears owner-slot metadata in the disaggregated decode fixture. No matching CI or manual-QA list entry was found.tests/unittest/_torch/attention/multi_gpu/test_mla_helix_context.py: Adds tests for owned prefill, compact caches, FP8 configurations, and context-head layouts. No matching CI or manual-QA list entry was found.tests/unittest/_torch/attention/test_attention_mla.py: Updates the metadata test double. The file appears in three CI lists; thetest_attention_mlacase is waived inwaives.txt.tests/unittest/_torch/attention/test_helix_context_slots.py: Adds CPU tests for slot ownership, reset behavior, and metadata reuse. No matching CI or manual-QA list entry was found.tests/unittest/_torch/executor/engine/test_metadata.py: Adds tests for Helix MLA defaults, explicit disable behavior, and preparation lifecycle. No matching CI or manual-QA list entry was found.tests/unittest/_torch/modeling/test_kimi_k3_mla.py: Adjusts reference tolerances for FP8 weights and KV cache. The file appears inl0_b200.ymlwith a timeout.