Skip to content

[https://nvbugs/6737351][fix] Remove CGA smem-reduction clamp from trtllm-gen FMHA kernel selection - #18945

Open
kris1025 wants to merge 1 commit into
NVIDIA:mainfrom
kris1025:fix-fmha-cga-clamp-b200-perf
Open

[https://nvbugs/6737351][fix] Remove CGA smem-reduction clamp from trtllm-gen FMHA kernel selection#18945
kris1025 wants to merge 1 commit into
NVIDIA:mainfrom
kris1025:fix-fmha-cga-clamp-b200-perf

Conversation

@kris1025

@kris1025 kris1025 commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator

Description

Problem: PR #18518 wrapped every FmhaAutoTuner::selectKernel() call in selectKernelWithCgaSmemReductionLimit(), which clamps FmhaOptions::mMaxNumCtasPerSeqKv from INT_MAX to 16 / max(clusterDimX, 2) (= 8) for any GmemReduction + Static-scheduler request — on all architectures. That request pattern is exactly the trtllm-gen generation (decode) path: xqaDispatcher sets mMultiCtasKvMode = multi_block_mode (→ GmemReduction) and mTileScheduler = Static when multi-block mode is on.

On B200 (SM100) MLA decode this silently changes the tuned kernel selection:

  1. computeNumCtas caps the split-KV CTA count at 8 instead of filling the machine in one wave (numCtasPerSeqKv = min(maxNumCtasPerSeqKv, SM_count / (numCtasX*numCtasY*numCtasZ)); e.g. ~18 splits for 8–9k KV at batch 1 on 148 SMs).
  2. The smaller grid flips selectMlaGenerationKernel's headDimPerCtaV fine-tuning from 256 to 128 (totalNumCtas * 4 <= multiProcessorCount now passes), so the 576-dim QK^T work is duplicated 4× (V-split) instead of 2×.
  3. The one-wave check in enableCgaReduction now succeeds and promotes GmemReductionCgaSmemReduction with far fewer CTAs.

Net effect: decode attention loses most of its split-KV parallelism at low batch. This regresses disagg gen-only DeepSeek-R1 FP4 MTP3 at con1:
disagg-gen_only-b200_deepseek-r1-fp4_8k1k_con1_ctx1_dep4_gen1_tep8_eplb0_mtp3_ccb-NIXL [con1_iter1_isl8192_osl1024].
High-concurrency cases are unaffected because the batch×heads grid dimension already fills the GPU; the ctx/prefill path is unaffected because it uses the persistent scheduler with multiCtasKvMode disabled.

Solution: remove the wrapper (selectKernelWithCgaSmemReductionLimit / limitCgaSmemReductionCtasKv) and restore the direct FmhaAutoTuner::selectKernel() calls at all three sites (checkIfKernelExist, warmupOneKernel, run), returning SM100-family kernel selection to the exact pre-#18518 behavior.

The clamp was introduced to keep a Rubin (SM107) CGA-promotion path legal (computeNumCtas checks numCtasPerSeqKv * clusterDimX <= 16). That constraint belongs in the trtllm-gen autotuner itself (or behind an mSM == kSM_107 gate), not in arch-agnostic host code that overrides tuned SM100 heuristics. Note SM107 is not reachable in current public builds (TLLM_RUBIN_FEATURES is not defined and Sm107a cubins are not archived), so this removal does not change any shipping Rubin behavior.

Test Coverage

  • Existing trtllm-gen FMHA unit tests exercise kernel selection end-to-end: tests/unittest/_torch/attention/test_combined_fmha.py, test_fmha_page_index.py.
  • Perf safeguard: perf/test_perf_sanity.py::test_e2e[disagg-gen_only-b200_deepseek-r1-fp4_8k1k_con1_ctx1_dep4_gen1_tep8_eplb0_mtp3_ccb-NIXL] (the case that regressed) should return to its pre-[None][feat] Enable Rubin (SM107) trtllm-gen FMHA features #18518 baseline.
  • This PR only deletes host-side clamp logic and restores the original call pattern; no new code paths are added.

PR Checklist

Please review the following before submitting your PR:

  • PR description clearly explains what and why.

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

  • Test cases are provided for new code paths (N/A — pure revert of host-side logic to the pre-regression state; covered by existing tests above).

  • No API changes, no new dependencies, no CODEOWNERS changes, no documentation impact.

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

Dev Engineer Review

  • Restores direct FmhaAutoTuner::selectKernel() calls for validation, JIT warmup, and execution.
  • Removes the CGA shared-memory reduction clamp that limited mMaxNumCtasPerSeqKv to 8.
  • Restores SM100 B200 MLA decode split-KV parallelism and avoids unintended promotion to CgaSmemReduction.
  • Verify that Rubin-specific constraints remain enforced in trtllm-gen autotuner logic or are gated for SM107.

QA Engineer Review

No test changes.

Per-File QA Perspective

  • cpp/tensorrt_llm/kernels/trtllmGenKernels/fmha/fmhaKernels.h: Kernel selection no longer applies the shared-memory reduction clamp or post-selection CTA limit. Verify FMHA behavior, kernel tuning, and low-batch B200 MLA decode performance across affected architectures.

@coderabbitai

coderabbitai Bot commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Enterprise

Run ID: 900430f0-b74c-4a9e-b9f3-177337fe4567

📥 Commits

Reviewing files that changed from the base of the PR and between adfc41e and 5287633.

📒 Files selected for processing (1)
  • cpp/tensorrt_llm/kernels/trtllmGenKernels/fmha/fmhaKernels.h

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


Walkthrough

FMHA validation, warmup, and execution now call FmhaAutoTuner::selectKernel() directly. The change removes CGA-specific CTA and shared-memory reduction limits and their related helper functions.

Changes

FMHA kernel selection

Layer / File(s) Summary
Direct autotuner selection
cpp/tensorrt_llm/kernels/trtllmGenKernels/fmha/fmhaKernels.h
Validation, warmup, and execution now use direct autotuner results. The removed helpers no longer apply CGA cluster-dimension limits or emit related warnings.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to 5ed49

FMHA validation, warmup, and execution now select kernels directly through the autotuner, restoring unconstrained CTA selection. No actionable merge-blocking risk is currently identified.

Suggested reviewers: chzblych

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies the NVBugs issue, change type, and primary change: removing the CGA shared-memory reduction clamp from trtllm-gen FMHA kernel selection.
Description check ✅ Passed The description clearly explains the regression, root cause, solution, affected architecture, expected behavior, test coverage, and checklist status. It matches the required sections and is relevant t…
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

@kris1025 kris1025 changed the title [None][fix] Remove CGA smem-reduction clamp from trtllm-gen FMHA kernel selection [https://nvbugs/6737351][fix] Remove CGA smem-reduction clamp from trtllm-gen FMHA kernel selection Sep 9, 2026
…el selection

PR NVIDIA#18518 wrapped every FmhaAutoTuner::selectKernel() call in
selectKernelWithCgaSmemReductionLimit(), which clamps
FmhaOptions::mMaxNumCtasPerSeqKv from INT_MAX to 8 for any
GmemReduction + Static-scheduler request on ALL architectures.
That request pattern is exactly the trtllm-gen generation (decode)
path (xqaDispatcher sets multi_block_mode -> GmemReduction + Static).

On B200 (SM100) MLA decode this changes the tuned kernel selection:
- computeNumCtas caps the split-KV CTA count at 8 instead of filling
  the machine in one wave (e.g. ~18 splits for 8-9k KV at batch 1);
- the smaller grid flips selectMlaGenerationKernel's headDimPerCtaV
  fine-tuning from 256 to 128, duplicating the 576-dim QK^T work 4x
  instead of 2x;
- the one-wave check in enableCgaReduction now succeeds and promotes
  GmemReduction to CgaSmemReduction with far fewer CTAs.

Net effect: decode attention loses most of its split-KV parallelism at
low batch, regressing disagg gen-only DeepSeek-R1 FP4 MTP3 at con1
(disagg-gen_only-b200_deepseek-r1-fp4_8k1k_con1_ctx1_dep4_gen1_tep8_
eplb0_mtp3_ccb-NIXL).

Remove the wrapper and restore the direct selectKernel() calls,
returning SM100-family kernel selection to the pre-PR behavior. The
clamp existed to keep a Rubin promotion path legal; that constraint
belongs in the trtllm-gen autotuner (or an SM107-gated check), not in
arch-agnostic host code.

Signed-off-by: linquanh <linquanh@nvidia.com>
@kris1025
kris1025 force-pushed the fix-fmha-cga-clamp-b200-perf branch from 5287633 to 5ed497f Compare September 9, 2026 07:52
@kris1025

kris1025 commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72371 [ run ] triggered by Bot. Commit: 5ed497f Link to invocation

@kris1025

kris1025 commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --stage-list "DGX_B200-16_GPUs-2_Nodes-PyTorch-Disagg-PerfSanity-CTX1-NODE1-GPU4-GEN1-NODE1-GPU8-Post-Merge"

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72376 [ run ] triggered by Bot. Commit: 5ed497f Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72371 [ run ] completed with state ABORTED. Commit: 5ed497f

Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72376 [ run ] completed with state FAILURE. Commit: 5ed497f
/LLM/main/L0_MergeRequest_PR pipeline #59400 (Partly Tested) 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

@kris1025

kris1025 commented Sep 9, 2026

Copy link
Copy Markdown
Collaborator Author

/bot run --disable-fail-fast

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72397 [ run ] triggered by Bot. Commit: 5ed497f Link to invocation

@tensorrt-cicd

Copy link
Copy Markdown
Collaborator

PR_Github #72397 [ run ] completed with state SUCCESS. Commit: 5ed497f
/LLM/main/L0_MergeRequest_PR pipeline #59418 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

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