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

[Unified checkpoint] update optimizer async save signal #8975

Merged
merged 1 commit into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion paddlenlp/trainer/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2305,7 +2305,12 @@
self._save_ckpt_func(state_dict, save_path)
with open(saved_signal_path, mode="w+") as f:
f.write("1")

else:
if self.args.unified_checkpoint and "async_save" in self.args.unified_checkpoint_config:
global_rank = paddle.distributed.get_rank() if paddle.distributed.get_world_size() > 1 else -1
paddle.save(global_rank, os.path.join(output_dir, f".optimizer_weight.done.{global_rank}"))
if "skip_save_model_weight" not in self.args.unified_checkpoint_config:
paddle.save(global_rank, os.path.join(output_dir, f".master_weight.done.{global_rank}"))

Check warning on line 2313 in paddlenlp/trainer/trainer.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/trainer.py#L2309-L2313

Added lines #L2309 - L2313 were not covered by tests
if self.args.should_save or self.args.use_expert_parallel:
if not self.args.use_hybrid_parallel:
logger.info("Saving optimizer files.")
Expand Down
3 changes: 2 additions & 1 deletion paddlenlp/trainer/trainer_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
from ..transformers.tokenizer_utils_base import BatchEncoding
from ..utils.import_utils import is_paddle_cuda_available, is_psutil_available
from ..utils.log import logger
from .utils.helper import distributed_file

__all__ = [
"TrainOutput",
Expand Down Expand Up @@ -273,7 +274,7 @@
if os.path.exists(os.path.join(current_path, ".checkpoint_done")):
return current_path
else:
saving_info = paddle.load(os.path.join(current_path, ".saving_info"))
saving_info = paddle.load(distributed_file(os.path.join(current_path, ".saving_info")))

Check warning on line 277 in paddlenlp/trainer/trainer_utils.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/trainer_utils.py#L277

Added line #L277 was not covered by tests
pre_world_size = saving_info.get("world_size", 1)
ignore_save_lr_and_optim = saving_info.get("ignore_save_lr_and_optim", False)
skip_save_model_weight = saving_info.get("skip_save_model_weight", False)
Expand Down
Loading