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

Attention Map example #7

Closed
fedegonzal opened this issue Oct 30, 2023 · 8 comments
Closed

Attention Map example #7

fedegonzal opened this issue Oct 30, 2023 · 8 comments
Assignees

Comments

@fedegonzal
Copy link

fedegonzal commented Oct 30, 2023

Hi,

Since this repo is based on the paper "ViT needs registers" should be usefull to publish some example to visualize attention maps.

Thanks for this great work!

Upvote & Fund

  • We're using Polar.sh so you can upvote and help fund this issue.
  • We receive the funding once the issue is completed & confirmed by you.
  • Thank you in advance for helping prioritize & fund our backlog.
Fund with Polar
@kyegomez
Copy link
Owner

kyegomez commented Nov 1, 2023

@fedegonzal yes this would be a good idea, let's work together on this. Can you make an example?

@aronvandepol
Copy link

I'd also be very curious to see some examples! 🙌

Copy link

Stale issue message

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale Feb 24, 2024
@wylapp
Copy link

wylapp commented Jun 13, 2024

Hello everyone!

I managed to draw the attention map, and the artifacts do exist.

Other than the attention map, has anyone tried to draw the norms plot in Figure 3 (from "Vision Transformers Need Registers")?
I got the opposite result, where there are no outlier patches.

We observe that an important difference between “artifact” patches and other patches is the norm of their token embedding at the output of the model.

This is the only sentence that authors explain what an outlier patch/token is.

FYI, this is my implementation.
https://colab.research.google.com/drive/1gHDOi8RL8hHmfAJvF7IqyBF7tmosG0ko

image

@zwyang6
Copy link

zwyang6 commented Aug 17, 2024

+1 demos are neccessary 🙌

@TumVink
Copy link

TumVink commented Sep 17, 2024

Hello everyone!

I managed to draw the attention map, and the artifacts do exist.

Other than the attention map, has anyone tried to draw the norms plot in Figure 3 (from "Vision Transformers Need Registers")? I got the opposite result, where there are no outlier patches.

We observe that an important difference between “artifact” patches and other patches is the norm of their token embedding at the output of the model.

This is the only sentence that authors explain what an outlier patch/token is.

FYI, this is my implementation. https://colab.research.google.com/drive/1gHDOi8RL8hHmfAJvF7IqyBF7tmosG0ko

image

Heyy,
I am having a look at your script. Your attention_map seems good, however why L2 norm is based on Outputs[0]? Where does it come from?

@wylapp
Copy link

wylapp commented Sep 20, 2024

As aforementioned, the authors define the outlier patch as follows:

We observe that an important difference between “artifact” patches and other patches is the norm of their token embedding at the output of the model.

The output[0] is the model's last hidden state, which has the shape of [Batch_size, Sequence_length, Embedding_size]. I think this can be seen as the "token embedding at the output of the model". Then calculate the L2-norm in the last dimension using torch.norm(outputs[0], 2, dim=-1).

@TumVink
Copy link

TumVink commented Sep 20, 2024

It makes sense!
However, I re-produces the hign-norm outliers with the codes from here with my own custom images.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants