Training a model on many GPUs takes several tools at once, and their names overlap. This page puts them in layers: TRL on Accelerate, on one of DDP, FSDP or DeepSpeed, on NCCL and CUDA. Then it shows where the memory goes on each GPU, lets you compute it for your own model and cluster, and ends with a guide to which tool to pick when.
Training · Distributed training
DDP, FSDP, DeepSpeed and TRL: the distributed training stack
You have a 7-billion-parameter model and four GPUs with 80 GB each. In bf16 the weights take only 14 GB. So why does the simplest multi-GPU setup run out of memory before it takes a single step?
The answer explains why there are so many tools with overlapping names. torchrun, DDP, FSDP, DeepSpeed, Accelerate and TRL are mostly not rivals. They sit at different layers of one stack, and a real training run often uses three or four of them at once: a TRL trainer, run by Accelerate, sharding the model with FSDP or DeepSpeed, talking over NCCL.
1 · Layers, not rivals
Each tool does one job in the stack
Read the stack from the bottom. GPUs do the arithmetic. NCCL moves tensors between them. One backend decides what each GPU stores: a full copy of everything (DDP) or a slice (FSDP, DeepSpeed). Accelerate lets one script run on any of those backends, and TRL supplies the post-training algorithms on top. A launcher on the side starts one process per GPU.
The stack · select a layerOnly one backend runs at a time
Post-training algorithms
Training orchestration
Backend: what each GPU stores
Distributed runtime
Hardware
GPU 0GPU 1GPU 2GPU 3
A common confusion: torchrun is not a training strategy. It only starts processes and tells each one its rank, so it can launch DDP and FSDP scripts alike. accelerate launch does the same job and also reads an Accelerate config file that names the backend.
2 · Where the memory goes
The weights are the smallest part of what training stores
With mixed-precision training and the AdamW optimizer, every parameter carries 16 bytes of model state, the estimate the ZeRO paper uses:
Parameters: 2 bytes (the bf16 weights used in the forward and backward passes).
Gradients: 2 bytes (bf16).
Optimizer states: 12 bytes (an fp32 master copy of the weights, plus AdamW's two fp32 running averages, 4 bytes each).
So the 7B model needs 7 × 16 = 112 GB of model state, which does not fit on one 80 GB GPU. Data parallelism with DDP does not help with this, because every GPU holds all 112 GB. Sharding does help: each GPU keeps only its own slice, and the copies that were duplicated go away.
Bytes of model state per parameter, per GPU · 4 GPUs
parameters 2 Bgradients 2 Boptimizer 12 B
Each box is drawn at the height of one full copy (16 bytes per parameter). A label such as 2/4 means the GPU holds the second of four shards. The hatched space is memory a GPU no longer needs. This shows only the state kept between steps. Activations, communication buffers and the layer a sharded GPU gathers for its current computation all come on top.
It is tempting to think ZeRO-3 means no GPU ever holds a whole layer. That misses how the computation works. Before a layer runs, the GPUs all-gather its parameters so each one holds the full layer for a moment. After the layer finishes they drop the borrowed parts again. Sharding saves memory between uses and pays for it in communication, which is why fast links between GPUs matter more for FSDP and ZeRO-3 than for DDP.
FSDP's full sharding corresponds to ZeRO-3: Hugging Face Accelerate's docs map FSDP's FULL_SHARD to ZeRO stage 3 and SHARD_GRAD_OP to ZeRO stage 2. In FSDP2 the same choice is the reshard_after_forward flag (True or False).
3 · Calculator
How much model state lands on each GPU
Pick a model size, a GPU count and the memory of one GPU. The bars use the same 16-bytes-per-parameter estimate. The dashed line marks one GPU's memory.
Model parameters
Number of GPUs
Memory per GPU
Assumes bf16 weights and gradients with fp32 master weights and AdamW states (16 bytes per parameter); 1 GB = 109 bytes. It leaves out activations, temporary gathered layers, communication buffers, a frozen reference model (DPO and GRPO often keep one) and the KV cache for generating rollouts. Real use is higher and depends on the implementation, so treat a bar that only just fits as a bar that does not fit.
4 · The four tools
What each one is good at and what it costs
torchrun + DDP
FSDP2
DeepSpeed
Accelerate / TRL
What it is
PyTorch's launcher plus its data-parallel wrapper
PyTorch's sharded data parallelism (fully_shard)
A training engine built around the ZeRO stages and offloading
Accelerate: runs one script on any backend. TRL: post-training trainers
Parameters
Full copy on every GPU
Sharded, gathered layer by layer
Full in ZeRO-1 and 2, sharded in ZeRO-3
Whatever the chosen backend does
Gradients
Full copy on every GPU
Sharded
Sharded in ZeRO-2 and 3
Optimizer states
Full copy (PyTorch's ZeroRedundancyOptimizer can shard them)
Sharded
Sharded in every ZeRO stage
CPU offload
No
Yes, all or nothing (CPUOffloadPolicy)
Yes: optimizer in stages 1 to 3, parameters in stage 3
Through the backend
NVMe offload
No
No
Yes, with ZeRO-3 (ZeRO-Infinity)
Through DeepSpeed
Training loop
You write it
You write it
You write it around the DeepSpeed engine
Accelerate: you write it. TRL: the trainer owns it
SFT, DPO, GRPO
Implement them yourself
Implement them yourself
Implement them yourself
Built into TRL
Main cost
Memory: adding GPUs never raises the largest model you can fit
Communication; distributed checkpoints
Config surface; harder to debug
Less direct control; dependency versions
torchrun and DDP
replicate, then average gradients
Every GPU holds the whole model and works on a different slice of the batch. During the backward pass DDP groups gradients into buckets and all-reduces each bucket as soon as it is ready, so communication overlaps with computation. Every copy then takes the same optimizer step and the copies stay identical.
torchrun --nproc_per_node=4 train.py
Good at
Simple to reason about and to debug
Often the fastest choice when the model fits comfortably
Full control of the loop, no extra dependencies
Costs
Duplicates parameters, gradients and optimizer states on every GPU
More GPUs means more throughput, never a bigger model
Best for
Small models, LoRA fine-tuning, vision models, custom-loss research
FSDP2 (Fully Sharded Data Parallel)
PyTorch-native sharding
FSDP splits parameters, gradients and optimizer states across GPUs, gathers each layer's parameters when it is needed, and frees them afterwards. FSDP2 is the current version. It represents each parameter as a DTensor sharded along its first dimension, where FSDP1 flattened groups of parameters into one FlatParameter. PyTorch's FSDP tutorial now marks FSDP1 as deprecated.
from torch.distributed.fsdp import fully_shard
for layer in model.layers:
fully_shard(layer) # shard each block first
fully_shard(model) # then the root module
optimizer = torch.optim.AdamW(model.parameters()) # build after sharding
Good at
Native PyTorch, launched with plain torchrun
Trains models that do not fit on one GPU
Custom loops; DTensor-based checkpoints (DCP); builds on the same DTensor layer as PyTorch's other parallelism tools
Costs
All-gathers and reduce-scatters on every step
Speed depends on links between GPUs and on how layers are wrapped
Checkpointing is more involved than with DDP
Best for
Full-parameter training and fine-tuning in your own code, or building a training framework
DeepSpeed
ZeRO stages and offload
DeepSpeed is a training engine, not only a sharding strategy. Its ZeRO stages add sharding step by step: stage 1 shards optimizer states, stage 2 adds gradients, stage 3 adds the parameters. ZeRO-Offload moves optimizer work to CPU memory, and ZeRO-Infinity, with stage 3, can push parameters and optimizer states out to CPU memory or NVMe drives.
Not every newer framework supports it (see section 5)
Best for
Large models on memory-limited clusters, and existing DeepSpeed pipelines
Hugging Face Accelerate and TRL
two libraries, two jobs
Accelerate handles device placement, mixed precision and backend setup, so the same script runs on one GPU, DDP, FSDP (set fsdp_version to 2 for FSDP2) or DeepSpeed. TRL builds post-training trainers on top: SFTTrainer, DPOTrainer, GRPOTrainer, RLOOTrainer, RewardTrainer and others. Transformers supplies the model architectures and PEFT supplies LoRA.
from datasets import load_dataset
from trl import GRPOTrainer
from trl.rewards import accuracy_reward
dataset = load_dataset("trl-lib/DeepMath-103K", split="train")
trainer = GRPOTrainer(
model="Qwen/Qwen2.5-0.5B-Instruct",
reward_funcs=accuracy_reward, # or your own Python functions
train_dataset=dataset,
)
trainer.train()
torchrun --nproc_per_node 8 train_grpo.py # how TRL's docs launch it
# DeepSpeed: pass deepspeed="zero3.json" in the training config
# FSDP or DeepSpeed through Accelerate: accelerate launch --config_file fsdp.yaml train_grpo.py
Good at
Very little boilerplate
Quick experiments with SFT, DPO and GRPO
Custom reward functions; vLLM for generating rollouts
Costs
Less direct control inside a trainer
Version compatibility across transformers, TRL, vLLM and the backend
New algorithms may mean overriding trainer internals
Best for
LLM post-training, preference optimization, RL with checkable rewards
5 · Post-training and RL
In RL, the backend is only half the system
Supervised fine-tuning is just training. Reinforcement learning with GRPO adds a loop around it: generate completions (rollouts), score them with a reward function or an environment, train on the scores, then send the new weights back to whatever generates the next rollouts. DDP, FSDP and DeepSpeed only cover the training step. The rest is either your own code or a library such as TRL.
Where the GPU time goes
GRPOTrainer generate, then train
generatetraingeneratetraingeneratetrain
AsyncGRPOTrainer both at once
generategenerategenerategenerategenerategenerate
traintraintraintraintrain
A schematic, not a measurement. In GRPOTrainer one phase must finish before the other starts, even when vLLM shares the training GPUs. AsyncGRPOTrainer streams completions from a separate vLLM server on its own GPUs while training consumes them, and sends updated weights to the server over NCCL every few steps. Samples generated by weights that are too many updates old are dropped.
Backend support differs between trainers. TRL's documentation for AsyncGRPOTrainer (now part of TRL's stable API, imported with from trl import AsyncGRPOTrainer) states: "Sharded training uses FSDP2. DeepSpeed is not supported". Context and sequence parallelism are not supported either, and generation always runs on a separate vLLM server. The plain GRPOTrainer does work with DeepSpeed; its docs say ZeRO-3 is required for models of 70B parameters and above.
Capability
DDP
FSDP2
DeepSpeed
TRL
Reward functions
Your code
Your code
Your code
Python functions passed as reward_funcs
GRPO, DPO
Your code
Your code
Your code
Built in
vLLM rollouts
Your code
Your code
Your code
Supported (GRPOTrainer, RLOOTrainer; server or shared GPUs)
Async RL
Your code
A building block
Your code
AsyncGRPOTrainer, with FSDP2, not DeepSpeed
Agent environments
Your code
Your code
Your code
Experimental environment_factory in AsyncGRPOTrainer
New algorithms
Full freedom
Full freedom
Within the engine
Subclass or override the trainer
6 · Which to pick when
Use the smallest tool that fits, then add layers
Two questions settle most choices: does the model state fit on one GPU, and do you want to write the training loop yourself? The picker reads the model, GPU count and memory you set in the calculator above.
What are you training?
Model state fits on one GPU
Use torchrun + DDP. It is the simplest setup and often the fastest. LoRA usually lands here: the frozen base weights cost about 2 bytes per parameter in bf16, and gradients and optimizer states exist only for the small adapters.
Fits only when sharded
Use FSDP2 if you want native PyTorch and your own loop. Use DeepSpeed ZeRO-2 or ZeRO-3 if you already have DeepSpeed configs or want its options.
Does not fit even when fully sharded
Add GPUs, or use DeepSpeed ZeRO-3 with CPU or NVMe offload and accept the slower steps. FSDP2 can offload to CPU, but only everything at once.
Post-training with Hugging Face models
Start with TRL on Accelerate, and choose its backend by the three rules above. For asynchronous GRPO, the backend must be DDP or FSDP2.
For a general training harness that has to support all four, a sensible build order is DDP first (it is the base case and the easiest to debug), then FSDP2 (native scaling), then TRL on Accelerate for post-training, then DeepSpeed when a memory limit or an existing pipeline calls for it.
No backend is fastest everywhere. Before committing, measure on your own workload: throughput, peak GPU memory, rollout latency for RL, and cost per training sample.
A common path: start with TRL, Accelerate, DDP or FSDP2, and vLLM. Move to veRL or your own distributed RL harness when you need more control over multi-turn agent trajectories, asynchronous rollouts, environment workers and how policy weights are synced.
Sources
Where these facts come from
Checked against the current documentation on 27 November 2026.
PyTorch: FSDP2 tutorial (DTensor per-parameter sharding, FSDP1 deprecated, CPU offload) · fully_shard API (reshard_after_forward, offload_policy) · torchrun · DDP design notes (gradient buckets, overlap with backward)
What it fixedSharding (FSDP, DeepSpeed ZeRO) removes the copies DDP keeps on every GPU: a 7B model's 112 GB of model state drops to 28 GB per GPU on 4 GPUs, and TRL on Accelerate runs SFT, DPO and GRPO on top of any of these backends.
What it still costsSharding pays in communication on every step and in harder checkpointing; offloading pays in throughput. Not every trainer supports every backend: TRL's AsyncGRPOTrainer supports FSDP2 but not DeepSpeed.