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
d4dbd7ca
Unverified
Commit
d4dbd7ca
authored
Sep 05, 2022
by
Joao Gante
Committed by
GitHub
Sep 05, 2022
Browse files
Generate: get the correct beam index on eos token (#18851)
parent
c6d3daba
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
2 deletions
+2
-2
src/transformers/generation_beam_search.py
src/transformers/generation_beam_search.py
+1
-1
tests/generation/test_generation_beam_search.py
tests/generation/test_generation_beam_search.py
+1
-1
No files found.
src/transformers/generation_beam_search.py
View file @
d4dbd7ca
...
@@ -259,7 +259,7 @@ class BeamSearchScorer(BeamScorer):
...
@@ -259,7 +259,7 @@ class BeamSearchScorer(BeamScorer):
continue
continue
if
beam_indices
is
not
None
:
if
beam_indices
is
not
None
:
beam_index
=
beam_indices
[
batch_beam_idx
]
beam_index
=
beam_indices
[
batch_beam_idx
]
beam_index
=
beam_index
+
(
next_inde
x
,)
beam_index
=
beam_index
+
(
batch_beam_id
x
,)
else
:
else
:
beam_index
=
None
beam_index
=
None
...
...
tests/generation/test_generation_beam_search.py
View file @
d4dbd7ca
...
@@ -172,7 +172,7 @@ class BeamSearchTester:
...
@@ -172,7 +172,7 @@ class BeamSearchTester:
input_ids
[
correct_idx
].
tolist
(),
beam_scorer
.
_beam_hyps
[
batch_idx
].
beams
[
0
][
1
].
tolist
()
input_ids
[
correct_idx
].
tolist
(),
beam_scorer
.
_beam_hyps
[
batch_idx
].
beams
[
0
][
1
].
tolist
()
)
)
self
.
parent
.
assertListEqual
(
self
.
parent
.
assertListEqual
(
expected_beam_indices
+
[
next_indices
[
batch_idx
,
1
].
item
()
],
expected_beam_indices
+
[
correct_idx
],
torch
.
tensor
(
beam_scorer
.
_beam_hyps
[
batch_idx
].
beams
[
0
][
2
]).
tolist
(),
torch
.
tensor
(
beam_scorer
.
_beam_hyps
[
batch_idx
].
beams
[
0
][
2
]).
tolist
(),
)
)
...
...
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