2121from hydra .core .hydra_config import HydraConfig
2222from omegaconf import DictConfig , OmegaConf
2323
24+ from flagscale .runner .diagnostics import diagnostic_command_body
2425from flagscale .runner .elastic .monitor_service import MonitorService
2526from flagscale .runner .heartbeat .config import (
2627 HeartbeatLaunchConfig ,
2728 prepare_heartbeat_launch_config ,
2829)
2930from flagscale .runner .runner_base_legacy import JobStatus , RunnerBase
31+ from flagscale .runner .tracing .config import TraceLaunchConfig , prepare_trace_launch_config
3032from flagscale .runner .utils import (
3133 find_latest_stdout_log ,
3234 flatten_dict_to_args ,
@@ -212,6 +214,8 @@ def _get_runner_cmd_train(
212214 del runner_args ["enable_monitoring" ]
213215 if "heartbeat" in runner_args :
214216 del runner_args ["heartbeat" ]
217+ if "tracing" in runner_args :
218+ del runner_args ["tracing" ]
215219 runner_args ["rdzv_id" ] = rdzv_id
216220 # runner_args["master_addr"] = master_addr
217221 # runner_args["master_port"] = master_port
@@ -245,8 +249,10 @@ def _generate_run_script_train(
245249 pkg_dir = None ,
246250 enable_monitoring = False ,
247251 heartbeat_config = None ,
252+ trace_config = None ,
248253):
249254 heartbeat_config = heartbeat_config or HeartbeatLaunchConfig (enabled = False )
255+ trace_config = trace_config or TraceLaunchConfig (enabled = False )
250256 system_config = config .train .system
251257 logging_config = config .train .system .logging
252258
@@ -293,6 +299,10 @@ def _generate_run_script_train(
293299 f .write (f"{ line } \n " )
294300 if heartbeat_config .enabled :
295301 f .write ("\n " )
302+ for line in trace_config .shell_setup_lines (node_rank ):
303+ f .write (f"{ line } \n " )
304+ if trace_config .enabled :
305+ f .write ("\n " )
296306 f .write (f'cmd="{ cmd } "\n ' )
297307 f .write ("\n " )
298308 if enable_monitoring :
@@ -315,7 +325,7 @@ def _generate_run_script_train(
315325 f .write (f'echo "Monitor service started in background for { host } (node { node_rank } )"\n ' )
316326 f .write ("\n " )
317327
318- command_body = heartbeat_config . training_command_body (node_rank )
328+ command_body = diagnostic_command_body (node_rank , heartbeat_config , trace_config )
319329 if background :
320330 f .write (
321331 f'nohup bash -c "{ command_body } " >> { host_output_file } 2>&1 & echo $! > { host_pid_file } \n '
@@ -331,8 +341,9 @@ def _generate_run_script_train(
331341 return host_run_script_file
332342
333343
334- def _generate_stop_script_train (config , host , node_rank , heartbeat_config = None ):
344+ def _generate_stop_script_train (config , host , node_rank , heartbeat_config = None , trace_config = None ):
335345 heartbeat_config = heartbeat_config or HeartbeatLaunchConfig (enabled = False )
346+ trace_config = trace_config or TraceLaunchConfig (enabled = False )
336347 if getattr (config , "train" , None ):
337348 logging_config = config .train .system .logging
338349 else :
@@ -362,6 +373,8 @@ def _generate_stop_script_train(config, host, node_rank, heartbeat_config=None):
362373 f .write ("fi\n " )
363374 for line in heartbeat_config .stop_shell_lines (node_rank ):
364375 f .write (f"{ line } \n " )
376+ for line in trace_config .stop_shell_lines (node_rank ):
377+ f .write (f"{ line } \n " )
365378 f .write (f"{ after_stop } \n " )
366379 f .flush ()
367380 os .fsync (f .fileno ())
@@ -426,6 +439,9 @@ def _prepare(self):
426439 raise ValueError (f"Unsupported backend: { self .config .experiment .task .backend } " )
427440 self .rdzv_id = datetime .now ().strftime ("%Y%m%d_%H%M%S.%f" )
428441 self .heartbeat_config = prepare_heartbeat_launch_config (self .config , self .rdzv_id )
442+ self .trace_config = prepare_trace_launch_config (
443+ self .config , self .rdzv_id , self .heartbeat_config
444+ )
429445 self .user_envs = self .config .experiment .get ("envs" , {})
430446 self .user_script = self .config .experiment .task .entrypoint
431447 self .resources = parse_hostfile (self .config .experiment .runner .get ("hostfile" , None ))
@@ -484,6 +500,7 @@ def _run_each(
484500 pkg_dir = node_specific_config .get ("build_dir" , None ),
485501 enable_monitoring = enable_monitoring ,
486502 heartbeat_config = self .heartbeat_config ,
503+ trace_config = self .trace_config ,
487504 )
488505
489506 if host != "localhost" :
@@ -616,6 +633,7 @@ def _stop_each(self, host, node_rank):
616633 host ,
617634 node_rank ,
618635 self .heartbeat_config ,
636+ self .trace_config ,
619637 )
620638 logging_config = self .config .train .system .logging
621639
@@ -889,6 +907,9 @@ def _prepare(self):
889907 _update_config_train (self .config )
890908 self .rdzv_id = datetime .now ().strftime ("%Y%m%d_%H%M%S.%f" )
891909 self .heartbeat_config = prepare_heartbeat_launch_config (self .config , self .rdzv_id )
910+ self .trace_config = prepare_trace_launch_config (
911+ self .config , self .rdzv_id , self .heartbeat_config
912+ )
892913 if self .config .experiment .task .backend == "megatron" :
893914 self .user_args = _get_args_megatron (self .config )
894915 logger .info ("\n ************** configuration ***********" )
@@ -922,6 +943,7 @@ def _run_each(
922943 cmd ,
923944 background = background ,
924945 heartbeat_config = self .heartbeat_config ,
946+ trace_config = self .trace_config ,
925947 )
926948
927949 run_local_command (f"bash { host_run_script_file } " , dryrun )
0 commit comments