Home

Awesome

<p align = 'center'> <em><b>Fast Forward Computer Vision</b>: train models at a fraction of the cost with accelerated data loading!</em> </p> <img src='assets/logo.svg' width='100%'/> <p align = 'center'> <!-- <br /> --> [<a href="#install-with-anaconda">install</a>] [<a href="#quickstart">quickstart</a>] [<a href="#features">features</a>] [<a href="https://docs.ffcv.io">docs</a>] [<a href="https://join.slack.com/t/ffcv-workspace/shared_invite/zt-11olgvyfl-dfFerPxlm6WtmlgdMuw_2A">support slack</a>] [<a href="https://ffcv.io">homepage</a>] [<a href="https://arxiv.org/abs/2306.12517">paper</a>] <br> Maintainers: <a href="https://twitter.com/gpoleclerc">Guillaume Leclerc</a>, <a href="https://twitter.com/andrew_ilyas">Andrew Ilyas</a> and <a href="https://twitter.com/logan_engstrom">Logan Engstrom</a> </p>

ffcv is a drop-in data loading system that dramatically increases data throughput in model training:

Keep your training algorithm the same, just replace the data loader! Look at these speedups:

<img src="assets/headline.svg" width='830px'/>

ffcv also comes prepacked with fast, simple code for standard vision benchmarks:

<img src="docs/_static/perf_scatterplot.svg" width='830px'/>

Installation

Linux

conda create -y -n ffcv python=3.9 cupy pkg-config libjpeg-turbo opencv pytorch torchvision cudatoolkit=11.3 numba -c pytorch -c conda-forge
conda activate ffcv
pip install ffcv

Troubleshooting note 1: if the above commands result in a package conflict error, try running conda config --env --set channel_priority flexible in the environment and rerunning the installation command.

Troubleshooting note 2: on some systems (but rarely), you'll need to add the compilers package to the first command above.

Troubleshooting note 3: courtesy of @kschuerholt, here is a Dockerfile that may help with conda-free installation

Windows

Citation

If you use FFCV, please cite it as:

@inproceedings{leclerc2023ffcv,
    author = {Guillaume Leclerc and Andrew Ilyas and Logan Engstrom and Sung Min Park and Hadi Salman and Aleksander Madry},
    title = {{FFCV}: Accelerating Training by Removing Data Bottlenecks},
    year = {2023},
    booktitle = {Computer Vision and Pattern Recognition (CVPR)},
    note = {\url{https://github.com/libffcv/ffcv/}. commit xxxxxxx}
}

(Make sure to replace xxxxxxx above with the hash of the commit used!)

Quickstart

Accelerate <a href="#features">any</a> learning system with ffcv. First, convert your dataset into ffcv format (ffcv converts both indexed PyTorch datasets and <a href="https://github.com/webdataset/webdataset">WebDatasets</a>):

from ffcv.writer import DatasetWriter
from ffcv.fields import RGBImageField, IntField

# Your dataset (`torch.utils.data.Dataset`) of (image, label) pairs
my_dataset = make_my_dataset()
write_path = '/output/path/for/converted/ds.beton'

# Pass a type for each data field
writer = DatasetWriter(write_path, {
    # Tune options to optimize dataset size, throughput at train-time
    'image': RGBImageField(max_resolution=256),
    'label': IntField()
})

# Write dataset
writer.from_indexed_dataset(my_dataset)

Then replace your old loader with the ffcv loader at train time (in PyTorch, no other changes required!):

from ffcv.loader import Loader, OrderOption
from ffcv.transforms import ToTensor, ToDevice, ToTorchImage, Cutout
from ffcv.fields.decoders import IntDecoder, RandomResizedCropRGBImageDecoder

# Random resized crop
decoder = RandomResizedCropRGBImageDecoder((224, 224))

# Data decoding and augmentation
image_pipeline = [decoder, Cutout(), ToTensor(), ToTorchImage(), ToDevice(0)]
label_pipeline = [IntDecoder(), ToTensor(), ToDevice(0)]

# Pipeline for each data field
pipelines = {
    'image': image_pipeline,
    'label': label_pipeline
}

# Replaces PyTorch data loader (`torch.utils.data.Dataloader`)
loader = Loader(write_path, batch_size=bs, num_workers=num_workers,
                order=OrderOption.RANDOM, pipelines=pipelines)

# rest of training / validation proceeds identically
for epoch in range(epochs):
    ...

See here for a more detailed guide to deploying ffcv for your dataset.

Prepackaged Computer Vision Benchmarks

From gridding to benchmarking to fast research iteration, there are many reasons to want faster model training. Below we present premade codebases for training on ImageNet and CIFAR, including both (a) extensible codebases and (b) numerous premade training configurations.

ImageNet

We provide a self-contained script for training ImageNet <it>fast</it>. Above we plot the training time versus accuracy frontier, and the dataloading speeds, for 1-GPU ResNet-18 and 8-GPU ResNet-50 alongside a few baselines.

Link to Configtop_1top_5# EpochsTime (mins)ArchitectureSetup
<a href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn50_configs/rn50_88_epochs.yaml'>Link</a>0.7840.9418877.2ResNet-508 x A100
<a href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn50_configs/rn50_56_epochs.yaml'>Link</a>0.7800.9375649.4ResNet-508 x A100
<a href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn50_configs/rn50_40_epochs.yaml'>Link</a>0.7720.9324035.6ResNet-508 x A100
<a href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn50_configs/rn50_32_epochs.yaml'>Link</a>0.7660.9273228.7ResNet-508 x A100
<a href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn50_configs/rn50_24_epochs.yaml'>Link</a>0.7560.9212421.7ResNet-508 x A100
<a href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn50_configs/rn50_16_epochs.yaml'>Link</a>0.7380.9081614.9ResNet-508 x A100
<a href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn18_configs/rn18_88_epochs.yaml'>Link</a>0.7240.90388187.3ResNet-181 x A100
<a href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn18_configs/rn18_56_epochs.yaml'>Link</a>0.7130.89956119.4ResNet-181 x A100
<a href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn18_configs/rn18_40_epochs.yaml'>Link</a>0.7060.8944085.5ResNet-181 x A100
<a href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn18_configs/rn18_32_epochs.yaml'>Link</a>0.7000.8893268.9ResNet-181 x A100
<a href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn18_configs/rn18_24_epochs.yaml'>Link</a>0.6880.8812451.6ResNet-181 x A100
<a href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn18_configs/rn18_16_epochs.yaml'>Link</a>0.6690.8681635.0ResNet-181 x A100

Train your own ImageNet models! You can <a href="https://github.com/libffcv/imagenet-example/tree/main">use our training script and premade configurations</a> to train any model seen on the above graphs.

CIFAR-10

We also include premade code for efficient training on CIFAR-10 in the examples/ directory, obtaining 93% top1 accuracy in 36 seconds on a single A100 GPU (without optimizations such as MixUp, Ghost BatchNorm, etc. which have the potential to raise the accuracy even further). You can find the training script <a href="https://github.com/libffcv/ffcv/tree/main/examples/cifar">here</a>.

Features

<img src='docs/_static/clippy-transparent-2.png' width='100%'/>

Computer vision or not, FFCV can help make training faster in a variety of resource-constrained settings! Our <a href="https://docs.ffcv.io/performance_guide.html">performance guide</a> has a more detailed account of the ways in which FFCV can adapt to different performance bottlenecks.

Contributors