-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Ensure RewardConfig
is backwards compatible
#748
Conversation
The documentation is not available anymore as the PR was closed or merged. |
" It will be set to `512` by default, but you should do it yourself in the future.", | ||
UserWarning, | ||
) | ||
max_length = 512 |
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.
Side remark for a later PR, but I think this should ideally be set to be the model's max context size as the default
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.
Thanks a lot ! I left two comments, otherwise looking great ! Thanks for taking care of the backward compatibility lewis!
"You cannot specify both `max_length` and `args.max_length`. Please use the `RewardConfig` to set `max_length` once." | ||
) | ||
if max_length is not None and args.max_length is None: | ||
if type(args) == TrainingArguments: |
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 type(args) == TrainingArguments: | |
if isinstance(args, TrainingArguments): |
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.
I tried this initially, but realised it wont' work because args
is a subclass of TrainingArguments
and thus is an instance of TrainingArguments
which makes the if-statement always true. See e.g. this: https://stackoverflow.com/questions/1549801/what-are-the-differences-between-type-and-isinstance
Happy to refactor to a try / except clause if you prefer :)
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.
I see perfect, thanks a lot lewis for explaining!
max_length = 512 | ||
if max_length is None and args.max_length is not None: | ||
max_length = args.max_length | ||
if type(args) == TrainingArguments: |
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 type(args) == TrainingArguments: | |
if isinstance(args, TrainingArguments): |
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.
Thanks again for your work on this @lewtun !
In #726 we replaced the
RewardTrainer.args
with a dedicatedRewardConfig
to collect all hyperparameters in a dedicated class (in particularmax_length
).Unfortunately, that implementation wasn't backwards compatible because
RewardTrainer.args
was of typetransformers.TrainingArguments
and that object doesn't have themax_length
attribute. This meant that part of the logic which checks for the presence ofargs.max_length
would throw an error for any users who hadn't updated their code to useRewardConfig
.This PR fixes that by first checking the type of
RewardTrainer.args
and raising a warning if it'stransformers.TrainingArguments
.Happy to add a unit test for this, but I felt it was a bit of overkill.