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

Ensure RewardConfig is backwards compatible #748

Merged
merged 1 commit into from
Sep 18, 2023
Merged

Conversation

lewtun
Copy link
Member

@lewtun lewtun commented Sep 8, 2023

In #726 we replaced the RewardTrainer.args with a dedicated RewardConfig to collect all hyperparameters in a dedicated class (in particular max_length).

Unfortunately, that implementation wasn't backwards compatible because RewardTrainer.args was of type transformers.TrainingArguments and that object doesn't have the max_length attribute. This meant that part of the logic which checks for the presence of args.max_length would throw an error for any users who hadn't updated their code to use RewardConfig.

This PR fixes that by first checking the type of RewardTrainer.args and raising a warning if it's transformers.TrainingArguments.

Happy to add a unit test for this, but I felt it was a bit of overkill.

@HuggingFaceDocBuilderDev
Copy link

HuggingFaceDocBuilderDev commented Sep 8, 2023

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
Copy link
Member Author

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

Copy link
Contributor

@younesbelkada younesbelkada left a 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:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if type(args) == TrainingArguments:
if isinstance(args, TrainingArguments):

Copy link
Member Author

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 :)

Copy link
Contributor

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:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if type(args) == TrainingArguments:
if isinstance(args, TrainingArguments):

@younesbelkada younesbelkada merged commit 9a8d52c into main Sep 18, 2023
@younesbelkada younesbelkada deleted the fix-rm-args branch September 18, 2023 11:54
Copy link
Contributor

@younesbelkada younesbelkada left a 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 !

kushal-tri pushed a commit to kushalarora/trl that referenced this pull request Sep 19, 2023
lapp0 pushed a commit to lapp0/trl that referenced this pull request May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants