Fix model checkpoint saving issue when using PEFT #727
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.
What does this PR do?
This PR fixes an issue in the model checkpoint saving process when using Parameter-Efficient Fine-Tuning (PEFT) in distributed training environments. Previously, if the directory for saving adapters already existed, an error would occur, particularly in distributed scenarios where multiple processes might try to create the directory simultaneously. This PR ensures that the directory creation is handled safely by using the
exist_ok=True
flag.Error Example
In distributed training environments, the following error could occur if the directory already existed:
This error is now handled by using the
exist_ok=True
parameter when creating directories, preventing failures if the directory already exists.How does this PR fix the problem?
This PR introduces the
exist_ok=True
flag in the directory creation step to handle the case where the directory already exists. The relevant code snippet is:By using
exist_ok=True
, theos.makedirs
call will not raise an error if the directory already exists, making it safe for distributed environments.Motivation and Context
In distributed training environments, multiple processes might attempt to save model checkpoints to the same directory. If the directory already exists, this can lead to an interruption in the training process. This PR resolves the issue by ensuring that the directory creation step is non-blocking and error-free.
Impact
This change makes the checkpoint-saving mechanism more robust when using PEFT in distributed training scenarios, eliminating errors related to existing directories and improving the reliability of the training process.