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
9934bb1f
Unverified
Commit
9934bb1f
authored
Jul 03, 2023
by
Joao Gante
Committed by
GitHub
Jul 03, 2023
Browse files
Generate: multi-device support for contrastive search (#24635)
parent
4b26a616
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
3 additions
and
1 deletion
+3
-1
src/transformers/generation/utils.py
src/transformers/generation/utils.py
+3
-1
No files found.
src/transformers/generation/utils.py
View file @
9934bb1f
...
@@ -2060,8 +2060,10 @@ class GenerationMixin:
...
@@ -2060,8 +2060,10 @@ class GenerationMixin:
context_hidden
=
last_hidden_states
.
repeat_interleave
(
top_k
,
dim
=
0
)
context_hidden
=
last_hidden_states
.
repeat_interleave
(
top_k
,
dim
=
0
)
# compute the degeneration penalty and re-rank the candidates based on the degeneration penalty and the
# compute the degeneration penalty and re-rank the candidates based on the degeneration penalty and the
# model confidence
# model confidence. Keeping `selected_idx` on CPU enables multi-device contrastive search and doesn't
# introduce (noticeable) slowdowns on single-device runs.
selected_idx
=
_ranking_fast
(
context_hidden
,
next_hidden
,
top_k_probs
,
penalty_alpha
,
top_k
)
selected_idx
=
_ranking_fast
(
context_hidden
,
next_hidden
,
top_k_probs
,
penalty_alpha
,
top_k
)
selected_idx
=
selected_idx
.
to
(
"cpu"
)
# prepare for the next step: (1) next token_id; (2) past_key_values; (3) last_hidden_states for computing
# prepare for the next step: (1) next token_id; (2) past_key_values; (3) last_hidden_states for computing
# the degeneration penalty; (4) logits for selecting next top-k candidates; (5) selected tokens scores
# the degeneration penalty; (4) logits for selecting next top-k candidates; (5) selected tokens scores
...
...
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