Skip to content

Conversation

@gante
Copy link
Contributor

@gante gante commented Mar 15, 2024

What does this PR do?

Fixes #29665

We don't allow saving bad generation config files (i.e. ones whose validation has warnings or exceptions). This check was only done at save time, which happens AFTER training. This PR introduces the same check in the trainer's __init__, to fail early (and before spending time/$)

@gante gante requested review from amyeroberts and muellerzr March 15, 2024 11:00
@gante gante changed the title Trainer: fail early in the presence of a unsavable generation_config Trainer: fail early in the presence of an unsavable generation_config Mar 15, 2024
@HuggingFaceDocBuilderDev

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.

Copy link
Contributor

@amyeroberts amyeroberts left a comment

Choose a reason for hiding this comment

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

Thanks for quickly adding this!

with warnings.catch_warnings(record=True) as caught_warnings:
gen_config.validate()
if len(caught_warnings) > 0:
raise ValueError(str([w.message for w in caught_warnings]))
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this properly separate out the messages? We might want to add a line break in between the w.message elements

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it prints a list of str, so it is easy to separate the messages :)

a = ["foo", "bar", "baz"]
raise ValueError(str([msg for msg in a]))
# ValueError: ['foo', 'bar', 'baz']

@gante gante merged commit c47fcd0 into huggingface:main Mar 15, 2024
@gante gante deleted the fail_trainer_early branch March 15, 2024 12:59
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.

GenerationConfig.from_pretrained raise ValueError after training, maybe raise it earlier?

3 participants