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

resuming checkpoint without lr schedule or optimizer state #253

Merged
merged 1 commit into from
Dec 3, 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
2 changes: 2 additions & 0 deletions src/nanotron/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,8 @@ class CheckpointsArgs:
save_initial_state: Optional[bool] = False
save_final_state: Optional[bool] = False
resume_checkpoint_path: Optional[xPath] = None
load_lr_scheduler: Optional[bool] = True
load_optimizer: Optional[bool] = True
checkpoints_path_is_shared_file_system: Optional[bool] = False

def __post_init__(self):
Expand Down
12 changes: 8 additions & 4 deletions src/nanotron/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def __init__(
optimizer_args=self.config.optimizer,
parallel_context=self.parallel_context,
)
if self.init_checkpoint_path is not None:
if self.init_checkpoint_path is not None and self.config.checkpoints.load_optimizer:
load_optimizer(
optimizer=self.optimizer,
parallel_context=self.parallel_context,
Expand All @@ -206,7 +206,7 @@ def __init__(
lr_scheduler_args=self.config.optimizer.learning_rate_scheduler,
total_training_steps=self.config.tokens.train_steps,
)
if self.init_checkpoint_path is not None:
if self.init_checkpoint_path is not None and self.config.checkpoints.load_lr_scheduler:
load_lr_scheduler(
lr_scheduler=self.lr_scheduler,
is_zero=self.config.optimizer.zero_stage,
Expand All @@ -215,7 +215,7 @@ def __init__(
)

# Define iteration start state
if self.init_checkpoint_path is not None:
if self.init_checkpoint_path is not None and self.config.checkpoints.load_lr_scheduler:
Copy link
Member

Choose a reason for hiding this comment

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

is this only lr related?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think when you want to do a new lr schedule, you also want to do a different data stages + reset the "last_train_step" argument

checkpoint_metadata = load_meta(
parallel_context=self.parallel_context, root_folder=self.init_checkpoint_path
)
Expand Down Expand Up @@ -553,7 +553,11 @@ def training_step(
handle = None

# Move optimizer states back to GPU before optimizer step
if self.init_checkpoint_path is not None and self.iteration_step == self.initial_iter_step:
if (
self.init_checkpoint_path is not None
and self.config.checkpoints.load_optimizer
and self.iteration_step == self.initial_iter_step
):
state_dict_to_device(self.optimizer.state_dict(), "cuda")

before_optim_step_sanity_checks(
Expand Down
Loading