Repository navigation
fix: set HAS_FLEX_ATTENTION=True after successful import (closes #3650) - #5834
botbikamordehai2-sketch wants to merge 2 commits into
Conversation
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
There was a problem hiding this comment.
Code Review
This pull request fixes a bug in unsloth/kernels/flex_attention.py where HAS_FLEX_ATTENTION was hardcoded to False even if the compilation of _flex_attention succeeded. It now correctly sets HAS_FLEX_ATTENTION to True upon successful compilation. There are no review comments, and I have no additional feedback to provide.
|
nice find. can you help us with what the attn_impl resolves to after the change for gemma3(n), gpt oss, gemma 4 etc? |
|
Hey @botbikamordehai2-sketch apparently this is dead code and used nowhere. Can you check if this is being used anywhere? If not we can remove it altogether |
|
HAS_FLEX_ATTENTION = False on the success path is intentional, not a bug. It was set deliberately in commit 6a1bef2 ('Disable Flex Attention', Oct 2024). Flipping it to True re-enables a disabled code path (used in unsloth/models/llama.py) with no tests, no benchmarks, and no discussion of why it was disabled, and it does not address #3650. If flex attention is to be re-enabled it needs a deliberate change with correctness and performance validation. Closing. |
What
In
unsloth/kernels/flex_attention.py,HAS_FLEX_ATTENTIONis incorrectly set toFalseeven after successfully importingflex_attentionfromtorch.nn.attention.flex_attention. This causes the flex attention code path to never be used, always falling back to the slow attention path, which can cause maximum recursion depth errors with models like Gemma 3n.Fix
Change
HAS_FLEX_ATTENTION = FalsetoHAS_FLEX_ATTENTION = Trueinside thetryblock after successfully importing and compiling flex attention.Closes #3650