Your GPUs Are 100% Allocated and 35% Utilized: Finding the Data-Loading Wall
Here is a billing situation that should make anyone running a training cluster uncomfortable: eight H100s, 100% allocated, reserved for the whole job, and the accelerators themselves working about a third of the time. You pay for every second the hardware is yours. The hardware spends most of each step waiting for data to show up.
The reason this goes unnoticed for so long is that the obvious metric lies
to you. nvidia-smi prints a column called GPU-Util, and
during a stalled training run it will happily read 95%. The job looks
healthy. The loss goes down. Nobody opens a ticket. Meanwhile the effective
throughput — samples per second per dollar — is less than half of what the
same silicon could do.
Why the headline utilization number is misleading
The GPU-Util field from nvidia-smi is defined as the
fraction of the sampling window during which at least one kernel was
executing. That is a very low bar. A training step that spends 600ms blocked
on the dataloader and 400ms doing matrix multiplies can still keep a trickle
of small kernels (optimizer updates, metric reductions, the tail of the
previous backward pass) firing across the idle gap, and the counter rounds
up toward 100%.
What you actually want is how busy the streaming multiprocessors are — the real compute units. That lives in the DCGM profiling fields, not in the headline number:
# Per-second GPU utilization the naive way (misleading under I/O stall)
nvidia-smi dmon -s u
# What you actually want: SM activity and tensor-core activity via DCGM
dcgmi dmon -e 1002,1004
# field 1002 = DCGM_FI_PROF_SM_ACTIVE (fraction of SMs with work)
# field 1004 = DCGM_FI_PROF_PIPE_TENSOR_ACTIVE (tensor pipe busy)
If GPU-Util says 95% but SM_ACTIVE hovers around 0.35
and PIPE_TENSOR_ACTIVE is lower still, you are not compute-bound.
Something upstream of the GPU is setting the pace.
Confirming it is the input pipeline, not the model
Before blaming storage, prove the GPU is idle waiting on the host. The cleanest way is to replace the real dataset with a synthetic one that hands back a tensor already resident on the device, and re-run a few hundred steps. If step time collapses, the model math was never the problem — the feeding was.
# Diagnostic: does step time drop when data is free?
# Swap the real loader for one that yields a pre-made GPU tensor.
batch = torch.randn(batch_size, 3, 224, 224, device="cuda")
for _ in range(500):
optimizer.zero_grad(set_to_none=True)
loss = model(batch).mean()
loss.backward()
optimizer.step()
# Compare steps/sec here vs. with the real DataLoader.
The PyTorch profiler says the same thing with more precision. A pipeline that is input-bound shows the GPU stream sitting in long gaps while the CPU side is pinned inside the dataloader's collate and decode path:
from torch.profiler import profile, ProfilerActivity
with profile(activities=[ProfilerActivity.CPU, ProfilerActivity.CUDA]) as p:
for i, batch in enumerate(loader):
train_step(batch)
if i == 20:
break
print(p.key_averages().table(sort_by="cuda_time_total", row_limit=15))
# Input-bound signature: large "cudaStreamSynchronize" / idle gaps on the
# CUDA timeline, CPU time dominated by image decode + collate, workers maxed.
The root cause is usually the shape of the data on disk
Once you know it is the input pipeline, the cause is almost always one of three things, and often all three at once:
- Millions of tiny objects. A dataset stored as one object per sample (a JPEG, a short audio clip, a JSON record) turns one training epoch into millions of small random GETs against object storage. Object stores are throughput monsters for large sequential reads and latency-bound for small random ones. Per-object overhead dominates.
- Too little overlap. With too few dataloader workers, or no prefetch, the GPU blocks on each batch instead of consuming a batch that was fetched while it was still computing the previous one.
- Decode on the critical path. JPEG decode and augmentation on a handful of CPU cores cannot keep up with a GPU that eats a batch every few milliseconds.
The first one is the big lever. Fetching 10 million individual 50 KB files is a fundamentally different workload from streaming a few thousand 1 GB shards, even though the byte count is identical.
The fix: reshape the data, add a fast tier, overlap everything
1. Shard into large sequential files
Pack the dataset into a few thousand large shards that a worker reads sequentially — WebDataset tar shards, TFRecord, or Parquet, depending on the framework. The dataloader streams a shard end to end instead of issuing one request per sample. A reasonable target is shards in the 256 MB–1 GB range, enough shards that every worker across every node gets its own without contention.
# Build ~1 GB WebDataset shards from a tree of per-sample files.
tar --sort=name -cf - data/train/ \
| split -b 1G -d - shard- --additional-suffix=.tar
# Stream them, decode and augment inside the pipeline, prefetch ahead.
import webdataset as wds
dataset = (
wds.WebDataset("shard-{000..512}.tar", shardshuffle=True)
.decode("pil")
.to_tuple("jpg", "cls")
.map_tuple(train_transform, lambda x: x)
.batched(batch_size)
)
2. Put a fast tier between object storage and the GPUs
Object storage is the system of record, not the thing you read from in the
hot loop. Stage shards onto a tier built for high-throughput reads at GPU
scale: a managed parallel filesystem (Lustre-class, offering TB/s aggregate
throughput and sub-millisecond latency to many clients at once), or local
NVMe on each node used as a cache that fills on first epoch and serves every
epoch after. On Kubernetes that is a mounted PVC backed by the parallel FS,
or a local-SSD-backed emptyDir populated by an init step:
# GKE: give the training pod a fast scratch tier on local NVMe.
volumes:
- name: fast-scratch
emptyDir:
medium: "" # backed by node local SSD, not tmpfs/RAM
sizeLimit: 2Ti
# An init container warms it from object storage once; the main
# container reads shards only from /scratch for every epoch.
3. Overlap fetch with compute, and stop decoding on too few cores
Give the loader enough workers to stay ahead of the GPU, let each keep a prefetch buffer, pin host memory so the host-to-device copy overlaps compute, and keep workers alive across epochs so you don't pay fork/warmup every time:
loader = DataLoader(
dataset,
batch_size=None, # batching handled in the pipeline
num_workers=16, # scale to available CPU cores, not to 2
prefetch_factor=4, # each worker stays several batches ahead
pin_memory=True, # enables async H2D copy overlapping compute
persistent_workers=True, # don't re-spawn workers each epoch
)
If CPU-side JPEG decode and augmentation are still the ceiling after that, move them onto the GPU with a library like NVIDIA DALI so decode runs on the same device that is otherwise starving — the CPU stops being the bottleneck because it is no longer doing the heavy per-sample work.
What "fixed" looks like
The number to watch is not the loss curve — it is SM_ACTIVE
and samples/sec. When the pipeline stops starving the accelerators, the SM
activity line climbs toward the compute-bound ceiling and stays there, and
step time drops to roughly what the synthetic-data test predicted. The chart
below is illustrative of the shape of the win, not measured telemetry from a
specific run:
Lesson
The most expensive idle hardware in an ML stack is rarely a GPU that is switched off — it is a GPU that is switched on, fully billed, and blocked on storage. Treat the headline utilization number as a smoke alarm that sometimes forgets to go off: trust SM activity and samples-per-dollar instead. And remember that the input pipeline is a performance system in its own right, with the same shape as any other — object storage is throughput- bound for big sequential reads and latency-bound for small random ones, so the cheapest speedup is usually to change what the data looks like on disk, not to buy more accelerators.
Hitting something like this in production? I help teams with performance engineering, SRE/observability, and AI-driven root cause analysis — work with me.
Comments
Post a Comment