Make output_dir
Optional in TrainingArguments
#27866
#35735
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.
Description
This PR addresses an issue where specifying an
output_dir
was mandatory inTrainingArguments
. This behavior could be confusing or cumbersome in scenarios where users do not necessarily need a dedicated output directory or prefer to let the library handle default paths.By making
output_dir
optional and defaulting to a temporary directory (named"tmp_trainer"
) when not specified, we simplify the API usage. If a user later needs to track outputs in a dedicated directory, they can still provide a valid path.Fixes : #27866
Proposed Solution
• Allow
output_dir
to be set toNone
.• Default to a built-in location (e.g.,
"tmp_trainer"
) ifNone
is provided.Implementation
The changes introduce a check to automatically assign a default directory if none is specified. This preserves backward compatibility for users already specifying
output_dir
while improving the experience for those who prefer a simpler workflow.Testing
• Added a test covering the scenario when
output_dir
is not provided.• Verified existing tests using a custom
output_dir
are unaffected.• Extended tests to ensure the directory is only created when needed (depending on the save strategy).
Screenshots
Below is a screenshot of all testcases passing :
cc : @ArthurZucker @Rocketknight1