Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate: get the correct beam index on eos token #18851

Merged
merged 2 commits into from
Sep 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/transformers/generation_beam_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ def process(
continue
if beam_indices is not None:
beam_index = beam_indices[batch_beam_idx]
beam_index = beam_index + (next_index,)
beam_index = beam_index + (batch_beam_idx,)
Copy link
Member Author

@gante gante Sep 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

batch_beam_idx -> beam idx considering all batches (between num_beams*(batch_idx-1) and (num_beams*batch_idx)-1)

next_index -> beam idx for the current batch (between 0 and num_beams-1)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yeah great point!

else:
beam_index = None

Expand Down
2 changes: 1 addition & 1 deletion tests/generation/test_generation_beam_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def cut_expected_tensor(tensor):
input_ids[correct_idx].tolist(), beam_scorer._beam_hyps[batch_idx].beams[0][1].tolist()
)
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(),
)

Expand Down