Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'VisionAttention' object has no attribute 'head_dim' #38

Closed
Betty-J opened this issue Aug 30, 2024 · 6 comments
Closed

Comments

@Betty-J
Copy link

Betty-J commented Aug 30, 2024

Hello,
I am encountering the following error while fine-tuning the qwen2-vl-2b-instruct with the Swift framework:
File "./miniconda3/envs/swift/lib/python3.11/site-packages/transformers/models/qwen2_vl/modeling_qwen2_vl.py", line 296, in forward
[rank1]: attn_weights = torch.matmul(q, k.transpose(1, 2)) / math.sqrt(self.head_dim)
AttributeError: 'VisionAttention' object has no attribute 'head_dim'.

After checking the original modeling_qwen2_vl.py file, I found that 'self.head_dim' is indeed not defined in VisionAttention. How can I resolve it?
截屏2024-08-30 17 51 48

@dongZheX
Copy link

when i set attn_implementation="eager", this error happened.

@simonJJJ
Copy link
Contributor

@Betty-J thanks for pointing this out, we will fix it.

@simonJJJ
Copy link
Contributor

we opened a PR for fixing this.

@ApolloRay
Copy link

Has it already fixed ? I meet the same question.

@nihirv
Copy link

nihirv commented Sep 3, 2024

Simple fix -- just add this line in the VisionAttention class: self.head_dim = dim // num_heads (site-packages/transformers/models/qwen2_vl/modeling_qwen2_vl.py)

@lonnex
Copy link

lonnex commented Sep 3, 2024

torch版本更新到2.2.2即可

@Betty-J Betty-J closed this as completed Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants