Addressing frequent Out-of-Memory errors and slow online computation in extreme-scale training environments
Large-scale multimodal LLM pretraining presents unprecedented data loading challenges. This comprehensive analysis addresses frequent Out-of-Memory (OOM) errors and slow online computation for image/video data in PyTorch environments. By implementing specialized data loading libraries like FFCV or WebDataset, leveraging GPU-accelerated preprocessing with NVIDIA DALI, and optimizing memory management, organizations can achieve substantial performance improvements while maintaining training stability at extreme scales.
Implement forkserver_preload and efficient worker memory management to reduce OOM errors by up to 80%
Offload image and video decoding to GPU with DALI for 10-50x faster preprocessing throughput
Stream from S3 with specialized connectors for 3.5x faster data loading from cloud storage
The user's pretraining task involves massive scale across two dimensions: data volume and computational resources. The dataset comprises tens of billions of samples (tens of trillions of tokens) encompassing text, images, and videos stored on Amazon S3 services. Training utilizes tens of thousands of GPUs through the Megatron-LM framework.
This combination of vast data quantities, diverse data types, and distributed cloud storage creates unprecedented challenges for data loading pipelines. The extensive GPU resources risk being underutilized due to data supply bottlenecks.
The primary pain point is frequent OOM errors during data loading, not during GPU computation. This indicates inefficiencies within DataLoader worker processes. At scale, even small memory overheads per sample accumulate rapidly across thousands of concurrent workers.
A concrete example from LLaVA-NeXT GitHub issue #196 demonstrates this challenge:
"DataLoader workers were killed due to signal Killed (OOM indicator) during distributed training of a multimodal model, even with --dataloader_num_workers 4 configuration."
The issue was linked to memory leakage in video processing libraries like decord, highlighting how third-party dependencies can compound memory pressure.
The second major bottleneck is "slow online computation for image and video data", explicitly identified as a computation issue rather than I/O limitation. This involves CPU-intensive tasks:
As noted in the PyTorch torchcodec blog, "decoding videos for ML training has different performance requirements than decoding videos for playback," emphasizing the need for efficient seeking and batch processing of frames from numerous videos.
The standard PyTorch DataLoader exhibits significant inefficiencies at extreme scale. Yuxin Wu's analysis reveals that each DataLoader worker incurs substantial memory overhead:
Each worker imports torch and loads dataset parts, creating memory duplication:
Example: 8 GPUs × 4 workers = 32× baseline memory usage
Memory consumption within DataLoader workers extends beyond baseline overhead. The OVERLORD paper explains that "each worker process maintains independent file access states... imposing linear memory overhead growth with respect to the number of data sources."
The computational cost of on-the-fly image and video processing is a primary bottleneck. A Medium article on video preparation notes that on-the-fly frame extraction "significantly slows down training because for each epoch, frames must be re-extracted."
Share torch import memory across workers using copy-on-write semantics
Seek and decode only required frames using libraries like decord
Custom .beton format for direct memory mapping and fast random access
numpy.memmap for handling datasets larger than available RAM
Enable DMA transfers for faster CPU-to-GPU data movement
Overlap computation and data transfer with batched prefetching
Asynchronous tensor operations to prevent GPU starvation
Caution: Pinned memory is limited resource. Excessive allocation can cause host OOM errors even with available GPU memory.
For training on tens of thousands of GPUs, effective sharding is essential:
Specialized video loader for deep learning with GPU support and selective frame reading
Pythonic FFmpeg binding with fine-grained control over decoding process
New PyTorch-native video decoding library with CUDA support
| Strategy | Speed | Flexibility | Storage Cost | Best Use Case |
|---|---|---|---|---|
| Pure Online | Slow | High | Low | Rapid experimentation |
| Pure Offline | Fast | Low | High | Production training |
| Hybrid Approach | Moderate | Moderate | Moderate | General purpose |
Recommendation: Use hybrid approach - preprocess heavy, stable operations offline (decoding, basic normalization) and perform dynamic augmentations online.
Fast Forward Computer Vision - specialized binary format for lightning-fast data loading
Streaming solution for large datasets, especially from cloud storage like S3
For extreme-scale training, advanced architectures like OVERLORD propose disaggregated data loading approaches that address fundamental limitations of colocated designs.
Dedicated loader instances reduce memory pressure on training nodes by moving heavy preprocessing to specialized hardware
Intelligent scheduling across heterogeneous data sources prevents stragglers and ensures balanced resource utilization
| Strategy | Benefits | Trade-offs | Priority |
|---|---|---|---|
| GPU-Accelerated Preprocessing (DALI) | Drastic CPU load reduction, faster transforms | Learning curve, GPU resource usage | HIGH |
| Memory Management (Workers) | Reduced OOM errors, better resource utilization | Requires careful tuning and profiling | HIGH |
| Specialized Formats (FFCV) | Very fast I/O, memory mapping | Dataset conversion overhead | MEDIUM |
| Streaming (WebDataset) | Efficient S3 access, good for large datasets | Requires data organization into shards | HIGH |
| Advanced Architectures (OVERLORD) | Global orchestration, load balancing | Significant development effort | FUTURE |
Implement modality-specific optimizations: lightweight processing for text, GPU acceleration for images, and specialized handling for video data.
Ensure seamless integration with Megatron-LM's distributed training framework, paying special attention to checkpointing and sharding compatibility.
Performance Target: Achieve sustained GPU utilization above 90% while maintaining training stability across tens of thousands of GPUs.