You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks for flagging this, and sorry on the delay! HAS_FLEX_ATTENTION = False on the success path is intentional: the old hand-written flex path in unsloth/kernels/flex_attention.py was deliberately disabled, so the flag acts as an off switch rather than an availability check.
Flipping it to True would actually break Gemma 2 training today. That branch builds one causal BlockMask at max_seq_length and reuses it for every batch, and current PyTorch refuses a mask built for a longer length (ValueError: block_mask was created for block_mask.shape=(1, 1, 1024, 1024) but got q_len=37 and kv_len=37, reproduced on torch 2.13). It also ignores padding masks.
Unsloth now uses flex attention through the transformers attention interface instead (for example Gemma 3 by default, and large head dim models via UNSLOTH_FLEX_ATTENTION_FOR_LARGE_HEAD_DIM), with BlockMasks built per batch. Gemma 2 stays on the softcapping kernel because it measured faster than flex.
So I'm closing this as not planned. If you want flex attention on a model that supports it, pass attn_implementation = "flex_attention" to from_pretrained. Same reasoning as #5834.
Activity
danielhanchen commentedon Feb 26, 2025
Oh I left some code pre Flex Attention, but I didn't have time to actually enable it yet
danielhanchen commentedon Oct 8, 2026
Thanks for flagging this, and sorry on the delay!
HAS_FLEX_ATTENTION = Falseon the success path is intentional: the old hand-written flex path inunsloth/kernels/flex_attention.pywas deliberately disabled, so the flag acts as an off switch rather than an availability check.Flipping it to
Truewould actually break Gemma 2 training today. That branch builds one causalBlockMaskatmax_seq_lengthand reuses it for every batch, and current PyTorch refuses a mask built for a longer length (ValueError: block_mask was created for block_mask.shape=(1, 1, 1024, 1024) but got q_len=37 and kv_len=37, reproduced on torch 2.13). It also ignores padding masks.Unsloth now uses flex attention through the transformers attention interface instead (for example Gemma 3 by default, and large head dim models via
UNSLOTH_FLEX_ATTENTION_FOR_LARGE_HEAD_DIM), with BlockMasks built per batch. Gemma 2 stays on the softcapping kernel because it measured faster than flex.So I'm closing this as not planned. If you want flex attention on a model that supports it, pass
attn_implementation = "flex_attention"tofrom_pretrained. Same reasoning as #5834.Fix optimizer state offload crash with Q-GaLore weight quantization (u…