[GH-ISSUE #87] ImportError: cannot import name 'LlamaFlashAttention2' from 'transformers.models.llama.modeling_llama' , !pip install transformers==4.47.1 does not fix #70

Open
opened 2026-10-26 21:11:22 +00:00 by bsakaguchi · 7 comments
Owner

Originally created by @mohayl on GitHub (Feb 18, 2025).
Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-VL2/issues/87


ImportError Traceback (most recent call last)
Cell In[43], line 11
6 except ImportError:
7 LlamaFlashAttention2 = None # or assign a fallback implementation
---> 11 from deepseek_vl2.models import DeepseekVLV2ForCausalLM
12 from deepseek_vl2.models import DeepseekVLV2Processor
14 from deepseek_vl2.utils.io import load_pil_images

File ~/DeepSeek-VL2/deepseek_vl2/models/init.py:21
1 # Copyright (c) 2023-2024 DeepSeek.
2 #
3 # Permission is hereby granted, free of charge, to any person obtaining a copy of
(...)
17 # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
18 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20 from .processing_deepseek_vl_v2 import DeepseekVLV2Processor
---> 21 from .modeling_deepseek_vl_v2 import DeepseekVLV2ForCausalLM
23 all = [
24 "DeepseekVLV2Processor",
25 "DeepseekVLV2ForCausalLM",
26 ]

File ~/DeepSeek-VL2/deepseek_vl2/models/modeling_deepseek_vl_v2.py:28
26 from .siglip_vit import VisionTransformer
27 from .configuration_deepseek import DeepseekV2Config
---> 28 from .modeling_deepseek import DeepseekV2ForCausalLM
31 logger = logging.get_logger(name)
34 class MlpProjector(nn.Module):

File ~/DeepSeek-VL2/deepseek_vl2/models/modeling_deepseek.py:37
35 from transformers.cache_utils import Cache, DynamicCache
36 from transformers.modeling_attn_mask_utils import _prepare_4d_causal_attention_mask
---> 37 from transformers.models.llama.modeling_llama import (
38 LlamaAttention,
39 LlamaFlashAttention2
40 )
41 from transformers.modeling_outputs import (
42 BaseModelOutputWithPast,
43 CausalLMOutputWithPast,
44 SequenceClassifierOutputWithPast,
45 )
46 from transformers.modeling_utils import PreTrainedModel

ImportError: cannot import name 'LlamaFlashAttention2' from 'transformers.models.llama.modeling_llama'

Originally created by @mohayl on GitHub (Feb 18, 2025). Original GitHub issue: https://github.com/deepseek-ai/DeepSeek-VL2/issues/87 --------------------------------------------------------------------------- ImportError Traceback (most recent call last) Cell In[43], line 11 6 except ImportError: 7 LlamaFlashAttention2 = None # or assign a fallback implementation ---> 11 from deepseek_vl2.models import DeepseekVLV2ForCausalLM 12 from deepseek_vl2.models import DeepseekVLV2Processor 14 from deepseek_vl2.utils.io import load_pil_images File ~/DeepSeek-VL2/deepseek_vl2/models/__init__.py:21 1 # Copyright (c) 2023-2024 DeepSeek. 2 # 3 # Permission is hereby granted, free of charge, to any person obtaining a copy of (...) 17 # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 from .processing_deepseek_vl_v2 import DeepseekVLV2Processor ---> 21 from .modeling_deepseek_vl_v2 import DeepseekVLV2ForCausalLM 23 __all__ = [ 24 "DeepseekVLV2Processor", 25 "DeepseekVLV2ForCausalLM", 26 ] File ~/DeepSeek-VL2/deepseek_vl2/models/modeling_deepseek_vl_v2.py:28 26 from .siglip_vit import VisionTransformer 27 from .configuration_deepseek import DeepseekV2Config ---> 28 from .modeling_deepseek import DeepseekV2ForCausalLM 31 logger = logging.get_logger(__name__) 34 class MlpProjector(nn.Module): File ~/DeepSeek-VL2/deepseek_vl2/models/modeling_deepseek.py:37 35 from transformers.cache_utils import Cache, DynamicCache 36 from transformers.modeling_attn_mask_utils import _prepare_4d_causal_attention_mask ---> 37 from transformers.models.llama.modeling_llama import ( 38 LlamaAttention, 39 LlamaFlashAttention2 40 ) 41 from transformers.modeling_outputs import ( 42 BaseModelOutputWithPast, 43 CausalLMOutputWithPast, 44 SequenceClassifierOutputWithPast, 45 ) 46 from transformers.modeling_utils import PreTrainedModel ImportError: cannot import name 'LlamaFlashAttention2' from 'transformers.models.llama.modeling_llama'
Author
Owner

@RunningLeon commented on GitHub (Feb 21, 2025):

met same issue with transformers==4.48.3. Roll back to 4.47.0 would fix it. Hope it fixed soon.

<!-- gh-comment-id:2674106349 --> @RunningLeon commented on GitHub (Feb 21, 2025): met same issue with transformers==4.48.3. Roll back to 4.47.0 would fix it. Hope it fixed soon.
Author
Owner

@baibizhe commented on GitHub (Feb 26, 2025):

i delete that line. that line of code of for tiny model. the small and normal model function properly without that line .

<!-- gh-comment-id:2683856729 --> @baibizhe commented on GitHub (Feb 26, 2025): i delete that line. that line of code of for tiny model. the small and normal model function properly without that line .
Author
Owner

@kevinkexu commented on GitHub (Mar 6, 2025):

i delete that line. that line of code of for tiny model. the small and normal model function properly without that line .

yeah, it seems deepseek never uses LlamaFlashAttention2, just commenting all LlamaFlashAttention2 will work.

<!-- gh-comment-id:2703106163 --> @kevinkexu commented on GitHub (Mar 6, 2025): > i delete that line. that line of code of for tiny model. the small and normal model function properly without that line . yeah, it seems deepseek never uses LlamaFlashAttention2, just commenting all LlamaFlashAttention2 will work.
Author
Owner

@randomradio commented on GitHub (Oct 30, 2025):

pip install transformers==4.41.1 resolved it.

<!-- gh-comment-id:3466651085 --> @randomradio commented on GitHub (Oct 30, 2025): pip install transformers==4.41.1 resolved it.
Author
Owner

@hieunc278 commented on GitHub (Nov 9, 2025):

Basically, we should not solve this issue by commenting out LlamaFlashAttention2 class, I solved this by more properly way

<!-- gh-comment-id:3507531596 --> @hieunc278 commented on GitHub (Nov 9, 2025): Basically, we should not solve this issue by commenting out LlamaFlashAttention2 class, I solved this by more properly way
Author
Owner

@MiddlePathLabs commented on GitHub (Nov 16, 2025):

Basically, we should not solve this issue by commenting out LlamaFlashAttention2 class, I solved this by more properly way

How?

<!-- gh-comment-id:3539322983 --> @MiddlePathLabs commented on GitHub (Nov 16, 2025): > Basically, we should not solve this issue by commenting out LlamaFlashAttention2 class, I solved this by more properly way How?
Author
Owner

@aibhavesh commented on GitHub (Mar 12, 2026):

yes how would it possible without using attention we can load it ??

<!-- gh-comment-id:4046906705 --> @aibhavesh commented on GitHub (Mar 12, 2026): yes how would it possible without using attention we can load it ??
Sign in to join this conversation.
No labels
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
deepseek-ai/DeepSeek-VL2#70
No description provided.