Abstract
We present FFCV, a library for easy and fast machine learning model training. FFCV speeds up model training by eliminating (often subtle) data bottlenecks from the training process. In particular, we combine techniques such as an efficient file storage format, caching, data pre-loading, asynchronous data transfer, and just-in-time compilation to (a) make data loading and transfer significantly more efficient, ensuring that GPUs can reach full utilization; and (b) offload as much data processing as possible to the CPU asynchronously, freeing GPU cycles for training. Using FFCV, we train ResNet-18 and ResNet-50 on the ImageNet dataset with competitive tradeoff between accuracy and training time. For example, we are able to train an ImageNet ResNet-50 model to 75% in only 20 mins on a single machine. We demonstrate FFCV's performance, ease-of-use, extensibility, and ability to adapt to resource constraints through several case studies.
Introduction
In modern deep learning, the primary focus of optimization is often the GPU. However, as hardware accelerators become increasingly powerful, the bottleneck of the training pipeline has shifted. A standard training step involves three distinct stages: reading data from disk, processing it (e.g., JPEG decoding, data augmentation), and updating model parameters on the GPU.
In many standard setups, the first two stages are so slow that the GPU spends a significant portion of its time "starving"—idly waiting for the next batch of data. Research indicates that in a standard PyTorch ImageNet setup, data processing can be nearly 30 times slower than the theoretical throughput of the GPU. FFCV (Fast Forward Computer Vision) is designed to close this gap, ensuring that hardware utilization is maximized by streamlining the entire data pipeline.
The FFCV Architecture
FFCV introduces a suite of optimizations to eliminate data-related stalls by rethinking how data is stored, processed, and moved.
1. The .beton File Format
Traditional datasets often consist of thousands of individual files, which strains filesystems, or sequential shards, which limit efficient random access. FFCV utilizes a custom paged file format called .beton. This format includes a "Data Table" for fast indexing and "Heap Storage" for large binary data. This structure allows for efficient, non-sequential reads, which is critical for maintaining high throughput during training.
2. JIT-Compiled Pipelines
Python is the standard language for deep learning research but is notoriously slow for heavy data manipulation. FFCV leverages the Numba library to compile Python data-processing code into optimized machine code just before training begins. This Just-In-Time (JIT) compilation ensures that data augmentations and transformations do not become the bottleneck.
3. Multithreading and the GIL
While PyTorch typically uses multiple sub-processes to load data to avoid Python’s Global Interpreter Lock (GIL), this approach incurs high memory overhead. Because FFCV’s JIT-compiled code releases the GIL, it can utilize threads instead of processes. This allows workers to share memory and collaborate on the same batch, keeping memory usage constant regardless of the number of workers.
4. Quasi-random Sampling
To reduce the "seek" penalty associated with traditional hard drives and network filesystems, FFCV implements a quasi-random sampling strategy. Instead of sampling from the entire dataset at once, it samples from a large buffer of pages, balancing the need for randomness with the physical constraints of I/O efficiency.
Experimental Evaluation
ImageNet Benchmarks
The primary evaluation of FFCV focuses on the ImageNet (ILSVRC-2012) dataset. The results are significant: FFCV can train a ResNet-50 to 75% accuracy in just 20 minutes on a single machine. In terms of the accuracy-vs-training-time tradeoff, FFCV consistently demonstrates Pareto dominance over standard PyTorch loaders and specialized commercial solutions.
Generalization Beyond Vision
To demonstrate that FFCV’s benefits extend beyond computer vision, the authors tested it on a large-scale sparse linear regression task ($n=100,000, d=50,000$). Simply replacing the default PyTorch loader with FFCV made the solver 1.6 times faster without any algorithmic changes, proving that data bottlenecks are a general problem in large-scale machine learning.
Key Insights
- Quantifying Starvation: On high-end hardware like AWS p4d instances (8x A100 GPUs), standard data loading can take ~1200 seconds per epoch, while the "idealized" training (compute only) would take only ~40 seconds. FFCV aims to reach that 40-second ideal.
- OS-Level Caching: FFCV leverages OS-level caching effectively. When training multiple models on the same dataset (e.g., during hyperparameter tuning), they share the same memory cache, leading to massive speedups in multi-GPU environments.
- Resource Efficiency: FFCV maintains high throughput even in low-memory settings where the dataset cannot fit entirely into RAM, thanks to its optimized I/O and caching strategies.
Limitations and Future Work
FFCV specifically targets data-related stalls. It does not provide speedups for models where the bottleneck is the GPU computation itself, such as extremely large Transformer models or very small datasets that already fit in memory. Additionally, while the framework is extensible, the current implementation is heavily optimized for computer vision. Finally, users must perform a one-time preprocessing step to convert datasets into the .beton format.
Conclusion
FFCV provides a high-performance, easy-to-use library that addresses the often-overlooked data bottleneck in machine learning. By combining efficient storage, JIT compilation, and thread-based concurrency, it allows researchers to utilize their hardware to its full potential, significantly reducing training times and costs. Documentation and support are available at https://ffcv.io/.
Summary updated