SuperAPI AI Directory

distributed-training-guide

Best practices & guides on how to write distributed pytorch training code.

Open website

About this tool

Purpose

This guide aims to help developers master how to write distributed PyTorch training code and solve common problems in large-scale neural network training, such as how to scale a single-GPU training script to multiple GPUs or multiple nodes, how to diagnose hangs or errors during training, how to schedule training jobs on a cluster, how to tune hyperparameters, and how to log effectively.

Main Capabilities

The guide is organized by chapters, each containing a README.md and a train_llm.py script, progressively upgrading the training code:

  • Chapter 1: A standard causal language model training script that can run on a single GPU.
  • Chapter 2: Upgrade the script to support multiple GPUs and use DDP (Distributed Data Parallel).
  • Chapter 3: Introduce how to launch training jobs on a multi-node cluster.
  • Chapter 4: Upgrade the script to use FSDP (Fully Sharded Data Parallel) to optimize memory usage.
  • Chapter 5: Upgrade the script to train the Llama-405b model.
  • Chapter 6: Upgrade the single-GPU training script to support tensor parallelism (TP).
  • Chapter 7: Upgrade the TP training script to use 2D parallelism (FSDP + TP). In addition, it also includes introductions to alternative frameworks (these frameworks are all compatible with PyTorch at the underlying level), best practices for diagnosing errors, and topics related to distributed training.

How to Use

The project is written entirely in standard PyTorch, relying only on the transformers and datasets libraries to handle models and data, and the distributed parts are all implemented by PyTorch. Before use, you need to clone the repository and configure a virtual environment. The tutorial uses wandb as the experiment tracking tool. The README for each chapter discusses the high-level concepts of distributed training and the code changes introduced in that chapter.

Applicable Scenarios

It is suitable for developers who need to train or fine-tune large causal language models (such as GPT, Llama), especially scenarios where they want to migrate from a single GPU to multiple GPUs or a multi-node cluster, or need to optimize memory usage or diagnose cluster training errors.

Limitations

The guide does not provide specific fees, prices, or platform information. Other feature details are not yet provided.