From 6eb47d1b340ed205e5c260a15bb0347961df7607 Mon Sep 17 00:00:00 2001 From: "Yushun Xiang@macbook" Date: Mon, 3 Nov 2025 22:36:35 +0800 Subject: [PATCH 1/2] Enhance ProgressCallback to initialize training bar with current step --- swift/trainers/callback.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/swift/trainers/callback.py b/swift/trainers/callback.py index be299a8fe9..2a70d40970 100644 --- a/swift/trainers/callback.py +++ b/swift/trainers/callback.py @@ -44,9 +44,12 @@ def add_train_message(logs, state, start_time) -> None: class ProgressCallbackNew(ProgressCallback): def on_train_begin(self, args, state, control, **kwargs): + initial_step = state.global_step if state.global_step is not None else 0 if state.is_world_process_zero: - self.training_bar = tqdm(desc='Train', total=state.max_steps, dynamic_ncols=True) - self.current_step = 0 + bar_initial = min(initial_step, state.max_steps) if state.max_steps else initial_step + self.training_bar = tqdm( + desc='Train', total=state.max_steps, initial=bar_initial, dynamic_ncols=True) + self.current_step = initial_step self.start_time = time.time() def on_prediction_step(self, args, state: TrainerState, control, eval_dataloader=None, **kwargs): From efc8bbd668024fc5b49c53f62f57230adbfa88e3 Mon Sep 17 00:00:00 2001 From: "Yushun Xiang@macbook" Date: Tue, 4 Nov 2025 01:10:17 +0800 Subject: [PATCH 2/2] pre-commit format --- swift/trainers/callback.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/swift/trainers/callback.py b/swift/trainers/callback.py index 2a70d40970..d77464e43c 100644 --- a/swift/trainers/callback.py +++ b/swift/trainers/callback.py @@ -44,11 +44,10 @@ def add_train_message(logs, state, start_time) -> None: class ProgressCallbackNew(ProgressCallback): def on_train_begin(self, args, state, control, **kwargs): - initial_step = state.global_step if state.global_step is not None else 0 + initial_step = state.global_step or 0 if state.is_world_process_zero: bar_initial = min(initial_step, state.max_steps) if state.max_steps else initial_step - self.training_bar = tqdm( - desc='Train', total=state.max_steps, initial=bar_initial, dynamic_ncols=True) + self.training_bar = tqdm(desc='Train', total=state.max_steps, initial=bar_initial, dynamic_ncols=True) self.current_step = initial_step self.start_time = time.time()