Small addition to a maybe_add_mask() function.#2674
Closed
gilmoright wants to merge 1 commit intohuggingface:mainfrom
Closed
Small addition to a maybe_add_mask() function.#2674gilmoright wants to merge 1 commit intohuggingface:mainfrom
gilmoright wants to merge 1 commit intohuggingface:mainfrom
Conversation
…pports both bool mask and float
Collaborator
|
@gilmoright aware of this, I did some work on another branch that requires more consistent mask behaviour ... see #2665 ... code: https://github.com/huggingface/pytorch-image-models/blob/ssl_tasks/timm/layers/attention.py However, it's likely not going to get merged anytime soon, not sure if I should cherry pick that in the meantime.. hmm. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some attention mechanism in the timm involves mask application, and while torch and onnx fused attention implementations like F.scaled_dot_product_attention supports both float mask (with -inf values) and bool mask (that is used to create float mask and False values corresponds to -inf), timm.layers.attention.maybe_add_mask expects only float mask.
I decided to make a small cosmetic change and now mask application function timm.layers.attention.maybe_add_mask supports both bool mask and float to better match torch functions.
Script to test:
Outputs before commit:
Outputs after commit