StoppingCriteria tracks elements separately in the batch#29056
StoppingCriteria tracks elements separately in the batch#29056zucchini-nlp wants to merge 0 commit intohuggingface:mainfrom
Conversation
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. |
gante
left a comment
There was a problem hiding this comment.
Looking good 👍
Regarding beam search: the current PyTorch implementation tracks beam termination in a separate class (as opposed to e.g. unfinished_sequences in greedy decoding). Ideally, beam termination should come from the stopping criteria as well but, as you wrote, calling it twice is suboptimal. We should first refactor beam search to be torch.compile-compatible first, then think of a solution for this particular case (leaving it as it is for now).
gante
left a comment
There was a problem hiding this comment.
oops, meant to approve.
btw, you'll need to run make fixup on your end to get rid of the formatting errors in CI.
dc518c5 to
f497f56
Compare
What does this PR do?
As was pointed out in #28932 , StoppingCriteria needs to stop generation per batch element and return a boolean tensor of
batch_size. This PR adds the logic to track each row and when StoppingCriteria is triggered, stop generating for that particular row only.Note that the when #28932 gets merged, we need to add logic to handle beam related generation. The problem is that beam search has an internal logic of tracking EOS tokens and adds candidate tokens to hypothesis when done. And if StoppingCriteria will take the responsibility to track custom EOS tokens, it has to be passed to beam scorer. Right now I am not sure if calling StoppingCriteria twice is a good decision. First time to check candidate beams, and the second time for the chosen beams. What do you think @gante? It can be something like:
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
Anyone in the community is free to review the PR once the tests have passed. Feel free to tag
members/contributors who may be interested in your PR.
@gante