Skip to content

[AutoParallel] Refine save and load ckpt for auto_trainer #8828

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

Merged
merged 2 commits into from
Aug 1, 2024
Merged
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
21 changes: 19 additions & 2 deletions paddlenlp/trainer/auto_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
MODEL_NAME = "model"
OPTIMIZER_NAME = "optimizer"
DIST_CKPT_PATH = "dist_ckpt"
FREE_SVAE_LOAD_KEY_PATTERNS = ["learning_rate_", "gradient_merge_", "@GRAD@MERG", "eager_tmp"]

Check warning on line 52 in paddlenlp/trainer/auto_trainer.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/auto_trainer.py#L52

Added line #L52 was not covered by tests


class AutoTrainer(Trainer):
Expand Down Expand Up @@ -543,7 +544,15 @@

if self.args.should_save_model_state:
if self.args.to_static:
state_dict = model.state_dict()
opt_state_dict = {

Check warning on line 547 in paddlenlp/trainer/auto_trainer.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/auto_trainer.py#L547

Added line #L547 was not covered by tests
key: value
for key, value in model.state_dict("opt").items()
if not any(keyword in key for keyword in FREE_SVAE_LOAD_KEY_PATTERNS)
}
state_dict = {

Check warning on line 552 in paddlenlp/trainer/auto_trainer.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/auto_trainer.py#L552

Added line #L552 was not covered by tests
MODEL_NAME: model.state_dict("param"),
OPTIMIZER_NAME: opt_state_dict,
}
else:
optim_state_dict = self.optimizer.state_dict()
optim_state_dict.pop("LR_Scheduler", None)
Expand Down Expand Up @@ -669,7 +678,15 @@
raise ValueError(f"Can't find a valid checkpoint at {resume_from_checkpoint}")

if self.args.to_static:
state_dict = self.model_wrapped.state_dict()
opt_state_dict = {

Check warning on line 681 in paddlenlp/trainer/auto_trainer.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/auto_trainer.py#L681

Added line #L681 was not covered by tests
key: value
for key, value in self.model_wrapped.state_dict("opt").items()
if not any(keyword in key for keyword in FREE_SVAE_LOAD_KEY_PATTERNS)
}
state_dict = {

Check warning on line 686 in paddlenlp/trainer/auto_trainer.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/trainer/auto_trainer.py#L686

Added line #L686 was not covered by tests
MODEL_NAME: self.model_wrapped.state_dict("param"),
OPTIMIZER_NAME: opt_state_dict,
}
else:
model_state_dict = self.model_wrapped.state_dict()
optim_state_dict = self.optimizer.state_dict()
Expand Down
Loading