fix(attention): fix unflatten crash with flash-attn >= 2.5.9 due to API return type change#18
Open
zhj2300380 wants to merge 1 commit into
Open
Conversation
…PI return type change flash-attn >= 2.5.9 changed the default return type of flash_attn_varlen_func from Tuple[Tensor, ...] to Tensor. The old code used )[0] to unpack the tuple, which incorrectly indexed the tensor when a Tensor was returned directly, causing 'unflatten: Provided sizes [B, Lq] don't multiply up to the size of dim 0' RuntimeError. Changes: - Add _extract_output() helper to handle both old (Tuple) and new (Tensor) API - Remove deprecated seqused_q/seqused_k parameters from FA3 call - Change FA3 import from 'import flash_attn_interface' to 'from flash_attn import flash_attn_interface' - Add ImportError to exception handling for FA3 detection - Add try-except with graceful fallback chain: FA3 -> FA2 -> PyTorch native attention - Remove hard assert on FLASH_ATTN_2_AVAILABLE, allow PyTorch fallback Fixes: RuntimeError: unflatten: Provided sizes [1, 32760] don't multiply up to the size of dim 0 (40)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🐛 Bug Description / 问题描述
When using
flash-attn >= 2.5.9, the application crashes with:使用
flash-attn >= 2.5.9时,应用程序崩溃并报错:🔍 Root Cause / 根本原因
flash-attn >= 2.5.9changed the default return type offlash_attn_varlen_func:Tuple[Tensor, ...]→ requires[0]unpackingTensordirectly →[0]incorrectly indexes the tensorflash-attn >= 2.5.9改变了flash_attn_varlen_func的默认返回类型:Tuple[Tensor, ...]→ 需要[0]解包Tensor→[0]会错误索引 tensor✅ Fix Summary / 修复摘要
_extract_output()helperfrom flash_attn import flash_attn_interfaceseqused_q/seqused_k参数🧪 Testing / 测试验证
flash-attn==2.7.4.post1flash-attn < 2.5.9📦 Environment / 测试环境
📝 Checklist / 检查清单