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

A n error about "The size of tensor a (96) must match the size of tensor b (288) at non-singleton dimension 0" #142

Open
ZhenyuLiu-SYSU opened this issue Apr 6, 2023 · 5 comments

Comments

@ZhenyuLiu-SYSU
Copy link

Dear author:
I'm glad to see your excellent work.
As I'm a newcomer to the this field, when I try to generate the captions on COCO2017 dataset, I found this question?:
image
could you tell me how can I fix it?
Thank you!

@cookielovesdata
Copy link

Same issue! Have you figured out how?

@ZhenyuLiu-SYSU
Copy link
Author

I tried to print the shape of each tensor and found that when is_cross_attention=True, mixed_query_layer shape: torch.Size([96, 4, 768]), but key_layer shape: torch.Size([288, 12, 577, 64] ), resulting in a difference in the dimension 0, so I performed the following operations:
image
The same problem will be encountered in two places later, and the solution is the same.

I tried to solve it but I don't know if it is correct, hope more people can help!

@kosarkazemi
Copy link

You need to downgrade the transformers library to 4.15.0.

@ZhenyuLiu-SYSU
Copy link
Author

It works.
Thank you!

@Vinicius-ufsc
Copy link

for me 4.15 did not worked, but it worked with

!pip install transformers=='4.16'

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

4 participants