{"id":13442860,"url":"https://github.com/libffcv/ffcv","last_synced_at":"2025-05-14T08:08:21.208Z","repository":{"id":37681316,"uuid":"416829986","full_name":"libffcv/ffcv","owner":"libffcv","description":"FFCV: Fast Forward Computer Vision (and other ML workloads!)","archived":false,"fork":false,"pushed_at":"2024-06-16T15:59:22.000Z","size":3449,"stargazers_count":2927,"open_issues_count":118,"forks_count":180,"subscribers_count":20,"default_branch":"main","last_synced_at":"2025-05-12T07:08:08.204Z","etag":null,"topics":["data-science","machine-learning","pytorch"],"latest_commit_sha":null,"homepage":"https://ffcv.io","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/libffcv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-13T17:03:39.000Z","updated_at":"2025-05-11T18:08:26.000Z","dependencies_parsed_at":"2023-02-14T03:17:04.918Z","dependency_job_id":"71451ef9-6d4e-4117-8da7-1b78cd0b166f","html_url":"https://github.com/libffcv/ffcv","commit_stats":{"total_commits":716,"total_committers":29,"mean_commits":"24.689655172413794","dds":0.691340782122905,"last_synced_commit":"6c3be0cabf1485aa2b6945769dbd1c2d12e8faa7"},"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libffcv%2Fffcv","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libffcv%2Fffcv/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libffcv%2Fffcv/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/libffcv%2Fffcv/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/libffcv","download_url":"https://codeload.github.com/libffcv/ffcv/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254101558,"owners_count":22014908,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-science","machine-learning","pytorch"],"created_at":"2024-07-31T03:01:52.266Z","updated_at":"2025-05-14T08:08:16.200Z","avatar_url":"https://github.com/libffcv.png","language":"Python","readme":"\u003cp align = 'center'\u003e\n\u003cem\u003e\u003cb\u003eFast Forward Computer Vision\u003c/b\u003e: train models at a fraction of the cost with accelerated data loading!\u003c/em\u003e\n\u003c/p\u003e\n\u003cimg src='assets/logo.svg' width='100%'/\u003e\n\u003cp align = 'center'\u003e\n\u003c!-- \u003cbr /\u003e --\u003e\n[\u003ca href=\"#install-with-anaconda\"\u003einstall\u003c/a\u003e]\n[\u003ca href=\"#quickstart\"\u003equickstart\u003c/a\u003e]\n[\u003ca href=\"#features\"\u003efeatures\u003c/a\u003e]\n[\u003ca href=\"https://docs.ffcv.io\"\u003edocs\u003c/a\u003e]\n[\u003ca href=\"https://join.slack.com/t/ffcv-workspace/shared_invite/zt-11olgvyfl-dfFerPxlm6WtmlgdMuw_2A\"\u003esupport slack\u003c/a\u003e]\n[\u003ca href=\"https://ffcv.io\"\u003ehomepage\u003c/a\u003e]\n[\u003ca href=\"https://arxiv.org/abs/2306.12517\"\u003epaper\u003c/a\u003e]\n\u003cbr\u003e\nMaintainers:\n\u003ca href=\"https://twitter.com/gpoleclerc\"\u003eGuillaume Leclerc\u003c/a\u003e,\n\u003ca href=\"https://twitter.com/andrew_ilyas\"\u003eAndrew Ilyas\u003c/a\u003e and\n\u003ca href=\"https://twitter.com/logan_engstrom\"\u003eLogan Engstrom\u003c/a\u003e\n\u003c/p\u003e\n\n`ffcv` is a drop-in data loading system that dramatically increases data throughput in model training:\n\n- [Train an ImageNet model](#prepackaged-computer-vision-benchmarks)\non one GPU in 35 minutes (98¢/model on AWS)\n- [Train a CIFAR-10 model](https://docs.ffcv.io/ffcv_examples/cifar10.html)\non one GPU in 36 seconds (2¢/model on AWS)\n- Train a `$YOUR_DATASET` model `$REALLY_FAST` (for `$WAY_LESS`)\n\nKeep your training algorithm the same, just replace the data loader! Look at these speedups:\n\n\u003cimg src=\"assets/headline.svg\" width='830px'/\u003e\n\n`ffcv` also comes prepacked with [fast, simple code](https://github.com/libffcv/imagenet-example) for [standard vision benchmarks]((https://docs.ffcv.io/benchmarks.html)):\n\n\u003cimg src=\"docs/_static/perf_scatterplot.svg\" width='830px'/\u003e\n\n## Installation\n### Linux\n```\nconda create -y -n ffcv python=3.9 cupy pkg-config libjpeg-turbo opencv pytorch torchvision cudatoolkit=11.3 numba -c pytorch -c conda-forge\nconda activate ffcv\npip install ffcv\n```\nTroubleshooting 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.\n\nTroubleshooting note 2: on some systems (but rarely), you'll need to add the ``compilers`` package to the first command above.\n\nTroubleshooting note 3: courtesy of @kschuerholt, here is a [Dockerfile](https://github.com/kschuerholt/pytorch_cuda_opencv_ffcv_docker) that may help with conda-free installation\n\n### Windows\n* Install \u003ca href=\"https://opencv.org/releases/\"\u003eopencv4\u003c/a\u003e\n  * Add `..../opencv/build/x64/vc15/bin` to PATH environment variable\n* Install \u003ca href=\"https://sourceforge.net/projects/libjpeg-turbo/files/\"\u003elibjpeg-turbo\u003c/a\u003e, download libjpeg-turbo-x.x.x-vc64.exe, not gcc64\n  * Add `..../libjpeg-turbo64/bin` to PATH environment variable\n* Install \u003ca href=\"https://www.sourceware.org/pthreads-win32/\"\u003epthread\u003c/a\u003e, download last release.zip\n  * After unzip, rename Pre-build.2 folder to pthread\n  * Open `pthread/include/pthread.h`, and add the code below to the top of the file.  \n  ```cpp\n  #define HAVE_STRUCT_TIMESPEC\n  ```\n  * Add `..../pthread/dll` to PATH environment variable\n* Install \u003ca href=\"https://docs.cupy.dev/en/stable/install.html#installing-cupy\"\u003ecupy\u003c/a\u003e depending on your CUDA Toolkit version.\n* `pip install ffcv`\n\n## Citation\nIf you use FFCV, please cite it as:\n\n```\n@inproceedings{leclerc2023ffcv,\n    author = {Guillaume Leclerc and Andrew Ilyas and Logan Engstrom and Sung Min Park and Hadi Salman and Aleksander Madry},\n    title = {{FFCV}: Accelerating Training by Removing Data Bottlenecks},\n    year = {2023},\n    booktitle = {Computer Vision and Pattern Recognition (CVPR)},\n    note = {\\url{https://github.com/libffcv/ffcv/}. commit xxxxxxx}\n}\n```\n(Make sure to replace xxxxxxx above with the hash of the commit used!)\n\n## Quickstart\nAccelerate \u003ca href=\"#features\"\u003e*any*\u003c/a\u003e learning system with `ffcv`.\nFirst,\nconvert your dataset into `ffcv` format (`ffcv` converts both indexed PyTorch datasets and\n\u003ca href=\"https://github.com/webdataset/webdataset\"\u003eWebDatasets\u003c/a\u003e):\n```python\nfrom ffcv.writer import DatasetWriter\nfrom ffcv.fields import RGBImageField, IntField\n\n# Your dataset (`torch.utils.data.Dataset`) of (image, label) pairs\nmy_dataset = make_my_dataset()\nwrite_path = '/output/path/for/converted/ds.beton'\n\n# Pass a type for each data field\nwriter = DatasetWriter(write_path, {\n    # Tune options to optimize dataset size, throughput at train-time\n    'image': RGBImageField(max_resolution=256),\n    'label': IntField()\n})\n\n# Write dataset\nwriter.from_indexed_dataset(my_dataset)\n```\nThen replace your old loader with the `ffcv` loader at train time (in PyTorch,\nno other changes required!):\n```python\nfrom ffcv.loader import Loader, OrderOption\nfrom ffcv.transforms import ToTensor, ToDevice, ToTorchImage, Cutout\nfrom ffcv.fields.decoders import IntDecoder, RandomResizedCropRGBImageDecoder\n\n# Random resized crop\ndecoder = RandomResizedCropRGBImageDecoder((224, 224))\n\n# Data decoding and augmentation\nimage_pipeline = [decoder, Cutout(), ToTensor(), ToTorchImage(), ToDevice(0)]\nlabel_pipeline = [IntDecoder(), ToTensor(), ToDevice(0)]\n\n# Pipeline for each data field\npipelines = {\n    'image': image_pipeline,\n    'label': label_pipeline\n}\n\n# Replaces PyTorch data loader (`torch.utils.data.Dataloader`)\nloader = Loader(write_path, batch_size=bs, num_workers=num_workers,\n                order=OrderOption.RANDOM, pipelines=pipelines)\n\n# rest of training / validation proceeds identically\nfor epoch in range(epochs):\n    ...\n```\n[See here](https://docs.ffcv.io/basics.html) for a more detailed guide to deploying `ffcv` for your dataset.\n\n## Prepackaged Computer Vision Benchmarks\nFrom gridding to benchmarking to fast research iteration, there are many reasons\nto want faster model training. Below we present premade codebases for training\non ImageNet and CIFAR, including both (a) extensible codebases and (b)\nnumerous premade training configurations.\n\n### ImageNet\nWe provide a self-contained script for training ImageNet \u003cit\u003efast\u003c/it\u003e.\nAbove we plot the training time versus\naccuracy frontier, and the dataloading speeds, for 1-GPU ResNet-18 and 8-GPU\nResNet-50 alongside a few baselines.\n\n\n| Link to Config                                                                                                                         |   top_1 |   top_5 |   # Epochs |   Time (mins) | Architecture   | Setup    |\n|:---------------------------------------------------------------------------------------------------------------------------------------|--------:|--------:|-----------:|--------------:|:---------------|:---------|\n| \u003ca href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn50_configs/rn50_88_epochs.yaml'\u003eLink\u003c/a\u003e | 0.784 | 0.941  |         88 |       77.2 | ResNet-50      | 8 x A100 |\n| \u003ca href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn50_configs/rn50_56_epochs.yaml'\u003eLink\u003c/a\u003e | 0.780 | 0.937 |         56 |       49.4 | ResNet-50      | 8 x A100 |\n| \u003ca href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn50_configs/rn50_40_epochs.yaml'\u003eLink\u003c/a\u003e | 0.772 | 0.932 |         40 |       35.6 | ResNet-50      | 8 x A100 |\n| \u003ca href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn50_configs/rn50_32_epochs.yaml'\u003eLink\u003c/a\u003e | 0.766 | 0.927 |         32 |       28.7 | ResNet-50      | 8 x A100 |\n| \u003ca href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn50_configs/rn50_24_epochs.yaml'\u003eLink\u003c/a\u003e | 0.756 | 0.921 |         24 |       21.7  | ResNet-50      | 8 x A100 |\n| \u003ca href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn50_configs/rn50_16_epochs.yaml'\u003eLink\u003c/a\u003e | 0.738 | 0.908 |         16 |       14.9 | ResNet-50      | 8 x A100 |\n| \u003ca href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn18_configs/rn18_88_epochs.yaml'\u003eLink\u003c/a\u003e | 0.724 | 0.903   |         88 |      187.3  | ResNet-18      | 1 x A100 |\n| \u003ca href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn18_configs/rn18_56_epochs.yaml'\u003eLink\u003c/a\u003e | 0.713  | 0.899 |         56 |      119.4   | ResNet-18      | 1 x A100 |\n| \u003ca href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn18_configs/rn18_40_epochs.yaml'\u003eLink\u003c/a\u003e | 0.706 | 0.894 |         40 |       85.5 | ResNet-18      | 1 x A100 |\n| \u003ca href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn18_configs/rn18_32_epochs.yaml'\u003eLink\u003c/a\u003e | 0.700 | 0.889 |         32 |       68.9   | ResNet-18      | 1 x A100 |\n| \u003ca href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn18_configs/rn18_24_epochs.yaml'\u003eLink\u003c/a\u003e | 0.688  | 0.881 |         24 |       51.6 | ResNet-18      | 1 x A100 |\n| \u003ca href='https://github.com/libffcv/ffcv-imagenet/tree/main/rn18_configs/rn18_16_epochs.yaml'\u003eLink\u003c/a\u003e | 0.669 | 0.868 |         16 |       35.0 | ResNet-18      | 1 x A100 |\n\n**Train your own ImageNet models!** You can \u003ca href=\"https://github.com/libffcv/imagenet-example/tree/main\"\u003euse our training script and premade configurations\u003c/a\u003e to train any model seen on the above graphs.\n\n### CIFAR-10\nWe also include premade code for efficient training on CIFAR-10 in the `examples/`\ndirectory, obtaining 93\\% top1 accuracy in 36 seconds on a single A100 GPU\n(without optimizations such as MixUp, Ghost BatchNorm, etc. which have the\npotential to raise the accuracy even further). You can find the training script\n\u003ca href=\"https://github.com/libffcv/ffcv/tree/main/examples/cifar\"\u003ehere\u003c/a\u003e.\n\n## Features\n\u003cimg src='docs/_static/clippy-transparent-2.png' width='100%'/\u003e\n\nComputer vision or not, FFCV can help make training faster in a variety of\nresource-constrained settings!\nOur \u003ca href=\"https://docs.ffcv.io/performance_guide.html\"\u003eperformance guide\u003c/a\u003e\nhas a more detailed account of the ways in which FFCV can adapt to different\nperformance bottlenecks.\n\n\n- **Plug-and-play with any existing training code**: Rather than changing\n  aspects of model training itself, FFCV focuses on removing *data bottlenecks*,\n  which turn out to be a problem everywhere from neural network training to\n  linear regression. This means that:\n\n    - FFCV can be introduced into any existing training code in just a few\n      lines of code (e.g., just swapping out the data loader and optionally the\n      augmentation pipeline);\n    - You don't have to change the model itself to make it faster (e.g., feel\n      free to analyze models *without* CutMix, Dropout, momentum scheduling, etc.);\n    - FFCV can speed up a lot more beyond just neural network training---in\n      fact, the more data-bottlenecked the application (e.g., linear regression,\n      bulk inference, etc.), the faster FFCV will make it!\n\n  See our [Getting started](https://docs.ffcv.io/basics.html) guide,\n  [Example walkthroughs](https://docs.ffcv.io/examples.html), and\n  [Code examples](https://github.com/libffcv/ffcv/tree/main/examples)\n  to see how easy it is to get started!\n- **Fast data processing without the pain**: FFCV automatically handles data\n  reading, pre-fetching, caching, and transfer between devices in an extremely\n  efficiently way, so that users don't have to think about it.\n- **Automatically fused-and-compiled data processing**: By either using\n  [pre-written](https://docs.ffcv.io/api/transforms.html) FFCV transformations\n  or\n  [easily writing custom ones](https://docs.ffcv.io/ffcv_examples/custom_transforms.html),\n  users can\n  take advantage of FFCV's compilation and pipelining abilities, which will\n  automatically fuse and compile simple Python augmentations to machine code\n  using [Numba](https://numba.pydata.org), and schedule them asynchronously to avoid\n  loading delays.\n- **Load data fast from RAM, SSD, or networked disk**: FFCV exposes\n  user-friendly options that can be adjusted based on the resources\n  available. For example, if a dataset fits into memory, FFCV can cache it\n  at the OS level and ensure that multiple concurrent processes all get fast\n  data access. Otherwise, FFCV can use fast process-level caching and will\n  optimize data loading to minimize the underlying number of disk reads. See\n  [The Bottleneck Doctor](https://docs.ffcv.io/bottleneck_doctor.html)\n  guide for more information.\n- **Training multiple models per GPU**: Thanks to fully asynchronous\n  thread-based data loading, you can now interleave training multiple models on\n  the same GPU efficiently, without any data-loading overhead. See\n  [this guide](https://docs.ffcv.io/parameter_tuning.html) for more info.\n- **Dedicated tools for image handling**: All the features above work are\n  equally applicable to all sorts of machine learning models, but FFCV also\n  offers some vision-specific features, such as fast JPEG encoding and decoding,\n  storing datasets as mixtures of raw and compressed images to trade off I/O\n  overhead and compute overhead, etc. See the\n  [Working with images](https://docs.ffcv.io/working_with_images.html) guide for\n  more information.\n\n# Contributors\n\n- [Guillaume Leclerc](https://github.com/GuillaumeLeclerc)\n- [Logan Engstrom](http://loganengstrom.com/)\n- [Andrew Ilyas](http://andrewilyas.com/)\n- [Sam Park](http://sungminpark.com/)\n- [Hadi Salman](http://hadisalman.com/)\n","funding_links":[],"categories":["Python","Data Processing","CV"],"sub_categories":["Data Pre-processing \u0026 Loading"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibffcv%2Fffcv","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flibffcv%2Fffcv","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flibffcv%2Fffcv/lists"}