class_docstr: Ray actor. The code here will run in each node allocated by Ray.
code: def run(
      self, master_addr, master_port, node_rank, dist_world_size, args
  ):
      processes = []
  
      # set PyTorch distributed related environmental variables
      current_env = os.environ.copy()
      current_env["MASTER_ADDR"] = master_addr
      current_env["MASTER_PORT"] = str(master_port)
      current_env["WORLD_SIZE"] = str(dist_world_size)
  
      if (
          "OMP_NUM_THREADS" not in os.environ
          and args.nproc_per_node > 1
      ):
          current_env["OMP_NUM_THREADS"] = str(1)
          print(
              "*****************************************\n"
              "Setting OMP_NUM_THREADS environment variable for each process "
              "to be {} in default, to avoid your system being overloaded, "
              "please further tune the variable for optimal performance in "
              "your application as needed. \n"
              "*****************************************".format(
                  current_env["OMP_NUM_THREADS"]
              )
          )
  
      # Set the init_method and rank of the process for distributed training.
      for local_rank in range(0, args.nproc_per_node):
          # each process's rank
          dist_rank = args.nproc_per_node * node_rank + local_rank
          current_env["RANK"] = str(dist_rank)
          current_env["LOCAL_RANK"] = str(local_rank)
  
          # spawn the processes
          with_python = not args.no_python
          cmd = []
          if with_python:
              cmd = [sys.executable, "-u"]
              if args.module:
                  cmd.append("-m")
          else:
              if not args.use_env:
                  raise ValueError(
                      "When using the '--no_python' flag, "
                      "you must also set the '--use_env' flag."
                  )
              if args.module:
                  raise ValueError(
                      "Don't use both the '--no_python' flag"
                      "and the '--module' flag at the same time."
                  )
  
          cmd.append(args.training_script)
  
          if not args.use_env:
              cmd.append("--local_rank={}".format(local_rank))
  
          cmd.extend(args.training_script_args)
          process = subprocess.Popen(cmd, env=current_env)
          processes.append(process)
  
      for process in processes:
          process.wait()
          if process.returncode != 0:
              raise subprocess.CalledProcessError(
                  returncode=process.returncode, cmd=cmd
              )
  
file_path: ClassyVision/classy_vision/distributed/launch_ray.py
imports: import logging
  import os
  import socket
  import subprocess
  import sys
  import time
  from argparse import ArgumentParser, REMAINDER
  from contextlib import closing
  import ray
label_desc: Use image node_id 1 for calling the NodeLaunchActor obj's underlying member method code with example usage: obj.run(master_addr, master_port, node_rank, dist_world_size, args) without return types