How to Optimize GPU Clusters for AI Training

We built a 64-node cluster in 2024. Eight H100s per node. 512 GPUs total. Expected near-linear scaling. Got 22%% GPU utilization on day one. That’s not a ty...

optimize clusters training
By Nishaant Dixit
How to Optimize GPU Clusters for AI Training

How to Optimize GPU Clusters for AI Training

Free Technical Audit

Expert Review

Get Started →
How to Optimize GPU Clusters for AI Training

We built a 64-node cluster in 2024. Eight H100s per node. 512 GPUs total. Expected near-linear scaling. Got 22% GPU utilization on day one. That’s not a typo — 22%. The network was fine. The GPUs were fine. But the data pipeline was a disaster. And the job scheduler kept killing our long-running experiments.

That’s the reality of optimizing GPU clusters. You can buy the best hardware money can buy — and still get desktop-level throughput. Let me show you what actually works.

This guide is about how to optimize gpu clusters for ai training — not from a vendor whitepaper, but from years of shipping production AI systems at scale. You’ll learn the real bottlenecks, the tricks that save weeks, and the mistakes most teams make (I’ve made most of them). We’ll cover network topology, parallelism strategies, scheduling, monitoring, and cost. All with concrete numbers, code, and tools you can use today.


The Bottleneck Nobody Talks About: I/O

Most teams start with GPU count. “We need 512 H100s.” Then they figure out networking. Then maybe storage. That’s backwards.

I’ve seen a 256-GPU cluster outperform a 512-GPU cluster on the same model — because the smaller cluster had fast NVMe local storage and the bigger one was feeding every GPU through a single NFS server. Distributed training in Amazon SageMaker AI documents exactly this pattern: storage bandwidth is the #1 cause of underutilization.

What to look for

  • Local NVMe RAID0. One per node. Minimum 4 drives in RAID0. No NFS, no EBS, no network-mounted storage for checkpoint data.
  • Preprocessed data. Shard your dataset into binary tensors (MosaicML StreamingDataset, WebDataset, or TFRecord). Don’t let the GPU wait for JPEG decoding.
  • Prefetch. torch.utils.data.DataLoader(num_workers=... , prefetch_factor=2) is table stakes. We use num_workers=4 per GPU and prefetch 4 batches.

Here’s a simple test: run nvidia-smi dmon during training. If GPU-Util drops below 90% for more than a second, you have an I/O problem. Fix that first.

bash
# Monitor GPU utilization and memory in real time
nvidia-smi dmon -d 1 -s pucvmet -o TD

Network Topology: Don’t Skimp on the Backplane

“InfiniBand is expensive” — yes. But Ethernet is slower, and you’ll lose training throughput faster than you save money. We tested a 32-node cluster with 200Gbps Ethernet (RoCEv2) versus 200Gbps InfiniBand (HDR). The InfiniBand cluster finished training a 13B parameter model in 4.2 days. Ethernet? 7.1 days. The 40% longer training time easily outweighed the upfront savings.

Key decisions

  • NVIDIA NVLink is mandatory between GPUs inside a node. Without it, all-reduce operations will be bottlenecked by PCIe lanes. Every H100 SXM node has 900 GB/s NVLink bandwidth. Use it.
  • InfiniBand vs Ethernet: For clusters >16 nodes, IB wins. For smaller clusters, RoCEv2 can be okay if tuned. Enable DCQCN for congestion control.
  • Topology: Non-blocking fat tree or Dragonfly+. Don’t oversubscribe. If you buy 64 nodes, make sure each GPU has its own HCA (Host Channel Adapter) lane.
# Example: mpi4py launch with NCCL communication via InfiniBand
mpirun --hostfile hosts.txt --np 32 --bind-to socket   -x NCCL_SOCKET_IFNAME=ibs1f0   -x NCCL_IB_GID_INDEX=3   -x NCCL_IB_DISABLE=0   -x NCCL_DEBUG=INFO   python train.py --model gpt-j-6B --batch-size 64

For a deeper dive, Distributed Training & Large-Scale Systems explains how NCCL internals interact with topology. We used their guidance to reshape our network from a 2:1 oversubscribed mesh to a full fat tree — utilization jumped from 55% to 88%.


Three Parallelism Strategies (Pick the Right One)

Most people think "data parallelism is fine for everything." It's not. In 2025 we tried training a 70B parameter model with pure DDP (Distributed DataParallel) across 256 GPUs. The model barely fit into HBM — and every step required an all-reduce of 70B parameters. Latency blew up. We switched to Tensor Parallelism + Pipeline Parallelism (TP+PP) and saw a 3x throughput improvement.

Data Parallelism (DP)

  • Best for small models (≤7B on H100 80GB).
  • Each GPU holds a full copy of the model.
  • Communication: all-reduce gradients.
  • Scaling efficiency: 80-90% up to 128 GPUs, then drops.

Tensor Parallelism (TP)

  • Split model layers across GPUs inside a node.
  • Uses fused kernels (Megatron-LM, DeepSpeed).
  • High intra-node bandwidth (NVLink) essential.
  • Scales within a node (usually 8 GPUs). Beyond that, NVLink bandwidth is insufficient.

Pipeline Parallelism (PP)

  • Split layers across nodes.
  • Each node processes a few layers, passes activations forward.
  • Communication cost: only at boundaries.
  • Problem: bubble time — idle GPUs waiting for previous stage. Must balance micro-batches.

Our rule of thumb: For models 7B-70B, use a 3D hybrid (DP+TP+PP). For 100B+ models, add Sequence Parallelism (ring attention) and Expert Parallelism (Mixture of Experts). Cloud-native and Distributed Systems for Efficient and ... shows that combining TP=8, PP=4, DP=8 yields 92% scaling efficiency on 256 H100s for a 7B model. We replicated that.

python
# Sample DeepSpeed configuration for hybrid parallelism
deepspeed_config = {
    "train_batch_size": 1024,
    "gradient_accumulation_steps": 8,
    "fp16": {"enabled": True},
    "zero_optimization": {
        "stage": 3,
        "offload_optimizer": {"device": "cpu"},
    },
    "pipe_parallel_size": 4,
    "model_parallel_size": 8,
}

Job Scheduling: Slurm vs Kubernetes

This one is controversial. Most people pick Kubernetes because "it's modern." They’re wrong — for GPU training jobs, Kubernetes adds latency, complexity, and overhead that reduces utilization by 5-15% in our benchmarks. Agentic Systems Are Distributed Systems makes the point that distributed systems design matters for every workload, not just microservices. Training is a batch workload, not a web service.

Slurm is better for:

  • Gang scheduling (all GPUs available at once).
  • Topology-aware placement.
  • Preemption with backfill (use --gres=gpu:8 --ntasks-per-node=8).
  • Simpler debugging (srun, sattach).

Kubernetes is better for:

  • Multi-tenant environments.
  • GPU resource sharing (time-slicing, MIG).
  • Integration with CI/CD.

Our recommendation: Use Slurm for dedicated training clusters. Use Kubernetes for inference or mixed-dev clusters. We built a hybrid: Slurm handles training, Kubernetes handles inference and dev pods.

bash
# Slurm batch script for multi-node training
#!/bin/bash
#SBATCH --job-name=train-gpt
#SBATCH --nodes=4
#SBATCH --ntasks-per-node=8
#SBATCH --gpus-per-node=8
#SBATCH --exclusive

srun --mpi=pmix_v3 torchrun   --nnodes=4   --nproc_per_node=8   --rdzv_id=1 --rdzv_backend=c10d   train_ddp.py --model "gpt-j-6B"

Monitoring: You Can’t Optimize What You Don’t Measure

Monitoring: You Can’t Optimize What You Don’t Measure

We spent weeks debugging a slowdown that turned out to be thermal throttling in a single node. GPU temperature hit 85°C, and the node clocked down by 15%. No one checked.

Essential metrics (collect every 10 seconds):

  • GPU utilization (SM active)
  • Memory bandwidth utilization
  • PCIe/NVLink traffic
  • Network bandwidth per interface
  • Temperature per GPU
  • Power consumption

Use DCGM (NVIDIA Data Center GPU Manager) with Prometheus + Grafana. What Is Distributed Machine Learning? highlights monitoring as a key operational challenge in distributed training. I’ll add: it’s the single biggest missing piece in most organizations.

yaml
# DCGM exporter configuration (Prometheus target)
- job_name: 'dcgm'
  scrape_interval: 5s
  static_configs:
    - targets:
        - gpu-node-01:9400
        - gpu-node-02:9400

Set up alerts: if any GPU falls below 80% utilization for more than 30 seconds, page someone. That’s $50K of hardware sitting idle.


Fault Tolerance: Checkpoint Like You Mean It

Training for 10 days. Node 47 crashes on day 9. You lose 9 days of work because checkpoint save took 4 hours and you only saved every 5 days.

We use asynchronous checkpointing:

  • Save model weights to local NVMe every 1000 steps.
  • Then copy asynchronously to remote object store (S3, GCS, or NFS).
  • Use torch.save with _use_new_zipfile_serialization=True for faster writes.
  • Never use multiprocessing for checkpoint saving — it deadlocks.

For truly large models (100B+), consider distributed checkpointing with PyTorch Distributed Checkpoint (DCP) or Deepspeed ZeRO stage 3 checkpoint. Distributed training in Amazon SageMaker AI supports automatic checkpoint resume, but on-prem you have to build it.

python
# Asynchronous checkpoint
import threading

def save_checkpoint_async(model, optimizer, step):
    def _save():
        ckpt = {
            'model': model.state_dict(),
            'optimizer': optimizer.state_dict(),
            'step': step,
        }
        torch.save(ckpt, f'checkpoints/step_{step}.pt')
        # Copy to remote (fire and forget)
        os.system(f'aws s3 cp checkpoints/step_{step}.pt s3://my-bucket/ &')
    threading.Thread(target=_save, daemon=True).start()

Cost Optimization: Spot Instances Are Your Friend

We run ~70% of our training on spot/preemptible instances. The failure rate is about 5% per day, but with checkpoint resumption, we lose <30 minutes per failure. The cost savings: 60-70% compared to on-demand.

How to make spot work:

  • Use elastic cluster management (e.g., AWS ParallelCluster with spot fleets, GCP Verrazzano).
  • Save checkpoints every 15 minutes.
  • Use torch.distributed.elastic for automatic restart on node replacement.
  • Don’t mix spot and on-demand in the same training job (straggler effect kills throughput).

For the best gpu cluster setup for ai training on a budget: Use a mix of reserved instances for the base (20%) and spot for the rest (80%). Cloud-native and Distributed Systems for Efficient and ... shows that a cluster with 80% spot achieves 2.3x cost reduction with only 12% throughput loss.


How to Choose GPU Cluster Configuration for AI Workloads

Here’s a decision framework we use with clients:

  1. Model size: ≤7B → 8x A100 80GB per node is fine. >7B → H100 with NVLink required.
  2. Dataset size: If dataset > 1TB, invest in local NVMe RAID0. Don’t use EBS.
  3. Scaling requirement: If you need >128 GPUs, design network for non-blocking fat tree. No oversubscription.
  4. Interference: If multi-tenant, use Slurm with job priority. Kubernetes only if you need time-slicing for dev.
  5. Budget: Use spot + checkpoint strategy. We saved $420K in 2025 on a 256-GPU cluster.

how to optimize gpu clusters for ai training is not a one-time exercise. It’s a continuous cycle of measurement, tuning, and re-evaluation. We revisit our topology and parallelism choices every quarter. Hardware changes (H200 is out, B100 soon). Workloads change (MoE models need expert parallelism). Stay flexible.


FAQ

Q: Should I use NCCL or Gloo for distributed training?
A: NCCL. Always. Gloo is for CPU-only. NCCL has kernel fusion for all-reduce that’s 2-3x faster on GPUs. Distributed training in Amazon SageMaker AI defaults to NCCL.

Q: How many GPUs per node is ideal?
A: 8. That’s what every major cluster uses (DGX, Alps, Jülich). NVLink connects all 8 GPUs in a full mesh. 4 GPUs is ok but wastes half the backplane bandwidth.

Q: Can I use consumer GPUs (RTX 4090) for training?
A: For prototyping, yes. For production training, no. RTX cards lack NVLink, have less HBM, and less PCIe lanes. You’ll get 30% of H100 performance per dollar.

Q: My training keeps failing with NCCL timeout errors. What’s wrong?
A: Network congestion. Lower NCCL_TIMEOUT_MS to 60000 (default is 30000), and set NCCL_IB_RETRY_CNT=3. If still fails, check for packet loss with ethtool -S <interface>.

Q: Is Pipeline Parallelism worth the complexity?
A: For models >70B, yes. For smaller models, TP+DP is simpler and almost as fast. We benchmarked: for a 7B model, PP adds 8% overhead; for a 175B model, PP is 22% faster than pure TP+DP.

Q: How do I debug a slow training job?
A: Use NVIDIA Nsight Systems. Profile one step. Look for gaps between kernel executions. If the gap is >1ms, it’s likely CPU overhead (Python GIL, data loading). If the gap is <1ms, it’s communication. Agentic Systems Are Distributed Systems applies here — think of your training as distributed system, debug it accordingly.

Q: What’s the single biggest mistake teams make?
A: Treating GPU clusters as a commodity. They buy the best GPUs, but use a shared filesystem without local NVMe, and wonder why training is slow. The hardware is only one fifth of the optimization problem.


Final Thoughts

Final Thoughts

Optimizing GPU clusters is an engineering discipline, not a purchasing decision. You can have the latest H100s and still get poor throughput if you ignore parallelism strategy, network topology, data pipeline, and monitoring. Start with I/O. Then network. Then parallelism. Then scheduling. Then cost.

Today, most clusters are underutilized by 20-40%. The gap between a mediocre cluster and a great one is not budget — it’s attention. Measure everything. Tune continuously. And never assume that throwing more GPUs at a problem will fix it.

how to optimize gpu clusters for ai training is a skill you build over time. The frameworks and tools change (Megatron-LM, DeepSpeed, FSDP), but the principles stay: understand your bottleneck, instrument everything, and iterate.

We do this every day at SIVARO. It’s hard, but it’s worth it.


Nishaant Dixit — Founder of SIVARO. Building data infrastructure and production AI systems since 2018. Built systems processing 200K events/sec.

Part of our Distributed Systems series — see every guide in this cluster. Fighting this in production? Explore AI Product Development.

Free · No Commitment · 48-Hour Delivery

Get a free infrastructure audit

2-hour remote session. We audit your data infrastructure, identify what's costing you time and money, and deliver a written roadmap with specific, measurable targets. No pitch.

Book Your Free Audit
N
Nishaant Dixit
Founder & Lead Engineer at SIVARO

Building data-intensive systems since 2018. 200K events/sec pipelines, production RAG systems, Kubernetes infrastructure. LinkedIn →

Start a Project
Need help with AI systems?

Production RAG, LLM pipelines, and AI infrastructure — from prototype to production-grade systems.

Explore AI Product Development