Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions include/flashinfer/trtllm/fmha/fmhaKernels.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,13 @@ class TllmGenFmhaKernel {
// Load the kernel.
std::tie(func, kernelMeta) = loadKernel(params, selectKernelParamsCopy);

// Handle the exception where computeCtaAndClusterConfig results in numTokensPerCtaQ == 0.
if (kernelMeta.mGroupsTokensHeadsQ) {
if (kernelMeta.mStepQ < params.mNumHeadsQPerKv) {
continue; // Skip this candidate as it's invalid
}
}
Comment on lines +629 to +634

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

This check is crucial for preventing a division-by-zero error. However, the fix appears to be incomplete. A similar crash can occur earlier in the selectTileSizeQForGqaGeneration function.

The computeCtaAndClusterConfig function is also called on line 591, which is before this loop. If the initial kernel parameters result in kernelMeta.mStepQ < params.mNumHeadsQPerKv, the program will crash at line 591, as the check is not present there.

To fully resolve the issue, a similar check should be added before the call to computeCtaAndClusterConfig on line 591.

Comment on lines +630 to +634

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For improved readability and conciseness, you can combine these nested if statements into a single condition using the logical AND (&&) operator.

      if (kernelMeta.mGroupsTokensHeadsQ && kernelMeta.mStepQ < params.mNumHeadsQPerKv) {
        continue; // Skip this candidate as it's invalid
      }


// Compute the number of CTAs.
computeCtaAndClusterConfig(ctaLaunchParams, params, kernelMeta, selectKernelParamsCopy);

Expand Down