Skip to content

fallback to fa2 (instead of fa3) for unsupported configuration (bf16 Q, Fp8 KV)#2536

Merged
yzh119 merged 2 commits intomainfrom
fix/mingyangw/2348
Feb 12, 2026
Merged

fallback to fa2 (instead of fa3) for unsupported configuration (bf16 Q, Fp8 KV)#2536
yzh119 merged 2 commits intomainfrom
fix/mingyangw/2348

Conversation

@saltyminty
Copy link
Collaborator

@saltyminty saltyminty commented Feb 10, 2026

📌 Description

When the KV cache dtype is FP8, Q dtype is BF16, GPU is hopper, and the backend is set to "auto", we should set the backend as "fa2" instead of "fa3".

🔍 Related Issues

#2348

🚀 Pull Request Checklist

Thank you for contributing to FlashInfer! Before we review your pull request, please make sure the following items are complete.

🧪 Tests

  • Tests have been added or updated as needed.
  • All tests are passing (unittest, etc.).

Reviewer Notes

Summary by CodeRabbit

  • Chores
    • Added configuration validation: when using an FP8 key/value cache, queries must also use FP8 to ensure FA3 backend compatibility. This prevents unsupported dtype combinations, surfaces clear validation errors earlier, and avoids runtime failures when mixing FP8 KV caches with non-FP8 queries.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @saltyminty, 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 an incompatibility issue where the Flash Attention 3 (FA3) backend was being incorrectly selected for certain configurations involving FP8 KV cache and non-FP8 query data types, specifically on Hopper GPUs. By adding a precise check, the system will now correctly fall back to Flash Attention 2 (FA2) in these unsupported scenarios, preventing potential errors and ensuring optimal performance.

Highlights

  • FA3 Backend Compatibility: Introduced a new condition in the is_fa3_backend_supported function to ensure that Flash Attention 3 (FA3) is not used when the KV cache data type is FP8 (e.g., torch.float8_e4m3fn or torch.float8_e5m2) but the query data type is not also FP8. This forces a fallback to FA2 for such configurations.

🧠 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.

Changelog
  • flashinfer/utils.py
    • Added a check to is_fa3_backend_supported to prevent FA3 usage with FP8 KV cache and non-FP8 query.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request correctly adds a check to is_fa3_backend_supported to handle an unsupported configuration where the KV cache is FP8 but the query is not, ensuring a fallback to the fa2 backend. The change is logical and addresses the issue described. I have one minor suggestion to improve the readability and consistency of the new conditional logic.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 10, 2026

📝 Walkthrough

Walkthrough

The PR tightens FA3 backend validation in flashinfer/utils.py: if KV cache dtype is FP8 (float8_e4m3fn or float8_e5m2), queries must also be FP8; otherwise FA3 is not supported. Existing checks (custom masks, positional encoding mode, FP16 QK reductions) remain.

Changes

Cohort / File(s) Summary
FA3 Backend Constraints
flashinfer/utils.py
Added a conditional disallowing FA3 when dtype_kv is FP8 but dtype_q is not FP8, tightening backend compatibility logic.
Repository metadata
manifest_file, pyproject.toml, requirements.txt
Minor metadata/packaging edits listed in the diff (non-functional).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Suggested reviewers

  • nvmbreughe

Poem

🐰 I nudge the bytes and tap the keys,

FP8 dances with matching pleas,
KV and Q now hop in pair,
FA3 hums through cotton air,
A carrot code fix — light as air.

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: adding a constraint that falls back to FA2 backend when using BF16 queries with FP8 KV cache, which directly matches the changeset.
Description check ✅ Passed The description includes the required Description and Related Issues sections with specific context. However, the PR Checklist sections are not completed (checkboxes unchecked), which are part of the template.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/mingyangw/2348

No actionable comments were generated in the recent review. 🎉

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


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.

❤️ Share

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

@yongwww
Copy link
Member

yongwww commented Feb 11, 2026

@saltyminty please rebase the PR onto the latest main to kick off CI.

@saltyminty
Copy link
Collaborator Author

/bot run

@flashinfer-bot
Copy link
Collaborator

GitLab MR !310 has been created, and the CI pipeline #43829833 is currently running. I'll report back once the pipeline job completes.

@flashinfer-bot
Copy link
Collaborator

[FAILED] Pipeline #43829833: 15/20 passed

@yzh119 yzh119 merged commit 8316a3f into main Feb 12, 2026
28 of 29 checks passed
@yzh119 yzh119 deleted the fix/mingyangw/2348 branch February 12, 2026 20:06
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.

5 participants