Fix: Skip invalid GQA tile candidates with stepQ < headsQPerKv.#2383
Fix: Skip invalid GQA tile candidates with stepQ < headsQPerKv.#2383KungYork wants to merge 1 commit intoflashinfer-ai:mainfrom
Conversation
Skip candidates where kernelMeta.mStepQ < params.mNumHeadsQPerKv in GQA tile selection to avoid numTokensPerCtaQ=0, resulting divide-by-zero crash.
Summary of ChangesHello @KungYork, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug in the GQA (Grouped Query Attention) tile selection logic within the FlashInfer library. By introducing a specific validation step, it prevents a potential divide-by-zero crash that could occur when certain kernel metadata conditions lead to an invalid number of tokens per CTA, ensuring more robust and stable operation. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
📝 WalkthroughWalkthroughThe change adds validation guard conditions to skip invalid kernel configurations during candidate selection. Guards check if per-CTA token budgeting conditions are violated when grouping tokens and heads in Q, applied in the main loop and tileSizeQ heuristic selection. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Code Review
This pull request introduces a fix to prevent a divide-by-zero crash in the GQA tile selection logic by skipping invalid kernel candidates. The change correctly addresses the issue within the kernel selection loop.
My review includes a critical comment about a potential remaining crash scenario where the same bug could manifest earlier in the function. I've also included a medium-severity suggestion to simplify the conditional logic for better readability. Please review the detailed comments for more information.
| // 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 | ||
| } | ||
| } |
There was a problem hiding this comment.
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.
| if (kernelMeta.mGroupsTokensHeadsQ) { | ||
| if (kernelMeta.mStepQ < params.mNumHeadsQPerKv) { | ||
| continue; // Skip this candidate as it's invalid | ||
| } | ||
| } |
There was a problem hiding this comment.
|
Looks like a duplicate of #2380 ? |
|
📌 Description
Skip candidates where kernelMeta.mStepQ < params.mNumHeadsQPerKv in GQA tile selection to avoid numTokensPerCtaQ=0, resulting divide-by-zero crash.
🔍 Related Issues
🚀 Pull Request Checklist
Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete.
✅ Pre-commit Checks
pre-commitby runningpip install pre-commit(or used your preferred method).pre-commit install.pre-commit run --all-filesand fixed any reported issues.🧪 Tests
unittest, etc.).Reviewer Notes
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.