[TRTLLM-13968][fix] Enable MiniMax M3 piecewise CUDA graphs - #15923
Conversation
31496ff to
c333655
Compare
📝 WalkthroughWalkthroughAdds an optional preallocated output tensor parameter threaded through MiniMax-M3 sparse attention functions, runtime backend, and dense/sparse attention cores, with a compiled custom-op boundary for the dense path. Also adds tracking and cleanup of piecewise CUDA graph runners in the torch.compile backend, invoked from model engine cleanup. ChangesMiniMax-M3 output tensor plumbing
Piecewise CUDA graph runner tracking and cleanup
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant RuntimeBackend as MiniMaxM3SparseRuntimeBackend
participant Decode as minimax_m3_sparse_decode/prefill
participant Masked as _sparse_gqa_masked
Caller->>RuntimeBackend: forward(forward_args, output, kwargs)
RuntimeBackend->>RuntimeBackend: merge forward_args/kwargs, resolve output
RuntimeBackend->>Decode: forward_sparse(output=resolved_output)
Decode->>Masked: _sparse_gqa_masked(output=resolved_output)
Masked-->>Decode: writes result into output tensor
sequenceDiagram
participant ModelEngine as PyTorchModelEngine
participant Backend
participant Runner as PiecewiseRunner
ModelEngine->>Backend: clear_piecewise_cuda_graphs()
Backend->>Runner: clear_cuda_graphs() (for each tracked runner)
Runner-->>Backend: resets captured graphs and cached state
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
|
/bot run --disable-fail-fast |
|
PR_Github #57464 [ run ] triggered by Bot. Commit: |
|
PR_Github #57464 [ run ] completed with state
|
f7ee59f to
3e5569f
Compare
|
/bot run --disable-fail-fast |
|
PR_Github #57706 [ run ] triggered by Bot. Commit: |
Wrap the MiniMax M3 metadata- and cache-dependent attention core in an inplace custom op so torch.compile can split it out of piecewise CUDA graphs. Keep QKV/index projections, QK normalization, RoPE, and the output projection visible to the compiled graph. Write dense and sparse attention results into the custom-op output buffer. Preserve FP32 sparse GQA accumulation until the final copy/cast, and expose the output buffer through MiniMaxM3SparseRuntimeBackend.forward. Register attention boundaries and mutation metadata through optional TRT-LLM op lookup, matching the latest GDN registration pattern from PR NVIDIA#15594. This avoids depending on model-specific custom ops being imported when compilation utilities initialize. Track piecewise runners owned by the compile backend and reset their CUDA graphs, captured addresses, outputs, and warmup state when phase-1 KV-cache estimation is released. Phase 2 then recaptures against the final allocations instead of replaying stale graph pointers. Add an 8-GPU MiniMax-M3-MXFP8 torch.compile E2E variant covering TP8/EP8, attention DP, TRTLLM MoE, padding CUDA graphs, multi-stream piecewise capture, and phase-2 recapture. Signed-off-by: Jin Li <59594262+liji-nv@users.noreply.github.com>
Resetting the last piecewise CUDA graph drops the caching allocator private pool use count to zero, but the runner still retains the opaque pool ID. Reusing that ID during phase-2 recapture can hit the allocator use_count assertion when a live allocation keeps the released pool in the allocator table. After clearing all captures, allocate one fresh pool handle for each previous pool and update every runner in that group. This preserves pool sharing across partitions from the same compiled graph while avoiding reuse of released pool IDs. Signed-off-by: Jin Li <59594262+liji-nv@users.noreply.github.com>
Signed-off-by: Jin Li <59594262+liji-nv@users.noreply.github.com>
Signed-off-by: Jin Li <59594262+liji-nv@users.noreply.github.com>
68ebcbe to
2786771
Compare
|
PR_Github #57755 [ run ] triggered by Bot. Commit: |
|
PR_Github #57706 [ run ] completed with state |
|
/bot run --disable-fail-fast |
|
PR_Github #57763 [ run ] triggered by Bot. Commit: |
|
PR_Github #57755 [ run ] completed with state |
|
PR_Github #57763 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #57831 [ run ] triggered by Bot. Commit: |
|
PR_Github #57831 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
PR_Github #57859 [ run ] triggered by Bot. Commit: |
|
@NVIDIA/trt-llm-qa @NVIDIA/trt-llm-qa-function @NVIDIA/trt-llm-torch-graph-compiler |
|
PR_Github #57859 [ run ] completed with state
|
|
/bot run --disable-fail-fast |
|
Need to waive one AutoDeploy test first: #16023 |
|
PR_Github #57880 [ run ] triggered by Bot. Commit: |
|
/bot run --disable-fail-fast |
|
PR_Github #57890 [ run ] triggered by Bot. Commit: |
|
PR_Github #57880 [ run ] completed with state |
|
PR_Github #57890 [ run ] completed with state |
…5809) Squashed cherry-pick of NVIDIA/TensorRT-LLM PR NVIDIA#15809, combining: - [None][feat] Integrate M3 sparse attention kernels form MSA - [None][fix] Fix parallel config of Minimax M3 MXFP8 test - [TRTLLM-14019][feat] Support MSA kernel with enable cuda graph - [None][fix] Fix M3 attention semantic issue Conflicts with the already-integrated PR NVIDIA#15923 were resolved as follows: - requirements.txt: keep flashinfer-python==0.6.14 (main) and add the fmha_sm100 (MSA) dependency. - modeling_minimaxm3.py: graft the _msa_geometry publishing block onto the current _sparse_attention_core (which returns self.attn.forward(..., output=output, ...)). - llm_function_core.txt: keep the MiniMax M3 piecewise/nvfp4 entries. Signed-off-by: Balaram Buddharaju <169953907+brb-nv@users.noreply.github.com>
…5809) Squashed cherry-pick of NVIDIA/TensorRT-LLM PR NVIDIA#15809, combining: - [None][feat] Integrate M3 sparse attention kernels form MSA - [None][fix] Fix parallel config of Minimax M3 MXFP8 test - [TRTLLM-14019][feat] Support MSA kernel with enable cuda graph - [None][fix] Fix M3 attention semantic issue Conflicts with the already-integrated PR NVIDIA#15923 were resolved as follows: - requirements.txt: keep flashinfer-python==0.6.14 (main) and add the fmha_sm100 (MSA) dependency. - modeling_minimaxm3.py: graft the _msa_geometry publishing block onto the current _sparse_attention_core (which returns self.attn.forward(..., output=output, ...)). - llm_function_core.txt: keep the MiniMax M3 piecewise/nvfp4 entries. Signed-off-by: Balaram Buddharaju <169953907+brb-nv@users.noreply.github.com>
…5923) Signed-off-by: Jin Li <59594262+liji-nv@users.noreply.github.com>
Wrap the MiniMax M3 metadata- and cache-dependent attention core in an inplace custom op so torch.compile can split it out of piecewise CUDA graphs. Keep QKV/index projections, QK normalization, RoPE, and the output projection visible to the compiled graph.
Write dense and sparse attention results into the custom-op output buffer. Preserve FP32 sparse GQA accumulation until the final copy/cast, and expose the output buffer through MiniMaxM3SparseRuntimeBackend.forward.
Register attention boundaries and mutation metadata through optional TRT-LLM op lookup, matching the latest GDN registration pattern from PR #15594. This avoids depending on model-specific custom ops being imported when compilation utilities initialize.
Track piecewise runners owned by the compile backend and reset their CUDA graphs, captured addresses, outputs, and warmup state when phase-1 KV-cache estimation is released. Phase 2 then recaptures against the final allocations instead of replaying stale graph pointers.
Add an 8-GPU MiniMax-M3-MXFP8 torch.compile E2E variant covering TP8/EP8, attention DP, TRTLLM MoE, padding CUDA graphs, multi-stream piecewise capture, and phase-2 recapture.
Summary by CodeRabbit
New Features
Bug Fixes
Description
Test Coverage
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-compatibleorapi-breaking. Forapi-breaking, includeBREAKINGin 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.