Repository navigation
fix(models): Update Flash Attention detection for version 2.7+ - #4361
BillionClaw wants to merge 2 commits into
Conversation
The Flash Attention availability check tried to import internal functions (flash_attn_gpu/flash_attn_cuda) from flash_attn.flash_attn_interface, which may not exist in flash-attn 2.7+. Now first tries to import the public API (flash_attn_func) from flash_attn, which is the actual function used by Unsloth. Falls back to legacy imports for older flash-attn versions. Fixes unslothai#4270
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
Summary of ChangesHello, 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 refines the Flash Attention availability detection mechanism within Unsloth. By prioritizing the import of the public Highlights
Changelog
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
|
There was a problem hiding this comment.
Code Review
This pull request correctly updates the Flash Attention availability check. My review includes two main points: first, to use specific exceptions (ImportError) instead of bare except: blocks for better error handling, and second, to refactor the duplicated code for checking Flash Attention into a helper function to improve maintainability.
| try: | ||
| # See https://github.com/unslothai/unsloth/issues/1437 | ||
| from flash_attn.flash_attn_interface import flash_attn_gpu | ||
| from flash_attn import flash_attn_func | ||
|
|
||
| _ = flash_attn_func # Ensure import is valid | ||
| except: | ||
| from flash_attn.flash_attn_interface import flash_attn_cuda | ||
| # Fall back to legacy import check (for older flash-attn versions) | ||
| # See https://github.com/unslothai/unsloth/issues/1437 | ||
| try: | ||
| from flash_attn.flash_attn_interface import flash_attn_gpu | ||
| except: |
There was a problem hiding this comment.
It's better to catch specific exceptions rather than using a bare except:. This prevents catching unexpected errors (like KeyboardInterrupt) and makes the code's intent clearer. Using except ImportError: would be more appropriate here.
| try: | |
| # See https://github.com/unslothai/unsloth/issues/1437 | |
| from flash_attn.flash_attn_interface import flash_attn_gpu | |
| from flash_attn import flash_attn_func | |
| _ = flash_attn_func # Ensure import is valid | |
| except: | |
| from flash_attn.flash_attn_interface import flash_attn_cuda | |
| # Fall back to legacy import check (for older flash-attn versions) | |
| # See https://github.com/unslothai/unsloth/issues/1437 | |
| try: | |
| from flash_attn.flash_attn_interface import flash_attn_gpu | |
| except: | |
| try: | |
| from flash_attn import flash_attn_func | |
| _ = flash_attn_func # Ensure import is valid | |
| except ImportError: | |
| # Fall back to legacy import check (for older flash-attn versions) | |
| # See https://github.com/unslothai/unsloth/issues/1437 | |
| try: | |
| from flash_attn.flash_attn_interface import flash_attn_gpu | |
| except ImportError: | |
| from flash_attn.flash_attn_interface import flash_attn_cuda |
| # Check for CUDA linking errors "undefined symbol: _ZNK3c106SymIntltEl" | ||
| try: | ||
| # Try importing the actual functions used by Unsloth first (for flash-attn 2.7+) | ||
| # See https://github.com/unslothai/unsloth/issues/4270 | ||
| try: | ||
| # See https://github.com/unslothai/unsloth/issues/1437 | ||
| from flash_attn.flash_attn_interface import flash_attn_gpu | ||
| from flash_attn import flash_attn_func | ||
|
|
||
| _ = flash_attn_func # Ensure import is valid | ||
| except: | ||
| from flash_attn.flash_attn_interface import flash_attn_cuda | ||
| # Fall back to legacy import check (for older flash-attn versions) | ||
| # See https://github.com/unslothai/unsloth/issues/1437 | ||
| try: | ||
| from flash_attn.flash_attn_interface import flash_attn_gpu | ||
| except: |
There was a problem hiding this comment.
This logic for checking Flash Attention availability is duplicated from the cuda device block above (lines 874-920). To improve maintainability, this should be refactored into a shared helper function.
Also, please apply the same fix here as suggested for the previous block: use specific except ImportError: instead of bare except:.
|
Hi! Just checking in on this PR. Is there anything needed from my side to help move it forward? |
|
Closing per ClawOSS blocklist — repo has 100% closure rate and no maintainer engagement. |
The Flash Attention availability check tried to import internal functions (flash_attn_gpu/flash_attn_cuda) from flash_attn.flash_attn_interface, which may not exist in flash-attn 2.7+.
Changed to first try importing the public API (flash_attn_func) from flash_attn, which is the actual function used by Unsloth throughout the codebase. Falls back to legacy imports for older flash-attn versions.
This fixes false negatives where flash-attn 2.7+ was incorrectly detected as broken, causing unnecessary fallback to XFormers and reduced GPU utilization.
Fixes #4270