Skip to main content

TurboLoader

Production-Ready ML Data Loading Library

PyPI version Tests Python 3.10+ C++20 License: MIT


Overview

TurboLoader is a high-performance data loading library for machine learning workflows. Built with C++20 and featuring Python bindings, it provides efficient data loading with SIMD-accelerated transforms, custom binary formats, and distributed training support.

Core Features

  • Decoded Tensor Caching - FastDataLoader(..., cache_decoded=True) keeps decoded arrays in RAM so later epochs skip decoding
  • Multiple Loader Types - FastDataLoader, MemoryEfficientDataLoader, standard DataLoader
  • Distributed Training Support - Multi-node data loading with deterministic sharding
  • SIMD-Accelerated Transforms - 19 vectorized transforms using AVX2/AVX-512/NEON
  • TBL v2 Binary Format - Custom format with LZ4 compression for reduced storage
  • Framework Integration - Seamless support for PyTorch, TensorFlow, and JAX
  • Memory-Mapped I/O - Zero-copy file access for improved throughput
  • Lock-Free Queues - Concurrent data structures for efficient multi-threading
  • GPU JPEG Decoding - Optional NVIDIA nvJPEG support for accelerated decoding

Installation

From PyPI (Recommended)

pip install turboloader

From Source

git clone https://github.com/ALJainProjects/TurboLoader.git
cd TurboLoader
pip install -e .

System Requirements

  • Python: 3.10 or higher
  • Compiler: C++20 capable (GCC 10+, Clang 12+, MSVC 19.29+)
  • OS: macOS, Linux, Windows

Optional Dependencies

Install for enhanced performance:

# macOS
brew install jpeg-turbo libpng libwebp lz4

# Ubuntu/Debian
sudo apt-get install libjpeg-turbo8-dev libpng-dev libwebp-dev liblz4-dev

Quick Start

Basic Usage

import turboloader

# Create DataLoader
loader = turboloader.DataLoader(
    'imagenet.tar',
    batch_size=128,
    num_workers=8
)

# Iterate over batches. Each sample is a dict:
#   {'image': np.ndarray (H, W, C), 'filename': str, 'index': int,
#    'width': int, 'height': int, 'channels': int}
for batch in loader:
    for sample in batch:
        image = sample['image']      # NumPy array (H, W, C)
        name = sample['filename']    # source path within the archive
        # Train your model...

Need (image, label) tuples like torch.utils.data.DataLoader? Use PyTorchCompatibleLoader, which derives labels from the folder structure (ImageFolder-style). The base DataLoader does not attach labels.

With Transforms

import turboloader

# Create transforms
resize = turboloader.Resize(224, 224)
normalize = turboloader.ImageNetNormalize()
flip = turboloader.RandomHorizontalFlip(p=0.5)

# Apply transforms
loader = turboloader.DataLoader('data.tar', batch_size=64, num_workers=8)

for batch in loader:
    for sample in batch:
        img = sample['image']
        img = resize.apply(img)
        img = flip.apply(img)
        img = normalize.apply(img)
        # Ready for training

PyTorch Integration

import turboloader
import torch

loader = turboloader.DataLoader('imagenet.tar', batch_size=64, num_workers=8)

# Convert to PyTorch tensors
to_tensor = turboloader.ToTensor(
    format=turboloader.TensorFormat.PYTORCH_CHW
)

for batch in loader:
    images = []
    for sample in batch:
        img = to_tensor.apply(sample['image'])
        images.append(torch.from_numpy(img))

    batch_tensor = torch.stack(images)
    # Train model...

Distributed Training

import turboloader
import torch.distributed as dist

# Initialize distributed training
dist.init_process_group(backend='nccl')

# Create loader with distributed support
loader = turboloader.DataLoader(
    data_path="/data/imagenet.tar",
    batch_size=64,
    num_workers=4,
    shuffle=True,
    enable_distributed=True,
    world_rank=dist.get_rank(),
    world_size=dist.get_world_size(),
    drop_last=True
)

# Each rank automatically gets its shard
for batch in loader:
    # Your training code
    pass

Transform Library

TurboLoader includes 24 transforms (19 per-image SIMD transforms + 5 batch augmentations). The authoritative list is turboloader.list_transforms().

Core Transforms

  • Resize - Bilinear/Bicubic/Lanczos interpolation
  • Normalize - Mean/std normalization with SIMD
  • CenterCrop - Center region extraction
  • RandomCrop - Random crop with padding

Augmentation Transforms

  • RandomHorizontalFlip - SIMD horizontal flip
  • RandomVerticalFlip - SIMD vertical flip
  • ColorJitter - Brightness/contrast/saturation/hue
  • RandomRotation - Arbitrary angle rotation
  • GaussianBlur - Separable convolution
  • RandomErasing - Cutout augmentation
  • Pad - Border padding (CONSTANT/EDGE/REFLECT)

Advanced Transforms

  • RandomPosterize - Bit-depth reduction
  • RandomSolarize - Threshold inversion
  • RandomPerspective - Perspective warp
  • AutoAugment - Learned policies (ImageNet/CIFAR10/SVHN)

Batch Augmentations

  • MixUp, CutMix, Mosaic, RandAugment, GridMask

Tensor Conversion

  • ToTensor - PyTorch CHW or TensorFlow HWC format

TBL v2 Binary Format

TurboLoader includes a custom binary format optimized for ML workloads:

Features

  • LZ4 compression for reduced storage
  • Memory-mapped access for fast loading
  • O(1) random access via indexed structure
  • Data integrity validation with CRC checksums
  • Cached image dimensions for filtered loading

Convert TAR to TBL

import tarfile
import turboloader

writer = turboloader.TblWriterV2("/data/imagenet.tbl", enable_compression=True)

# The TAR archive is read with Python's stdlib (TurboLoader does not expose a
# standalone Python TarReader; the DataLoader reads TAR directly for training).
with tarfile.open("/data/imagenet.tar") as tar:
    for member in tar.getmembers():
        if not member.name.lower().endswith((".jpg", ".jpeg")):
            continue
        data = tar.extractfile(member).read()
        writer.add_sample(data=data, format=turboloader.SampleFormat.JPEG)

writer.finalize()

For bulk conversion there is also a C++ CLI tool, tools/tar_to_tbl_v2.cpp.


Documentation

Getting Started

API Documentation

Framework Integration

Examples


Benchmarks

Measured on Apple Silicon over Imagenette-160 (9,469 real ImageNet JPEGs → resize 160×160 → ImageNet-normalize → batched CHW float32, batch 64). To control for thermal throttling, every loader is built once, warmed up one epoch, then timed over 5 interleaved rounds (each loader runs once per round); the table reports the median. Output is verified correct against torchvision (mean abs diff ≈ 0.04, bilinear antialiasing only).

Image — on-the-fly decode (re-decode every epoch; for datasets too large to cache or with per-epoch random augmentation):

Loader img/s (median) vs tf.data
TurboLoader DataLoader (output_format='pytorch', nw=6) ~55,000 2.0×
TensorFlow tf.data (AUTOTUNE) ~27,300 1.00×
PyTorch DataLoader (PIL, 8 persistent workers) ~20,500 0.75×

Image — cached (decoded tensors held in RAM; both sides consume identically via np.sum, i.e. delivered as numpy/torch-ready batches — the PyTorch use case):

Loader img/s (median) vs tf.data.cache
TurboLoader (cache_decoded=True, prefetch) ~67,000 1.9×
TensorFlow tf.data.cache() (+ .numpy() materialize) ~35,100 1.00×

(For TF-native consumption that stays in tf tensors, tf.data.cache() is faster — TurboLoader's cache win is for delivering numpy/torch batches.)

LLM tokens (real text, 55M-token memory-mapped corpus, seq_len=1024, next-token):

Loader sequences/s (median)
TurboLoader TokenDataLoader ~467,000
numpy memmap idiom (nanoGPT get_batch) ~251,000

Transforms (per-image throughput vs torchvision): Resize 2.7×, ImageNetNormalize 3.3×, HFlip ~1.0×. For CenterCrop, torchvision returns a lazy strided view (moves zero bytes); compared against TurboLoader's real contiguous crop that looks like 0.45×, but when torchvision actually materializes the crop (.contiguous(), required before batching/most ops) it drops to ~23k img/s and TurboLoader's contiguous crop is ~6.8× faster (155k vs 23k). Like the cache, this is a lazy-vs-eager comparison; for the realistic crop→batch path TurboLoader wins.

Earlier drafts quoted single-run figures (~42k, "1.4×") and a "cached epoch" in the tens-of-millions img/s. Those were artifacts (thermal noise; a no-op loop over aliased cached arrays) and were replaced with the interleaved, identical-consumption medians above. Numbers are hardware-dependent — run benchmarks/ yourself.

The fast path runs decode + resize + normalize + batch assembly in C++ across a thread pool with zero Python per-sample work. Use it like this:

loader = turboloader.DataLoader(
    'imagenet.tar', batch_size=64, num_workers=6,
    output_format='pytorch',          # (N, C, H, W) float32 array per batch
    image_size=160,                   # exact resize, done in C++
    transform=turboloader.ImageNetNormalize())
for epoch in range(epochs):           # re-iterable
    for images, meta in loader:       # images.shape == (64, 3, 160, 160)
        train_step(images)

Honest caveats:

  • Run it yourself (benchmarks/) — results depend heavily on hardware, image size, and pipeline; Linux fork-based PyTorch workers shift the PyTorch numbers a lot.
  • Decode backend differs: TurboLoader uses libjpeg-turbo; the PyTorch baseline uses PIL.
  • The output_format='dict' path returns per-sample dicts and stacks in Python (GIL-bound), so it is much slower — use it only when you need per-sample metadata.

For large source images, the default path also wins: on 768×768 JPEGs resized to 160 it runs ~15,000 img/s — faster than even an expertly-tuned tf.data pipeline using manual decode_jpeg(ratio=...) (~14,400) — because it picks the libjpeg-turbo DCT scaled-decode factor automatically (you don't have to know to set ratio).

Implementation notes

  • Direct-batch path (src/pipeline/direct_batch_loader.hpp): the default fast path is FFCV/tf.data-style — a persistent thread pool reads JPEG bytes by index and decodes → resizes → normalizes directly into the output batch buffer in one parallel pass (no worker queue, no per-sample heap copy, no serial collection). Verified memory-safe and race-free (disjoint slot writes, const mmap reads, atomic cursor, per-thread decoders).
  • Automatic DCT scaled decode: large JPEGs are decoded at the nearest libjpeg-turbo scale ≥ target, then finely resized — much faster than full-decode + resize.
  • Resize convention: half-pixel centers (align_corners=False), matching PIL/OpenCV/PyTorch/TF (agrees with torchvision plain bilinear to ~0.4/255; the only remaining difference vs torchvision's default is its antialiasing low-pass filter).
  • SIMD transforms (AVX2/AVX-512/NEON), libjpeg-turbo decode, lock-free SPSC queues (legacy/dict + remote path), persistent std::thread pool (src/core/parallel_for.hpp).
  • The GIL is released during C++ processing.
  • OpenMP is opt-in (TURBOLOADER_ENABLE_OPENMP=1); off by default because linking a second OpenMP runtime crashes alongside PyTorch on macOS — the thread pool replaces it.

Beyond Images: Tokens & Arrays

TurboLoader also ships loaders for non-image modalities with the same ergonomics (re-iterable, shuffle, set_epoch, batched arrays):

# LLM pretraining: memory-mapped token stream -> (B, seq_len) next-token batches
loader = turboloader.TokenDataLoader('train.bin', seq_len=1024, batch_size=8,
                                     dtype='uint16', shuffle=True)
for x, y in loader:          # x, y: (8, 1024) int64; y is x shifted by one
    loss = model(x, y)

# Generic arrays/memmaps (embeddings, tabular features, labels, pre-tokenized data)
loader = turboloader.ArrayDataLoader(features, labels, batch_size=256, shuffle=True)
for xb, yb in loader:
    ...

TokenDataLoader uses a vectorized fancy-index gather over a np.memmap (so multi-GB corpora stream without loading into RAM) and benchmarks ~1.9× the standard nanoGPT get_batch idiom. The image pipeline (decode/transform/TBL) remains C++; these modality loaders are NumPy-based and modality-agnostic.

All three modalities are also reachable from the single DataLoader entry point:

turboloader.DataLoader('train.bin', modality='tokens', seq_len=1024, batch_size=8)
turboloader.DataLoader(arrays=[feats, labels], data_path=None, modality='array', batch_size=256)
turboloader.DataLoader('data.tar', image_size=160, output_format='pytorch')   # modality='image' (default)

Architecture

TurboLoader uses a multi-threaded pipeline architecture:

┌─────────────────────────────────────────────┐
│           Memory-Mapped Reader              │
│     (TAR/TBL v2 with zero-copy access)      │
└──────────────┬──────────────────────────────┘
               │
        ┌──────▼──────┐
        │Worker Pool  │
        │  (N threads)│
        ├─────────────┤
        │ Decode      │
        │ Transform   │
        │ Convert     │
        └──────┬──────┘
               │
        ┌──────▼──────────────┐
        │ Lock-Free Queue     │
        └──────┬──────────────┘
               │
        ┌──────▼──────┐
        │Python API   │
        └─────────────┘

Key Components

  • Memory-Mapped I/O - Zero-copy file access
  • Worker Thread Pool - Parallel processing with per-thread decoders
  • SIMD Transforms - Vectorized operations (AVX2/AVX-512/NEON)
  • Lock-Free Queues - High-performance concurrent data structures

License

TurboLoader is released under the MIT License.


Citation

If you use TurboLoader in your research:

@software{turboloader,
  author = {Jain, Arnav},
  title = {TurboLoader: High-Performance ML Data Loading},
  year = {2026},
  version = {2.25.0},
  url = {https://github.com/ALJainProjects/TurboLoader}
}

Support


TurboLoader - High-performance ML data loading with a C++20 core and SIMD transforms.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

turboloader-2.26.0.tar.gz (609.5 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

turboloader-2.26.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

turboloader-2.26.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.5 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

turboloader-2.26.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

turboloader-2.26.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.5 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

turboloader-2.26.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

turboloader-2.26.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.5 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

turboloader-2.26.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (10.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

turboloader-2.26.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (9.5 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

File details

Details for the file turboloader-2.26.0.tar.gz.

File metadata

  • Download URL: turboloader-2.26.0.tar.gz
  • Upload date:
  • Size: 609.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for turboloader-2.26.0.tar.gz
Algorithm Hash digest
SHA256 38d27ec85f268c0f683873c273eb975ef080e7280cb459a4f5f326e95d6210ec
MD5 f6332cb053ce4375eb6b7f17bd5d8530
BLAKE2b-256 b4df1552391e5068605efd5894a752d5b575f667a6d9852d69e98fea1d9e4af7

See more details on using hashes here.

Provenance

The following attestation bundles were made for turboloader-2.26.0.tar.gz:

Publisher: build-wheels.yml on ALJainProjects/TurboLoader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file turboloader-2.26.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for turboloader-2.26.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 11e6ab736052987f7f78eed4a40e2cb81de52a850f957a2458ada36247e7c3e9
MD5 67035b506dbefab6932d6bda8a36abb6
BLAKE2b-256 c57461fef6ef4bc351bd5d5f209102af6a993eab70b4116f5e8c60d1b48494bf

See more details on using hashes here.

Provenance

The following attestation bundles were made for turboloader-2.26.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on ALJainProjects/TurboLoader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file turboloader-2.26.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for turboloader-2.26.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1eaba5ca6302b520bda3563b148a66d2cb38caf5e7dfff7262b8ac5d038aa31b
MD5 8a7030036b1200f7f2ca7f84122be7fa
BLAKE2b-256 4bff13a9c680d9944bb3019e8b3c70871ded9547ad6822542f4f91612c852a7c

See more details on using hashes here.

Provenance

The following attestation bundles were made for turboloader-2.26.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: build-wheels.yml on ALJainProjects/TurboLoader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file turboloader-2.26.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for turboloader-2.26.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1a4a4ee1b85243b47b8c5e10bcd213b8d8fa0c27b2559562e4ec8d1d7464f8f4
MD5 4dd239ac99d55c564503352caf35cb88
BLAKE2b-256 26708072cc5ed386d253a9004a220f13cbc6e1c3c91b1995d6d89d14698fd2d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for turboloader-2.26.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on ALJainProjects/TurboLoader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file turboloader-2.26.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for turboloader-2.26.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 59f7aab6ac9a77e9ad0e67033a8bbefe70b397597e7066d22f5f28da922d4fb0
MD5 279b07aa805d185bdc49368007da1835
BLAKE2b-256 1c1c1714f5b6e339d070e6d3bfac95181b9a82e590fc4a5bc215d91772f3f08d

See more details on using hashes here.

Provenance

The following attestation bundles were made for turboloader-2.26.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: build-wheels.yml on ALJainProjects/TurboLoader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file turboloader-2.26.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for turboloader-2.26.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 06b34636a3b280d5760c22c0f6e9d9dac3d3f6cbaf0dd0d455a489a1a16546f9
MD5 8b2edfbaa250d7c161b166f5ed9fe28d
BLAKE2b-256 fa7f2457191ba43bfb950621183297c1694026da69b6679cffde9ef011df6e80

See more details on using hashes here.

Provenance

The following attestation bundles were made for turboloader-2.26.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on ALJainProjects/TurboLoader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file turboloader-2.26.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for turboloader-2.26.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8a875ff0bdcb5dc606a1b842f0b3ccbdbc687a0f7d00a4412a22754c378ebe32
MD5 7df6885ec8cd8cc74c44a8c3606646de
BLAKE2b-256 48c5ec1594219d428619e6ae8d3e6b345d3e76ab0b17016a43cc804bf2c9e34b

See more details on using hashes here.

Provenance

The following attestation bundles were made for turboloader-2.26.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: build-wheels.yml on ALJainProjects/TurboLoader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file turboloader-2.26.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for turboloader-2.26.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 81d98182ababebe60e4066308d00ab2f4ebb21c7c90eb0c89645c69b9619f8cd
MD5 df462895af1a8c6191f1053b3500927f
BLAKE2b-256 e6bad8ebb39594135e5ebd708ead3ded1555cdc9faf6e79ed80c53a696817cd9

See more details on using hashes here.

Provenance

The following attestation bundles were made for turboloader-2.26.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: build-wheels.yml on ALJainProjects/TurboLoader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file turboloader-2.26.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for turboloader-2.26.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e6dfc750772250ef5cd803701be2a393cdb257b17cae9370875c84faa1afd6a4
MD5 b5908edeae47ac6873d47446a3dcac8a
BLAKE2b-256 8d38735a465f6dd4fd4e6a095e942adeb1a2a8d8c8aba4c4f1f2d5d8f9435371

See more details on using hashes here.

Provenance

The following attestation bundles were made for turboloader-2.26.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: build-wheels.yml on ALJainProjects/TurboLoader

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page