Distributed

Utilities to start multiple processes from a single program invocation in distributed learning



PyTorch

PyTorch provides a Python module/console script to launch distributed runs. Visit PyTorch’s torchrun documentation for more details.

The following environment variables available in all processes can be accessed through the library:

JAX

According to the JAX documentation for multi-host and multi-process environments, JAX doesn’t automatically start multiple processes from a single program invocation.

Therefore, in order to make distributed learning simpler, this library provides a module (based on the PyTorch torch.distributed.run module) for launching multi-host and multi-process learning directly from the command line.

This module launches, in multiple processes, the same JAX Python program (Single Program, Multiple Data (SPMD) parallel computation technique) that defines the following environment variables for each process:

  • JAX_LOCAL_RANK (accessible via skrl.config.jax.local_rank): The rank of the worker/process (e.g.: GPU) within a local worker group (e.g.: node).

  • JAX_RANK (accessible via skrl.config.jax.rank): The rank (ID number) of the worker/process (e.g.: GPU) within a worker group (e.g.: across all nodes).

  • JAX_WORLD_SIZE (accessible via skrl.config.jax.world_size): The total number of workers/process (e.g.: GPUs) in a worker group (e.g.: across all nodes).

  • JAX_COORDINATOR_ADDR (accessible via skrl.config.jax.coordinator_address): IP address where process 0 will start a JAX coordinator service.

  • JAX_COORDINATOR_PORT (accessible via skrl.config.jax.coordinator_address): Port where process 0 will start a JAX coordinator service.


Usage

$ python -m skrl.utils.distributed.jax --help
usage: python -m skrl.utils.distributed.jax [-h] [--nnodes NNODES]
                        [--nproc-per-node NPROC_PER_NODE] [--node-rank NODE_RANK]
                        [--coordinator-address COORDINATOR_ADDRESS] script ...

JAX Distributed Training Launcher

positional arguments:
  script                Training script path to be launched in parallel
  script_args           Arguments for the training script

options:
  -h, --help            show this help message and exit
  --nnodes NNODES       Number of nodes
  --nproc-per-node NPROC_PER_NODE, --nproc_per_node NPROC_PER_NODE
                        Number of workers per node
  --node-rank NODE_RANK, --node_rank NODE_RANK
                        Node rank for multi-node distributed training
  --coordinator-address COORDINATOR_ADDRESS, --coordinator_address COORDINATOR_ADDRESS
                        IP address and port where process 0 will start a JAX service

API

skrl.utils.distributed.jax.launcher.launch()

Main entry point for launching distributed runs