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
"...git@developer.sourcefind.cn:chenpangpang/transformers.git" did not exist on "ea89bec185f7acaeb4b7e5c0ee1082e541becedd"
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
Hide 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,7 +481,18 @@ class EosTokenCriteria(StoppingCriteria):
...
@@ -481,7 +481,18 @@ 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
:
is_done
=
torch
.
isin
(
input_ids
[:,
-
1
],
self
.
eos_token_id
.
to
(
input_ids
.
device
))
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
))
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