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

[fix] Correctly pass mask in TransformerBlock.forward in transformer_layers.py #218

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MarcSzafraniec
Copy link

@MarcSzafraniec MarcSzafraniec commented Sep 18, 2024

The attention mask was not passed correctly to the Attention in TransformerBlock.forward.

One problem it caused was that when passing two images in the image encoder, the attention would be done on all images at the same time, thus taking more resources and returning an incorrect result.

This PR fixes this problem.
Tested by passing two images separately to the encoder, and checking that passing them as a batch gives "almost" the same thing.
Also tested on classic vision benchmarks where the results were very low (and inference very slow), now considerably better:
ImageNet KNN:

  • was 7.27% accuracy and took 5h
  • now is 63.79% accuracy and takes 35 min (8.6 times faster)

…layers.py

The attention mask was not passed correctly to the `Attention` in `TransformerBlock.forward`.

One problem it caused was that when passing two images in the image encoder, the attention would be done on all images at the same time, thus taking more resources and returning an incorrect result.

This PR fixes this problem.
@baldassarreFe
Copy link

I observed the same bug, this PR fixes the bug

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

Successfully merging this pull request may close these issues.

2 participants