πΎ Data & StorageΒ· 8 min read
GPU-Accelerated Preprocessing
NVIDIA DALI for vision and multimodal workloads β moving data transforms from CPU to GPU to eliminate preprocessing bottlenecks.
daligpu-preprocessingvisiondata-pipelineaugmentation
When CPU-based preprocessing canβt keep up with GPU training speed, NVIDIA DALI moves transforms (decode, resize, augment) to the GPU β eliminating the CPU bottleneck entirely.
1. The CPU Preprocessing Bottleneck
For vision and multimodal workloads, preprocessing is expensive:
Standard pipeline (CPU):
Read JPEG β CPU decode (10ms) β CPU resize (5ms) β CPU augment (3ms)
β CPUβGPU transfer (1ms) β GPU training step (5ms)
Total: ~24ms, GPU waits 19ms (79% idle!)
DALI pipeline (GPU):
Read JPEG β GPU decode (0.5ms) β GPU resize (0.3ms) β GPU augment (0.2ms)
β Already on GPU! β GPU training step (5ms)
Total: ~6ms, GPU waits <1ms (~83% utilized)
2. NVIDIA DALI Pipeline
from nvidia.dali.pipeline import pipeline_def
import nvidia.dali.fn as fn
import nvidia.dali.types as types
@pipeline_def(batch_size=64, num_threads=4, device_id=0)
def training_pipeline():
jpegs, labels = fn.readers.file(
file_root="/data/imagenet/train",
random_shuffle=True,
)
images = fn.decoders.image(jpegs, device="mixed") # decode on GPU
images = fn.resize(images, size=[224, 224])
images = fn.crop_mirror_normalize(
images,
mean=[0.485 * 255, 0.456 * 255, 0.406 * 255],
std=[0.229 * 255, 0.224 * 255, 0.225 * 255],
mirror=fn.random.coin_flip(),
)
return images, labels
pipe = training_pipeline()
pipe.build()
Key Benefits
| Benefit | Details |
|---|---|
| GPU decode | JPEG/video decode on GPU (nvJPEG, nvVideoCodec) |
| Zero CPU bottleneck | Transforms run on GPU, no CPUβGPU transfer |
| Prefetching | Automatic pipeline prefetch hides I/O |
| PyTorch integration | DALIGenericIterator wraps DALI as a PyTorch DataLoader |
3. When to Use DALI
| Workload | DALI helps? | Why |
|---|---|---|
| Vision (ImageNet, detection) | β Best use case | Heavy decode + augmentation |
| Video training | β | GPU video decode is much faster |
| Multimodal (image + text) | β For image part | Text preprocessing stays on CPU |
| Pure text (LLM pre-training) | β | No image decode, tokenization is CPU-efficient |
| Audio | β οΈ Limited | Some audio ops supported |
For text-focused data loading, see PyTorch DataLoader and Streaming Datasets.
Self-Check
- Explain the CPU preprocessing bottleneck for vision workloads
- Compare CPU vs GPU decode/resize latency
- Write a DALI pipeline for ImageNet training
- Identify when DALI helps vs when itβs unnecessary (text vs vision)