GenerationConfig validate both constraints and force_words_ids #29163
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does this PR do?
There is currently two ways to pass constraints to constrained beam search, either
constraints
orforce_words_ids
. They get merged here which is after the GenerationConfig initialization. I was following the blog on constrained decoding (usingforce_words_ids
and was checking for myself which other options constrained beam search can be combined with (Ex: can I sample and constrained beam search? [no])This snippet raised a
ValueError
:while this snipped didn't:
I've added the additional check to
GenerationConfig.validate()
to includeforce_words_ids
and I've added two new tests:Without the change only the first test passes, with the change both tests pass as they now both raise
ValueErrors
(Expected behavior).This is my first time opening a PR here, so let me know what I can improve. I've followed the docs on contribution for this PR, though after running all tests after installation there were 5 tests that failed before I changed anything.
Cheers! :)
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
maybe @gante