Navigation
📐 Foundations· 10 min read

GPU Memory & Interconnects

Where training memory goes, optimization strategies (ZeRO, checkpointing, offloading), and multi-GPU interconnect topologies.

memoryadamzeronvlinkinfinibanddgx

Two questions dominate AI infrastructure engineering: “why doesn’t my model fit in memory?” and “how do I connect enough GPUs?” This chapter answers both.


1. Where Training Memory Goes

When training large models, memory is often the first bottleneck. A 7B-parameter model in FP16 requires ~14 GB just for parameters — but that’s the smallest piece.

With Adam optimizer + FP16 mixed precision, memory per parameter:

ComponentBytes/paramNotes
FP16 parameters2 BUsed in forward/backward
FP32 parameter copy4 BAdam needs FP32 master weights
FP32 gradients4 BProduced by backward pass
Adam first moment (m)4 BExponential moving average of gradients
Adam second moment (v)4 BExponential moving average of squared gradients
Total18 B—

Training Memory Breakdown

A 7B model’s fixed memory = 7×109×18=1267 \times 10^9 \times 18 = 126 GB — before activations.

A single 80 GB H100 cannot even hold the fixed state. Activations add more on top, scaling with batch size and sequence length. This is why multi-GPU training and memory optimization are not optional — they are the baseline.


2. Memory Optimization Strategies

StrategyPrincipleMemory SavingsCost
Mixed precisionFP16/BF16 for forward/backward, FP32 for updates~50% parameter memoryLoss scaling needed (FP16)
Gradient accumulationAccumulate gradients across micro-batchesReduces peak activation memoryMore training steps
Activation checkpointingSave only some activations, recompute during backwardActivation memory drops to O(N)O(\sqrt{N})~33% more compute
ZeRO Stage 1Shard optimizer states across GPUs~4× reduction in optimizer memoryMore communication
ZeRO Stage 2+ shard gradientsFurther reductionMore communication
ZeRO Stage 3+ shard parametersLinear reduction with GPU countSignificant communication
CPU offloadingMove optimizer states to CPU RAMBreak single-GPU limitPCIe bandwidth bottleneck
NVMe offloadingMove to SSDBreak CPU RAM limitMuch slower

These strategies are not mutually exclusive. A typical production configuration:

DeepSpeed ZeRO Stage 2 + BF16 mixed precision + activation checkpointing — standard for training 7B–70B models.

How ZeRO Reduces Memory

Without ZeRO, each GPU holds a full copy of everything (18 bytes/param). With ZeRO-3 across N GPUs, each GPU holds only 1N\frac{1}{N} of parameters, gradients, and optimizer states — but must communicate to reconstruct full tensors during forward/backward.

The tradeoff: memory scales linearly down with GPU count, communication scales up.


3. Multi-GPU Interconnects

When a single GPU’s memory and compute are insufficient, multi-GPU parallelism is needed. The interconnect bandwidth and topology directly determine efficiency.

Interconnect Technologies

TechnologyBandwidthScopeNotes
PCIe 5.0128 GB/s (bidirectional)Cross-GPU (general)Universal but low bandwidth
NVLink 4.0 (Hopper)900 GB/s (bidirectional total)Intra-node GPU↔GPU18 links × 25 GB/s × 2
NVLink 5.0 (Blackwell)1,800 GB/s (bidirectional total)Intra-node GPU↔GPUB200
NVSwitchFull-bisection NVLink fabricIntra-node all-to-allAny GPU to any GPU at full BW
InfiniBand NDR400 Gb/s (50 GB/s) per portInter-nodeLarge cluster standard

DGX H100 Topology

DGX H100 Topology

A DGX H100 (8 GPUs):

  • 8× H100 fully connected via NVSwitch — 900 GB/s between any two GPUs
  • 8× ConnectX-7 InfiniBand NICs for cluster connectivity
  • Intra-node: 900 GB/s vs inter-node: 50 GB/s per NIC — an 18× bandwidth gap

This gap directly shapes parallelism strategy:

Parallelism typeCommunication volumeBest interconnect
Tensor parallelismVery high (every layer)NVLink (intra-node)
Data parallelismMedium (gradient sync)InfiniBand (inter-node OK)
Pipeline parallelismLow (activation boundaries)InfiniBand (inter-node OK)
Expert parallelism (MoE)High (All-to-All)NVLink preferred

Rule of thumb: Put high-communication parallelism dimensions on NVLink. Put lower-communication dimensions on InfiniBand.

# View GPU topology
nvidia-smi topo -m

# View NVLink status
nvidia-smi nvlink -s

Self-Check

  • Calculate memory for a 7B model with Adam + FP16 mixed precision
  • Explain ZeRO Stage 1/2/3 and the tradeoff between memory and communication
  • List 3+ memory optimization strategies and their costs
  • Know the bandwidth difference between NVLink and InfiniBand
  • Explain why tensor parallelism should be intra-node and data parallelism can be inter-node
  • Use nvidia-smi topo -m to check GPU connectivity

References