Skip to content

[TRTLLM-12807][feat] Wrap CuteDSL MLA decode as FMHA lib#15333

Draft
yuxianq wants to merge 8 commits into
NVIDIA:mainfrom
yuxianq:feat/trtllm-12807-mla-decode-fmha-lib
Draft

[TRTLLM-12807][feat] Wrap CuteDSL MLA decode as FMHA lib#15333
yuxianq wants to merge 8 commits into
NVIDIA:mainfrom
yuxianq:feat/trtllm-12807-mla-decode-fmha-lib

Conversation

@yuxianq

@yuxianq yuxianq commented Jun 13, 2026

Copy link
Copy Markdown
Collaborator

@coderabbitai summary

Description

Wrap the CuteDSL FP8/FP16 MLA decode kernels as a TRTLLM FMHA library so they participate in the new FMHA library selection path.

This PR:

  • Moves the CuteDSL MLA decode backend into tensorrt_llm/_torch/attention_backend/fmha/.
  • Registers it as cute_dsl_mla in FMHA_LIBS.
  • Keeps fallback behavior available through TLLM_FMHA_LIBS ordering.
  • Restores generation_seq_len_q=[1, 4] coverage by replaying the single-token CuteDSL kernel per intra-step query with adjusted effective KV lengths.
  • Updates the focused MLA decode test and attention developer guide.

Test Coverage

B200:

  • python3 -m pytest -p no:threadleak -q tests/unittest/_torch/attention/test_cute_dsl_mla_decode.py --timeout=600 --tb=short (16 passed)
  • python3 -m pytest -p no:threadleak -q tests/unittest/_torch/attention/test_attention_mla.py --timeout=600 --tb=short (87 passed)

Local:

  • python3 -m py_compile tensorrt_llm/_torch/attention_backend/fmha/cute_dsl.py tests/unittest/_torch/attention/test_cute_dsl_mla_decode.py tensorrt_llm/_torch/custom_ops/cute_dsl_custom_ops.py
  • ruff check --config ruff-legacy.toml tensorrt_llm/_torch/attention_backend/fmha/cute_dsl.py tests/unittest/_torch/attention/test_cute_dsl_mla_decode.py tensorrt_llm/_torch/custom_ops/cute_dsl_custom_ops.py
  • git diff --check

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.

yuxianq and others added 8 commits June 12, 2026 06:22
Signed-off-by: Yuxian Qiu <142763828+yuxianq@users.noreply.github.com>
Signed-off-by: Yuxian Qiu <142763828+yuxianq@users.noreply.github.com>
Signed-off-by: Yuxian Qiu <142763828+yuxianq@users.noreply.github.com>
Signed-off-by: Yuxian Qiu <142763828+yuxianq@users.noreply.github.com>
Signed-off-by: Yuxian Qiu <142763828+yuxianq@users.noreply.github.com>
Add a CuteDSL attention backend that intercepts the MLA decode-only path
and dispatches to Blackwell CuTe DSL kernels (FP8 e4m3 / FP16), falling
back to TrtllmAttention for all other paths.

- attention_backend/cute_dsl.py: CuteDslAttention(TrtllmAttention)
- cute_dsl_kernels/blackwell/attention/mla: decode fp8/fp16 kernels + helpers
- custom_ops: register cute_dsl_mla_decode_{fp8,fp16}_blackwell ops
- utils/__init__: wire up CUTEDSL backend selection
- tests: CUTEDSL coverage in test_attention_mla + dedicated decode test

Signed-off-by: haow <haow@nvidia.com>
…ayer paged-KV, multi-layer test

- attention_backend/cute_dsl.py: feed the scaled quant_q_buffer (not q.to(fp8))
  and fold the fp8 dequant + de-folded log2(e) softmax scale into the bmm1/bmm2
  scales; resolve the per-layer KV pool / page-table for layer_idx>0; gate the
  non-causal fast path off CUSTOM masks and speculative decoding; add a
  once-per-process ENGAGED log (symmetric to the fallback warning) confirming the
  decode kernel actually ran.
- custom_ops/cute_dsl_custom_ops.py: add BF16 to the decode runner and the fp16
  op with dtype dispatch + validation; pass workspace=None for split_kv==1 to
  avoid a zero-sized-buffer global write.
- cute_dsl_kernels/.../mla_decode_fp8.py: allow a widened BF16 attention output.
- cute_dsl_kernels/.../mla_decode_fp16.py: accept BF16 input/output in can_implement.
- tests/.../test_cute_dsl_mla_decode.py: parametrize over num_layers to exercise
  the layer_idx>0 paged-KV path (reproduces the real DeepSeek-V3 E2E case).

Signed-off-by: haow <haow@nvidia.com>
Signed-off-by: Yuxian Qiu <142763828+yuxianq@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants