Skip to content

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

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

[TRTLLM-12807][feat] Wrap CuteDSL MLA decode as FMHA lib#15333
yuxianq wants to merge 4 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.

haow-nv and others added 4 commits June 19, 2026 14:54
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>
…fp8 scale

Normalize the per-layer paged-KV pool view for the v1 KVCacheManager
(interleaved single-pool layout) to a packed combined-slot view and fold
the layer offset into the page table, so the CuTe DSL paged TMA addresses
the correct layer's memory. No-op for the v2 manager.

Cache the static fp8 dequant scales on the per-layer backend instance and
read them eagerly during warmup, avoiding an illegal .item() device->host
sync under CUDA graph capture.

Add a long decode-only test that crosses paged-KV block boundaries
mid-decode (short prompt, 64 steps), parametrized over v1/v2 KV cache
managers, reproducing the DeepSeek-V3 E2E degeneration path.

Signed-off-by: haow <haow@nvidia.com>
Signed-off-by: Yuxian Qiu <142763828+yuxianq@users.noreply.github.com>
@yuxianq
yuxianq force-pushed the feat/trtllm-12807-mla-decode-fmha-lib branch from 4aba0ef to b893d83 Compare June 19, 2026 16:18
@yuxianq

yuxianq commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator Author

This PR's commit has been cherry-picked to target branch in #15138, close it

@yuxianq yuxianq closed this Jun 24, 2026
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