-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Save and display per-token attention maps #1866
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
Save and display per-token attention maps #1866
Conversation
Generation error: |
8b8a43e
to
a054fae
Compare
this should be merged into main asap, even if that means frontend isn't using it. attention map collection is always-on in this PR but the memory/performance impact is negligible. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 simple change requested - adding types to util function. I haven't been consistent with this at all but I want to make an effort to add types whenever possible going forward.
This is not related to this particular PR, but we will need to save the attention map data somewhere besides just the gallery. The gallery images arrays are not persisted across reloads, and even if they were, resetting localstorage will of course clear them.
So we need to think about how to store them as metadata.
Co-authored-by: psychedelicious <[email protected]>
This pull request enables the display of per-token attention maps after generating an image.
Done:
generationResult
:attentionMaps
(base64 image, sizewidth/8 x 77*height/8
), andtokens
, see below.Todo:
Typical content of the
tokens
array is, eg for prompta fluffy miyazaki dog
, an array:['a</w>', 'fluffy</w>', 'mi', 'yaz', 'aki</w>', 'dog']
. The</w>
strings represent "end-of-word". With this implementation, to match tokens to fragments of the input prompt text in the input box, the frontend code is going to have to crawl through the prompt and do a best-fit match of these tokens to the prompt string.