File tree Expand file tree Collapse file tree
src/megatron/bridge/training Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1717
1818from megatron .bridge .data .utils import get_dataset_provider
1919from megatron .bridge .training .callbacks import Callback , CallbackManager , normalize_callbacks
20- from megatron .bridge .training .checkpointing import save_checkpoint
2120from megatron .bridge .training .config import ConfigContainer , runtime_config_update
2221from megatron .bridge .training .eval import evaluate_and_print_results
2322from megatron .bridge .training .forward_step_func_types import ForwardStepCallable
@@ -154,17 +153,6 @@ def _pretrain(
154153 )
155154
156155 barrier_and_log ("after training is done" )
157- ckpt_config = config .checkpoint
158- if ckpt_config .save and state .train_state .step != 0 and ckpt_config .save_interval != 0 :
159- save_checkpoint (
160- state ,
161- model ,
162- optimizer ,
163- scheduler ,
164- state .train_state .floating_point_operations_so_far ,
165- ckpt_context ,
166- train_data_iterator = train_data_iterator ,
167- )
168156
169157 else :
170158 print_rank_0 ("skipping training ..." )
Original file line number Diff line number Diff line change @@ -588,6 +588,27 @@ def train(
588588 if should_exit :
589589 break
590590
591+ # Save final checkpoint when training completes normally and the last
592+ # step wasn't already persisted by the interval-based save inside
593+ # checkpoint_and_decide_exit.
594+ if not should_exit :
595+ ckpt_config = config .checkpoint
596+ if (
597+ ckpt_config .save
598+ and global_state .train_state .step != 0
599+ and ckpt_config .save_interval != 0
600+ and (ckpt_config .save_interval is None or global_state .train_state .step % ckpt_config .save_interval != 0 )
601+ ):
602+ save_checkpoint_and_time (
603+ global_state ,
604+ model ,
605+ optimizer ,
606+ scheduler ,
607+ num_floating_point_operations_so_far ,
608+ checkpointing_context ,
609+ train_data_iterator = train_data_iterator ,
610+ )
611+
591612 _delete_cuda_graphs (cuda_graph_helper )
592613
593614 # Flush TensorBoard, WandB writers and one-logger.
You can’t perform that action at this time.
0 commit comments