22
33"""Main function for launching the trainer."""
44
5+ import os
56import pathwaysutils
67import functools
78from absl import app , flags
1011from axlearn .common import launch , launch_trainer , measurement , utils
1112from axlearn .common .config import config_for_function
1213
13- enable_elastic_training = True
14- enable_pause_resume = False
15- enable_replica_resize = True
14+
15+ # Env variables to control Elastic training functionality
16+ ENABLED_PAUSE_RESUME = os .environ ['ENABLED_PAUSE_RESUME' ] if "ENABLED_PAUSE_RESUME" in os .environ else False
17+ ENABLED_REPLICA_RESIZE = os .environ ['ENABLED_REPLICA_RESIZE' ] if "ENABLED_REPLICA_RESIZE" in os .environ else False
1618
1719
1820def main (_ ):
@@ -22,8 +24,9 @@ def main(_):
2224 # trainer_config.set(recorder=config_for_function(lambda: measurement.global_recorder))
2325 # measurement.start_monitoring()
2426 clean_up_checkpoints = functools .partial (utils .clean_up_checkpoints , checkpoint_dir = trainer_config .dir )
25- if pathwaysutils .is_pathways_backend_used () and enable_elastic_training :
26-
27+ enabled_elastic_training = True if ENABLED_PAUSE_RESUME or ENABLED_REPLICA_RESIZE else False
28+ if pathwaysutils .is_pathways_backend_used () and enabled_elastic_training :
29+ print ("Pathways backend with elastic training being used" )
2730 def train ():
2831 # measurement.initialize(flags.FLAGS)
2932 # launch.setup()
@@ -36,7 +39,7 @@ def train():
3639
3740 # utils.elastic_manager.live_devices = live_devices()
3841
39- if enable_pause_resume :
42+ if ENABLED_PAUSE_RESUME :
4043 print ("Pathways backend with pause resume being used" )
4144 train = utils .elastic_manager .pause_resume (
4245 max_retries = 10 , # Handle up to 10 disruptions before restarting
@@ -45,8 +48,8 @@ def train():
4548 # on_elastic_event_callback=clean_up_checkpoints,
4649 )(train )
4750
48- if enable_replica_resize :
49-
51+ if ENABLED_REPLICA_RESIZE :
52+ print ( "Pathways backend with replica resize being used" )
5053 def pre_callback ():
5154 # Wait up to 1 minute before starting if there are any inactive slices
5255 if utils .elastic_manager .inactive_slice_indices :
0 commit comments