cd /news/ai-infrastructure/what-are-deepspeed-zero-stages-1-2-a… · home › topics › ai-infrastructure › article
[ARTICLE · art-178885] src=dev.to ↗ pub= topic=ai-infrastructure verified=true sentiment=· neutral

What are DeepSpeed ZeRO stages 1, 2 and 3?

A Nodus Compute engineer published a reference breaking down how DeepSpeed ZeRO stages 1, 2 and 3 partition training state across GPUs, using the ZeRO paper's 16-bytes-per-parameter formula to compute per-GPU memory floors. On 8 GPUs, a 70B full fine-tune needs 1,120 GB per GPU at stage 0 but 140 GB with ZeRO-3, and the analysis notes only ZeRO-3 keeps shrinking memory as GPUs are added, since stages 1 and 2 floor at 4P and 2P respectively. The writeup also prices a 70B fine-tune at 8 x B200 for $44.00/hr with ZeRO-3 versus 8 x H100 at $20.80/hr with ZeRO-3 plus CPU optimizer offload.

recommendation

Use ZeRO-3 or CPU optimizer offload for 70B fine-tunes, since ZeRO-1 and ZeRO-2 keep 4P and 2P per GPU no matter how many GPUs you add.

more in playbook: Inference and self-hosting
by read9 min views6 publishedNov 30, 2026

DeepSpeed ZeRO stages 1, 2 and 3 split a model's training state across GPUs: stage 1 splits the Adam optimizer state, stage 2 also splits the gradients, and stage 3 also splits the weights. On Nodus, the stage decides the hardware: by our math a 70B full fine-tune fits 8 x NVIDIA B200 at $44.00/hr with ZeRO-3, or 8 x NVIDIA H100 at $20.80/hr with ZeRO-3 and the optimizer in CPU memory. Only ZeRO-3 keeps cutting per-GPU memory as you add GPUs, and it moves 1.5 times as much data per step as stages 1 and 2.

This post is the memory and config reference for the stages themselves. If you are choosing between DeepSpeed and PyTorch FSDP, read our FSDP vs DeepSpeed guide. If you are new to sharding, start with FSDP vs DDP.

Each stage removes one more copy that plain data parallelism keeps on every GPU. The ZeRO paper counts 16 bytes of model state per parameter for mixed-precision training with Adam: 2 bytes of 16-bit weights, 2 bytes of 16-bit gradients and K = 12 bytes of optimizer state. Those 12 bytes are an fp32 copy of the weights plus Adam's two fp32 moments, 4 bytes each.

The DeepSpeed ZeRO tutorial defines the stages the same way. In stage 1, "each process updates only its partition" of the optimizer state. Stage 2 keeps only the gradients that match that partition. Stage 3 partitions the 16-bit weights and "will automatically collect and partition them during the forward and backward passes."

With P parameters on N GPUs, section 5 of the paper gives the per-GPU model state:

Stage What is split Model state per GPU DeepSpeed setting
0 (off) Nothing 16P "stage": 0
ZeRO-1 Optimizer state 4P + 12P/N "stage": 1
ZeRO-2 Optimizer state and gradients 2P + 14P/N "stage": 2
ZeRO-3 Optimizer state, gradients and weights 16P/N "stage": 3

Activations are not in these numbers, and neither are temporary buffers. The DeepSpeed memory docs warn that for long sequences activations can take as much memory as weights, gradients and optimizer state combined. Treat every figure below as a floor.

On 8 GPUs, a 7B model needs between 112 GB and 14 GB per GPU depending on the stage, and a 70B model between 1,120 GB and 140 GB. These are our numbers from the paper's formulas, in decimal GB, before activations:

Setting on 8 GPUs 7B per GPU 70B per GPU
Stage 0 112 GB 1,120 GB
ZeRO-1 38.5 GB 385 GB
ZeRO-2 26.25 GB 262.5 GB
ZeRO-3 14 GB 140 GB
ZeRO-2 + CPU optimizer offload 14 GB 140 GB
ZeRO-3 + CPU optimizer offload 1.75 GB 17.5 GB

For 7B: 7 x 16 = 112; 7 x (4 + 12/8) = 38.5; 7 x (2 + 14/8) = 26.25; and 7 x 16/8 = 14. The 70B column multiplies by 70 instead. The two offload rows use the DeepSpeed memory docs, which put GPU memory at 2P for ZeRO-2 with the optimizer on CPU, and at 2P/N plus the largest layer for ZeRO-3.

The bigger lesson is in the formulas. ZeRO-1 and ZeRO-2 keep a full copy of something on every GPU, so they hit a floor: 4P for stage 1 and 2P for stage 2. For 70B those floors are 280 GB and 140 GB, more than any 80 GB GPU holds no matter how many you add. Only ZeRO-3 divides everything by N.

Adding GPUs barely helps ZeRO-1 and ZeRO-2 on a 70B model; only ZeRO-3 keeps shrinking.

The 70B curve points come from the same formulas, for example 70 x (4 + 12/32) = 306.25 GB for ZeRO-1 on 32 GPUs, and 70 x 16/32 = 35 GB for ZeRO-3.

For 70B, ZeRO-1 never fits a listed GPU, ZeRO-2 fits only the 288 GB NVIDIA B300, and ZeRO-3 fits 8 x B200. We matched the 70B numbers against the per-GPU memory and hourly supply prices on the Nodus pricing page:

70B full fine-tune Model state per GPU Left for activations Listed price
8 x H100 (80 GB), ZeRO-3 + CPU optimizer 17.5 GB 62.5 GB $20.80/hr
16 x H100 (80 GB), ZeRO-3, two machines 70 GB 10 GB $41.60/hr
8 x H200 (141 GB), ZeRO-3 140 GB 1 GB $28.74/hr
8 x B200 (180 GB), ZeRO-3 140 GB 40 GB $44.00/hr
8 x B300 (288 GB), ZeRO-2 262.5 GB 25.5 GB $55.54/hr

Prices checked November 30, 2026: H100 $2.600, H200 $3.593, B200 $5.500 and B300 $6.943 per GPU-hour, times the GPU count. The 8 x H200 row is there to show a trap: 1 GB of headroom will not hold real activations, so treat it as a miss.

The cheapest per hour is the offload setup, but CPU offload slows each step, so compare the price per finished run.

ZeRO-1 fails because its unsplit weights and gradients alone are 4 x 70 = 280 GB per GPU. The 16 x H100 row works on paper, but 10 GB of headroom is tight, and it needs two machines on a fast network. On Nodus, multi-node runs are in Beta and list the DeepSpeed launcher as "Accepted in the Beta, qualified later".

A 7B model is much easier. With no ZeRO at all, its 112 GB fits one H200 with 29 GB to spare, or one B200 with 68 GB to spare. On 8 x H100, ZeRO-2 leaves 53.75 GB per GPU for activations, which is usually enough. For the GPU count behind longer training runs, see how many GPUs you need to train a model.

ZeRO-1 and ZeRO-2 move the same data as plain data parallelism, and ZeRO-3 moves 1.5 times as much. Section 7 of the ZeRO paper works this out per GPU and per training step. Standard data parallelism all-reduces the gradients, which costs 2P values. ZeRO-2 replaces that with a reduce-scatter of gradients (P) and an all-gather of updated weights (P), again 2P.

ZeRO-3 adds a weight all-gather in the forward pass and another in the backward pass, plus the gradient reduce-scatter. That totals 3P. With 16-bit values at 2 bytes, here is our arithmetic for one step:

Model DDP, ZeRO-1, ZeRO-2 (2P) ZeRO-3 (3P)
7B 28 GB per GPU 42 GB per GPU
70B 280 GB per GPU 420 GB per GPU

ZeRO-3 buys its memory savings with 50% more traffic per step.

Inside one 8-GPU machine, the extra traffic stays on the GPUs' own interconnect. Across machines it crosses the network, which is where it hurts most. DeepSpeed's ZeRO++ targets that case: the config docs say zero_hpz_partition_size should ideally equal the number of GPUs per node, so weight gathers stay inside each machine.

Offload has a different cost. The config docs say that with offload_optimizer the optimizer computation runs on the CPU "regardless of device option", so every step ships gradients to the host and updated weights back. The ZeRO-Offload tutorial says DeepSpeedCPUAdam is 5X to 7X faster than the standard PyTorch implementation, but we have not measured the end-to-end slowdown, and it depends on your CPUs.

Pick the lowest stage that leaves room for activations, and offload only when no stage fits the GPUs you can get. Here is the rule we use, derived from the formulas above:

offload_optimizer to CPU. That cuts GPU memory to about 2P/N but needs host RAM.offload_param), or use NVMe, only when CPU memory runs out. This is ZeRO-Infinity, and it is the slowest option. Host RAM is the check people skip. The DeepSpeed memory docs size ZeRO-3 with optimizer offload and zero.Init at P x 16 x 1.5 on one machine, which is 70 x 16 x 1.5 = 1,680 GB for 70B. Our 70B VRAM guide covers the LoRA and inference cases that avoid most of this.

Each one is a zero_optimization block that goes into your full ds_config.json, next to your batch size and bf16 settings. The ZeRO-1 and ZeRO-2 blocks are copied from the ZeRO tutorial.

ZeRO-1:

{
    "zero_optimization": {
        "stage": 1,
        "reduce_bucket_size": 5e8
    }
}

ZeRO-2:

{
    "zero_optimization": {
        "stage": 2,
        "contiguous_gradients": true,
        "overlap_comm": true,
        "reduce_scatter": true,
        "reduce_bucket_size": 5e8,
        "allgather_bucket_size": 5e8
    }
}

ZeRO-2 with CPU optimizer offload, from the ZeRO-Offload tutorial. We fixed the comma placement in the published snippet so the JSON parses:

{
    "zero_optimization": {
        "stage": 2,
        "offload_optimizer": {
            "device": "cpu"
        },
        "contiguous_gradients": true,
        "overlap_comm": true
    }
}

ZeRO-3 with both offloads, the ZeRO-Infinity block from the ZeRO tutorial. Delete offload_param for optimizer-only offload, and delete both offload sections for plain ZeRO-3:

{
    "zero_optimization": {
        "stage": 3,
        "contiguous_gradients": true,
        "stage3_max_live_parameters": 1e9,
        "stage3_max_reuse_distance": 1e9,
        "stage3_prefetch_bucket_size": 1e7,
        "stage3_param_persistence_threshold": 1e5,
        "reduce_bucket_size": 1e7,
        "sub_group_size": 1e9,
        "offload_optimizer": {
            "device": "cpu"
        },
        "offload_param": {
            "device": "cpu"
        }
    }
}

To use NVMe, set "device": "nvme" and add "nvme_path": "/local_nvme", the default path in the config docs. The same docs say NVMe offload works only with stage 3, while CPU optimizer offload works with stages 1, 2 and 3.

On one machine, pass the DeepSpeed launcher to nodus run. The nodus run reference shows nodus run --gpu H100:8 --max-cost 40 -d -- torchrun train.py; for DeepSpeed, only the part after -- changes:

nodus run --gpu H100:8 --max-cost 40 -d -- deepspeed train.py --deepspeed --deepspeed_config ds_config.json

Before an offload run, check host memory with nodus get gpus --gpu H100 --count 8 --region us and read the MEMORY column. The example listing in the Nodus GPU guide shows an 8 x H100 machine with 1800Gi. If you launch with torchrun instead, the ZeRO-Offload tutorial warns that it sets OMP_NUM_THREADS=1, which leaves CPU Adam on one thread, so export a higher value first.

Write DeepSpeed checkpoints under /nodus/state, which the checkpoint guide restores into the next attempt if a machine is lost. One limit: managed TrainingJobs "reject ZeRO1, ZeRO2 and ZeRO3 with a distributed shape before launch", so use a plain Job for DeepSpeed sharding.

ZeRO-3 is the stage that partitions the 16-bit weights as well as gradients and optimizer state, so each GPU holds about 16P/N bytes of model state and gathers each layer's weights only when it runs. It is the stage that lets a 70B full fine-tune fit 8 x B200 on Nodus, at the price of 1.5 times the per-step traffic.

No. ZeRO's data-parallel stages cover weights, gradients and optimizer state only. Activations need gradient checkpointing or smaller micro-batches, and if you still run out, our CUDA out of memory guide goes through the other fixes.

Much less. With LoRA only the small adapters have gradients and Adam state, so stages 1 and 2 have little to split. ZeRO-3 still helps by sharding the frozen base weights, which matters for 70B and up. See LoRA vs full fine-tuning.

Originally published on the Nodus blog.

── more in #ai-infrastructure 4 stories · sorted by recency
── more on @deepspeed 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/what-are-deepspeed-z…] indexed:0 read:9min 2026-11-30 · —