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.1.tar.gz (628.0 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.1-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.1-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.1-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.1-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.1-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.1-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.1-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.1-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.1.tar.gz.

File metadata

  • Download URL: turboloader-2.26.1.tar.gz
  • Upload date:
  • Size: 628.0 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.1.tar.gz
Algorithm Hash digest
SHA256 ba5fb35f6ef46783bf2026310d8f7a1c557b3f6cc706998deda5cf1df041a660
MD5 ab4604f5181cd1a81663631c22b9dbf0
BLAKE2b-256 c975b1f810fc4f4352902d05c0953baeb48515048f965841e640c3f429ad2235

See more details on using hashes here.

Provenance

The following attestation bundles were made for turboloader-2.26.1.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.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for turboloader-2.26.1-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5fe544ed75af5b2872356e0b631bb50a6a8949baa3fb8ab33d75d77884ee3337
MD5 e070c1f1318441973c5366548998c2ba
BLAKE2b-256 9c572431a87a63d0a5f06ab18555b6b6aeca7a79aa112f549cb506ea65c66b6a

See more details on using hashes here.

Provenance

The following attestation bundles were made for turboloader-2.26.1-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.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for turboloader-2.26.1-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e48f502e9af543d369d42aa0aef1a94df3620415eae188f7720e4d8f33a2a963
MD5 ab2e9f2f79956d542ebfcd946a04d150
BLAKE2b-256 a956db6ec68e1e29a261fb75b90d4f578473f7d91a8485ea04c475b1c493c3c5

See more details on using hashes here.

Provenance

The following attestation bundles were made for turboloader-2.26.1-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.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for turboloader-2.26.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b0b36cf21444e86da31258d183ab4fd3662569d96da81e52d19b9f99172efac2
MD5 dd6ea5d73a705b0a745b44c7f3daf65f
BLAKE2b-256 9b2454327efb748023fba0719bf53d48f888d41fe862e69d61ad5d36b43b5c34

See more details on using hashes here.

Provenance

The following attestation bundles were made for turboloader-2.26.1-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.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for turboloader-2.26.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e8efd104237802ba80f44ebd07d71d256d4f65d7f8ed001cab48a6bd7e22a646
MD5 4bab00bb47ccfd8a1550b3a327958f4c
BLAKE2b-256 277e6c5253876946eaeca986ac6e8100545d6e55c11ae035b95434dec14e53ff

See more details on using hashes here.

Provenance

The following attestation bundles were made for turboloader-2.26.1-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.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for turboloader-2.26.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 47fd5f0b8a5dbf2aad6cb7a02777d249f10dbc314a5b0341246254a96ece1b02
MD5 24caf1d375012205c20a839816c9b145
BLAKE2b-256 b80e9e78ae44df3e20693b5ec282b8df6b09931edb156fa5e91a86e2e447be6d

See more details on using hashes here.

Provenance

The following attestation bundles were made for turboloader-2.26.1-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.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for turboloader-2.26.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1e5c58abd51d4f4c256984d6c9ce456a5c26f79db3715b3fd4dcf20e78cfbe89
MD5 6a3de553d045ec53c6179913b403d95b
BLAKE2b-256 837133ea48f95e529ad20a366c21c7c434352f21034f875e0941bc0fff2f9728

See more details on using hashes here.

Provenance

The following attestation bundles were made for turboloader-2.26.1-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.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for turboloader-2.26.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1ede374597cbf548330b2e6bbe6ae0392f407aa6cc428a363c9dd5c769fb11b3
MD5 1ded2f0df840486853977f865e9d5032
BLAKE2b-256 8f045ac5191a83b55a5571c98bf110cfe9555358b416745b6107a2813dd28868

See more details on using hashes here.

Provenance

The following attestation bundles were made for turboloader-2.26.1-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.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for turboloader-2.26.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 aaa46d5f15125aaec36e00875b9633a60e910036033d4ae74d87fa88251410ca
MD5 f42f68efeafdb4e5665a076fb9778d17
BLAKE2b-256 3cb7441bbacf03d9554dd5a6bebe7d355b7d42ac62d56fc78aaceb1f6687b066

See more details on using hashes here.

Provenance

The following attestation bundles were made for turboloader-2.26.1-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