Customization
This section describes how to customize TorchElastic to fit your
needs.
Launcher
The launcher program that ships with TorchElastic should be sufficient
for most use-cases (see torchrun (Elastic Launch)). You can implement
a custom launcher by programmatically creating an agent and passing it
specs for your workers as shown below.
# my_launcher.py
if name == "main":
     args = parse_args(sys.argv[1:])
     rdzv_handler = RendezvousHandler(...)
     spec = WorkerSpec(
         local_world_size=args.nproc_per_node,
         fn=trainer_entrypoint_fn,
         args=(trainer_entrypoint_fn args.fn_args,...),
         rdzv_handler=rdzv_handler,
         max_restarts=args.max_restarts,
         monitor_interval=args.monitor_interval,
     )
 agent = LocalElasticAgent(spec, start_method="spawn")
 try:
     run_result = agent.run()
     if run_result.is_failed():
         print(f"worker 0 failed with: run_result.failures[0]")
     else:
