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
4b63d013
Unverified
Commit
4b63d013
authored
Apr 23, 2024
by
Pedro Cuenca
Committed by
GitHub
Apr 23, 2024
Browse files
Make EosTokenCriteria compatible with mps (#30376)
parent
57fc00f3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
1 deletion
+12
-1
src/transformers/generation/stopping_criteria.py
src/transformers/generation/stopping_criteria.py
+12
-1
No files found.
src/transformers/generation/stopping_criteria.py
View file @
4b63d013
...
@@ -481,6 +481,17 @@ class EosTokenCriteria(StoppingCriteria):
...
@@ -481,6 +481,17 @@ class EosTokenCriteria(StoppingCriteria):
@
add_start_docstrings
(
STOPPING_CRITERIA_INPUTS_DOCSTRING
)
@
add_start_docstrings
(
STOPPING_CRITERIA_INPUTS_DOCSTRING
)
def
__call__
(
self
,
input_ids
:
torch
.
LongTensor
,
scores
:
torch
.
FloatTensor
,
**
kwargs
)
->
torch
.
BoolTensor
:
def
__call__
(
self
,
input_ids
:
torch
.
LongTensor
,
scores
:
torch
.
FloatTensor
,
**
kwargs
)
->
torch
.
BoolTensor
:
if
input_ids
.
device
.
type
==
"mps"
:
# https://github.com/pytorch/pytorch/issues/77764#issuecomment-2067838075
is_done
=
(
input_ids
[:,
-
1
]
.
tile
(
self
.
eos_token_id
.
shape
[
0
],
1
)
.
eq
(
self
.
eos_token_id
.
unsqueeze
(
1
).
to
(
input_ids
.
device
))
.
sum
(
dim
=
0
)
.
bool
()
.
squeeze
()
)
else
:
is_done
=
torch
.
isin
(
input_ids
[:,
-
1
],
self
.
eos_token_id
.
to
(
input_ids
.
device
))
is_done
=
torch
.
isin
(
input_ids
[:,
-
1
],
self
.
eos_token_id
.
to
(
input_ids
.
device
))
return
is_done
return
is_done
...
...
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