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
f4e4b4d0
Unverified
Commit
f4e4b4d0
authored
Jul 03, 2023
by
Joao Gante
Committed by
GitHub
Jul 03, 2023
Browse files
Generate: force cache with `inputs_embeds` forwarding (#24639)
parent
9934bb1f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
1 deletion
+6
-1
src/transformers/generation/utils.py
src/transformers/generation/utils.py
+6
-1
No files found.
src/transformers/generation/utils.py
View file @
f4e4b4d0
...
@@ -1304,6 +1304,11 @@ class GenerationMixin:
...
@@ -1304,6 +1304,11 @@ class GenerationMixin:
# 4. Define other model kwargs
# 4. Define other model kwargs
model_kwargs
[
"output_attentions"
]
=
generation_config
.
output_attentions
model_kwargs
[
"output_attentions"
]
=
generation_config
.
output_attentions
model_kwargs
[
"output_hidden_states"
]
=
generation_config
.
output_hidden_states
model_kwargs
[
"output_hidden_states"
]
=
generation_config
.
output_hidden_states
# decoder-only models with inputs_embeds forwarding must use caching (otherwise we can't detect whether we are
# generating the first new token or not, and we only want to use the embeddings for the first new token)
if
not
self
.
config
.
is_encoder_decoder
and
model_input_name
==
"inputs_embeds"
:
model_kwargs
[
"use_cache"
]
=
True
else
:
model_kwargs
[
"use_cache"
]
=
generation_config
.
use_cache
model_kwargs
[
"use_cache"
]
=
generation_config
.
use_cache
accepts_attention_mask
=
"attention_mask"
in
set
(
inspect
.
signature
(
self
.
forward
).
parameters
.
keys
())
accepts_attention_mask
=
"attention_mask"
in
set
(
inspect
.
signature
(
self
.
forward
).
parameters
.
keys
())
...
...
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