-
Notifications
You must be signed in to change notification settings - Fork 1.8k
🧸 Fix unset tokenizer pad_token #3290
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
🧸 Fix unset tokenizer pad_token #3290
Conversation
trl/trainer/grpo_trainer.py
Outdated
@@ -358,6 +358,8 @@ def __init__( | |||
# Processing class | |||
if processing_class is None: | |||
processing_class = AutoTokenizer.from_pretrained(model.config._name_or_path, padding_side="left") | |||
if processing_class.pad_token is None: | |||
processing_class.pad_token = processing_class.eos_token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we warn/inform the user of this default behaviour?
For the record, setting the |
on second thought how about matching the approach of Lines 52 to 54 in 1e61f6c
this makes the default behaviour very explicit, i fear it would get drowned out in the processing_class doc. my only gripe with the above is stuffing the config with too many parameters, how common is it for a user to want to use a custom padding token. |
Yes, that's an option as well. But this one would require to change the way we pad the inputs. Currently we rely on the tokenizer for padding.
Hardly never I would guess. I'm good with both options |
Chose to document the default behavior of |
trl/trainer/grpo_trainer.py
Outdated
if processing_class.pad_token is None: | ||
processing_class.pad_token = processing_class.eos_token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if processing_class.pad_token is None: | |
processing_class.pad_token = processing_class.eos_token | |
if processing_class.pad_token is None: | |
processing_class.pad_token = processing_class.eos_token |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We also want to run this when the processing class is passed, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, agreed. But the more I think about it, the less I like the idea of silently setting the padding token.... even if it's documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
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. |
What does this PR do?
Fixes #3287
This quietly solves the issue where an auto initialized tokenizer lacks a padding token, by setting it to the EOS token. I considered adding a
pad_token
as an input parameter to GRPOTrainer but at that point you may as well initialize the tokenizer yourself and pass it to GRPOTrainer asprocessing_class=
.Before submitting
Pull Request section?
to it if that's the case.
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.