Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
transformers
Commits
87a6cf41
Unverified
Commit
87a6cf41
authored
Jan 08, 2024
by
zspo
Committed by
GitHub
Jan 08, 2024
Browse files
[AttentionMaskConverter] fix sdpa unmask unattended (#28369)
fix tensor device
parent
98dba52c
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
2 deletions
+2
-2
src/transformers/modeling_attn_mask_utils.py
src/transformers/modeling_attn_mask_utils.py
+2
-2
No files found.
src/transformers/modeling_attn_mask_utils.py
View file @
87a6cf41
...
@@ -234,8 +234,8 @@ class AttentionMaskConverter:
...
@@ -234,8 +234,8 @@ class AttentionMaskConverter:
# Get the index of the first non-zero value for every sample in the batch.
# Get the index of the first non-zero value for every sample in the batch.
# In the above example, indices = [[2], [0], [1]]]
# In the above example, indices = [[2], [0], [1]]]
tmp
=
torch
.
arange
(
attention_mask
.
shape
[
1
],
0
,
-
1
)
tmp
=
torch
.
arange
(
attention_mask
.
shape
[
1
],
0
,
-
1
,
device
=
attention_mask
.
device
)
indices
=
torch
.
argmax
(
attention_mask
.
cpu
()
*
tmp
,
1
,
keepdim
=
True
)
indices
=
torch
.
argmax
(
attention_mask
*
tmp
,
1
,
keepdim
=
True
)
# Find the batch indexes that have unattended tokens on the leftmost side (e.g. [0, 0, 1, 1, 1]), for which the first rows of the
# Find the batch indexes that have unattended tokens on the leftmost side (e.g. [0, 0, 1, 1, 1]), for which the first rows of the
# expanded mask will be completely unattended.
# expanded mask will be completely unattended.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment