Accelerate ND-Parallel: A guide to Efficient Multi-GPU Training
Accelerate's ParallelismConfig, also exposed through Axolotl config fields, lets you compose data parallelism, FSDP, tensor parallelism and context parallelism in one training setup. The guide explains how each strategy trades memory for communication. FSDP shards weights, gradients and optimizer states and gathers each layer when needed. Tensor parallelism splits linear layers column-wise then row-wise so only one all-reduce is required, which makes it best kept within a single NVLink node. Context parallelism shards the sequence and uses RingAttention so very long contexts fit in memory. It then covers hybrid combinations such as HSDP, FSDP+TP and FSDP+CP, with guidance on matching each parallelism degree to intra-node versus inter-node bandwidth.
Related posts
- Fully Sharded Data Parallel: faster AI training with fewer GPUs
Meta Engineering hardMasterFully Sharded Data Parallel (FSDP) shards model parameters, gradients and optimizer states across data-parallel GPU workers. It does this by decomposing DDP's all-reduce into reduce-scatter and all-gather steps, gathering each layer's full weights just in time for the forward and backward passes and then discarding them. It produces results identical to PyTorch DDP, overlaps communication with computation, can offload optimizer state to CPU, and is meant to scale to trillions of parameters. It is available through FairScale, fairseq, VISSL and PyTorch Lightning, with caveats around nested wrapping, consistent weight initialization, optimizer parameter groups, mixed precision and checkpointing.
- Accelerate Large Model Training using PyTorch Fully Sharded Data Parallel
Hugging Face hardMasterHugging Face Accelerate exposes PyTorch FullyShardedDataParallel (FSDP), which shards parameters, gradients and optimizer states across GPUs (ZeRO stage 2/3) with optional CPU offload, and does so without changes to training code. On 2x24GB Titan RTX GPUs, FSDP gives 2-3x larger batch sizes than DDP for GPT-2 Large. It also trains GPT-2 XL (1.5B), which DDP cannot fit even at batch size 1, and with CPU offload it can do so on a single GPU. DDP with FP16 remained fastest in wall-clock time. Practical caveats: tune the auto-wrap min_num_params, prepare the model before creating the optimizer because parameter flattening loses parameter groups, and note that mixed precision was not yet supported.
- Ulysses Sequence Parallelism: Training with Million-Token Contexts
Hugging Face hardMasterUlysses Sequence Parallelism, part of Snowflake's Arctic Long Sequence Training protocol, enables training on contexts of hundreds of thousands to millions of tokens. Each GPU holds a shard of the sequence, and all-to-all collectives regroup the data so each GPU computes attention over every position for a subset of heads. That costs O(n·d/P) communication per GPU, versus O(n·d) over P−1 serial hops for Ring Attention. Ulysses is now integrated into Hugging Face Accelerate (ParallelismConfig with a DeepSpeed backend), the Transformers Trainer and TRL's SFTTrainer, which handle dataloader sharding, shifted labels and token-weighted loss aggregation automatically. Practical guidance covers padding to a multiple of sp_size, the num_heads ≥ sp_size constraint, choosing FlashAttention versions, ZeRO-3 offload, expandable_segments, Liger-Kernel, and balancing SP against DP across GPU counts.
- Accelerate Large Model Training using DeepSpeed
Hugging Face mediumAdeptHugging Face Accelerate can enable DeepSpeed ZeRO data parallelism, which shards optimizer states, gradients and parameters across GPUs and optionally offloads them to CPU, with no or minimal code changes. On two 24GB Titan RTX GPUs, ZeRO Stage-2 allowed 5x larger batches than DDP for DeBERTa-XL (900M) and gave about a 3.5x training speedup with no accuracy loss. BlenderBot-400M fine-tuning saw 2x batch size and a ~1.44x training speedup. ZeRO Stage-3 with CPU offload made GPT-2 XL (1.5B) trainable at batch size 16 where DDP ran out of memory even at batch size 1. The post includes the accelerate config, DeepSpeed JSON configs, and the DummyOptim/DummyScheduler changes needed when the optimizer and scheduler are defined in the DeepSpeed config.
- From DeepSpeed to FSDP and Back Again with Hugging Face Accelerate
Hugging Face hardMasterDeepSpeed ZeRO-3 and PyTorch FSDP gave different training results on Mistral-7B loaded in bfloat16 because DeepSpeed silently upcasts flattened parameters and optimizer state to fp32, while FSDP keeps them in the loaded dtype. That made the same learning rate converge on one backend and stall on the other. Hugging Face Accelerate 0.30.0 adds automatic fp32 upcasting for FSDP when mixed precision is enabled, so FSDP can run either in a DeepSpeed-like mixed-precision mode or in a low-precision mode for memory-constrained setups. In that aligned mode, throughput on four A100s with Granite 7B is roughly equal: about 3159 vs 3095 tokens/sec/GPU and an MFU of 0.41 vs 0.40.