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
5e6cd51b
"tests/vscode:/vscode.git/clone" did not exist on "2c04e5855cf4a4696d8b1688e2858a93b125a865"
Unverified
Commit
5e6cd51b
authored
Mar 01, 2023
by
Andy Ehrenberg
Committed by
GitHub
Mar 01, 2023
Browse files
Flax beam search fix (#21857)
parent
b599b192
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
src/transformers/generation/flax_utils.py
src/transformers/generation/flax_utils.py
+8
-6
No files found.
src/transformers/generation/flax_utils.py
View file @
5e6cd51b
...
...
@@ -448,9 +448,10 @@ class FlaxGenerationMixin:
model_kwargs
[
"encoder_outputs"
][
"last_hidden_state"
],
num_beams
=
generation_config
.
num_beams
)
if
"attention_mask"
in
model_kwargs
:
model_kwargs
[
"attention_mask"
]
=
self
.
_expand_to_num_beams
(
model_kwargs
[
"attention_mask"
],
num_beams
=
generation_config
.
num_beams
for
kwarg
in
[
"attention_mask"
,
"decoder_attention_mask"
]:
if
kwarg
in
model_kwargs
:
model_kwargs
[
kwarg
]
=
self
.
_expand_to_num_beams
(
model_kwargs
[
kwarg
],
num_beams
=
generation_config
.
num_beams
)
return
self
.
_beam_search
(
...
...
@@ -821,8 +822,9 @@ class FlaxGenerationMixin:
model_kwargs
[
"encoder_outputs"
][
"last_hidden_state"
]
=
flatten_beam_dim
(
model_kwargs
[
"encoder_outputs"
][
"last_hidden_state"
]
)
if
"attention_mask"
in
model_kwargs
:
model_kwargs
[
"attention_mask"
]
=
flatten_beam_dim
(
model_kwargs
[
"attention_mask"
])
for
kwarg
in
[
"attention_mask"
,
"decoder_attention_mask"
]:
if
kwarg
in
model_kwargs
:
model_kwargs
[
kwarg
]
=
flatten_beam_dim
(
model_kwargs
[
kwarg
])
# initialize model specific kwargs
model_kwargs
=
self
.
prepare_inputs_for_generation
(
flatten_beam_dim
(
input_ids
),
max_length
,
**
model_kwargs
)
...
...
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