4545
4646import torch
4747
48+ ########## FlagScale Begin ##########
4849from flagscale .train import gpu_heartbeat
50+ ########## FlagScale End ##########
4951
5052from . import arguments , global_vars
5153from .utils import is_rank0 , print_rank_0
@@ -78,10 +80,12 @@ def get_rank_monitor_client() -> Optional[Any]:
7880
7981def setup () -> None :
8082 """Initialize fault tolerance before initialize_megatron"""
83+ ########## FlagScale Begin ##########
8184 # GPU progress heartbeat is independent of the NVIDIA FT package. The runner
8285 # enables it through environment variables, and this call is a no-op otherwise.
8386 gpu_heartbeat .initialize_from_env ()
8487 gpu_heartbeat .set_phase ("setup" )
88+ ########## FlagScale End ##########
8589 args = arguments .parse_args (ignore_unknown_args = True )
8690 if not args .enable_ft_package :
8791 return
@@ -127,7 +131,9 @@ def setup() -> None:
127131
128132def on_training_step_start () -> None :
129133 """Should be called before each training step"""
134+ ########## FlagScale Begin ##########
130135 gpu_heartbeat .set_phase ("train" )
136+ ########## FlagScale End ##########
131137 rmon_cli = get_rank_monitor_client ()
132138 if rmon_cli is not None :
133139 global _is_setup_section_open
@@ -143,11 +149,13 @@ def on_training_step_start() -> None:
143149
144150def on_training_step_end () -> None :
145151 """Should be called after each training step"""
152+ ########## FlagScale Begin ##########
146153 # This is the only hot-path operation: an in-memory progress counter update.
147154 # The background publisher performs all JSON serialization and file I/O.
148155 gpu_heartbeat .mark_training_progress (
149156 getattr (global_vars .get_args (), "curr_iteration" , None )
150157 )
158+ ########## FlagScale End ##########
151159 rmon_cli = get_rank_monitor_client ()
152160 if rmon_cli is not None :
153161 global _seen_tr_iters_cnt
@@ -158,7 +166,9 @@ def on_training_step_end() -> None:
158166
159167def on_eval_step_start () -> None :
160168 """Should be called before each validation step"""
169+ ########## FlagScale Begin ##########
161170 gpu_heartbeat .set_phase ("eval" )
171+ ########## FlagScale End ##########
162172 rmon_cli = get_rank_monitor_client ()
163173 if rmon_cli is not None :
164174 global _is_setup_section_open
@@ -172,7 +182,9 @@ def on_eval_step_start() -> None:
172182
173183def on_eval_step_end () -> None :
174184 """Should be called after each validation step"""
185+ ########## FlagScale Begin ##########
175186 gpu_heartbeat .mark_progress ("eval" )
187+ ########## FlagScale End ##########
176188 rmon_cli = get_rank_monitor_client ()
177189 if rmon_cli is not None :
178190 global _curr_eval_iter_idx
@@ -183,7 +195,9 @@ def on_eval_step_end() -> None:
183195
184196def on_checkpointing_start () -> None :
185197 """Should be called before each checkpoint-saving-related operation."""
198+ ########## FlagScale Begin ##########
186199 gpu_heartbeat .set_phase ("checkpointing" )
200+ ########## FlagScale End ##########
187201 rmon_cli = get_rank_monitor_client ()
188202 if rmon_cli is not None :
189203 rmon_cli .start_section ("checkpointing" )
@@ -195,7 +209,9 @@ def on_checkpointing_end(is_async_finalization: bool) -> None:
195209 Args:
196210 is_async_finalization (bool): true if called after an async checkpointing finalization
197211 """
212+ ########## FlagScale Begin ##########
198213 gpu_heartbeat .mark_progress ("checkpointing" )
214+ ########## FlagScale End ##########
199215 rmon_cli = get_rank_monitor_client ()
200216 if rmon_cli is not None :
201217 rmon_cli .end_section ("checkpointing" )
@@ -231,7 +247,9 @@ def shutdown() -> None:
231247 rmon_cli .shutdown_workload_monitoring ()
232248 print_rank_0 ("FT: closed." )
233249 _GLOBAL_RANK_MONITOR_CLIENT = None
250+ ########## FlagScale Begin ##########
234251 gpu_heartbeat .shutdown ()
252+ ########## FlagScale End ##########
235253
236254
237255def _load_state_if_exists ():
0 commit comments