Skip to main content

Stream ML datasets from ZIP/ZSTD/S3 archives into PyTorch without disk extraction.

Project description

cdmltrain ๐Ÿš€

Stream ML Datasets Directly from ZIP / ZSTD / S3 Cloud โ€” No Extraction. No Wasted Storage. Zero OOM.

MIT License PyPI version Python 3.8+ Platform


๐Ÿ”ฅ The Problem This Solves

Every Data Scientist / ML Engineer hits this wall:

"Your 100 GB Kaggle dataset is a ZIP file.
 Extracting it takes 2 hours and needs 300 GB of free disk space.
 Your Colab/Kaggle notebook crashes with Out-of-Memory errors."

cdmltrain eliminates this problem entirely.

It lets PyTorch read images, audio, text, CSV, JSON โ€” any data โ€” directly from a compressed archive into RAM, skipping disk extraction completely.


โœจ Key Features

Feature Description
๐Ÿ—œ๏ธ Format Agnostic Images, audio (.wav), text, CSV, JSON, binary โ€” all supported
โšก O(1) Random Access ZIP Central Directory indexing โ€” jumps to any file instantly
๐Ÿง  Memory-Safe Cache Custom LRU cache enforces strict RAM limits โ€” zero OOM crashes
๐Ÿ”’ Thread Safe Concurrent reads for PyTorch DataLoader(num_workers=N)
๐Ÿ”ง 4-Tier Architecture Auto-selects best engine based on your hardware & data location
๐ŸŽ๏ธ ZSTD Support .tar.zst archives โ€” 25x faster than ZIP deflate
๐ŸŽฎ GPU Direct Loader Streams data to CUDA VRAM with async prefetch
โ˜๏ธ S3 Cloud Streaming Stream data directly from AWS S3 โ€” zero local download
๐ŸŒ Cross-Platform Windows, Linux, macOS โ€” works everywhere

๐Ÿ—๏ธ Architecture (4 Tiers โ€” Auto-Selected)

graph TD
    A[Local File <br> .zip / .tar.zst] --> D{Auto-Select <br> Engine}
    B[Cloud AWS S3 <br> s3://bucket/data.zip] --> D

    subgraph Tier 1: Core
    E[1. Python CoreStreamEngine <br> <i>Zero dependencies, works anywhere</i>]
    end

    subgraph Tier 2: Fast Core
    F[2. C++ FastCoreEngine <br> <i>Bypasses GIL, faster multi-worker reads</i>]
    end

    subgraph Tier 3: ZSTD & GPU
    G[3. ZSTD / GPU Direct Loader <br> <i>25x faster decompression, CUDA VRAM streaming</i>]
    end

    subgraph Tier 4: S3 Cloud
    H[4. S3 Cloud Streaming Engine <br> <i>Byte-range HTTP requests, zero local download</i>]
    end

    D --> E
    D --> F
    D --> G
    D --> H

    E --> I(PyTorch DataLoader)
    F --> I
    G --> I
    H --> I
    
    I --> J((Model Training))
    
    classDef default fill:#1f2937,stroke:#3b82f6,stroke-width:2px,color:#f3f4f6;
    classDef tier fill:#111827,stroke:#10b981,stroke-width:2px,color:#e5e7eb;
    class E,F,G,H tier;

The library auto-detects your hardware and data location, then picks the best tier. Same code always.


๐Ÿ“ฆ Installation

# Core (Tier 1 + 2) โ€” works everywhere
pip install cdmltrain

# With ZSTD support (Tier 3)
pip install cdmltrain[zstd]

# With AWS S3 Cloud Streaming (Tier 4)
pip install cdmltrain[s3]

# Everything
pip install cdmltrain[full]

# Or from source:
git clone https://github.com/prem85642/cdmltrain.git
cd cdmltrain
pip install .

# Step 3 (Optional): ZSTD support for .tar.zst archives
pip install zstandard

C++ Acceleration (Tier 2):

  • Windows: Install Microsoft C++ Build Tools
  • Linux: sudo apt-get install build-essential
  • If skipped: pure-Python engine runs automatically โ€” no errors.

๐Ÿš€ Quick Start

Basic Usage (ZIP โ€” Any Data Type)

from cdmltrain import CDMLStreamDataset
from torch.utils.data import DataLoader

# Point directly to your ZIP โ€” no extraction needed!
dataset = CDMLStreamDataset(
    zip_path="my_dataset.zip",
    max_cache_mb=2048    # RAM cache limit (MB)
)

dataloader = DataLoader(dataset, batch_size=32, shuffle=True, num_workers=4)

for batch in dataloader:
    # Train your model normally
    pass

Image Dataset (with PyTorch Transforms)

from cdmltrain import CDMLStreamDataset
from torchvision import transforms

transform = transforms.Compose([
    transforms.Resize((224, 224)),
    transforms.ToTensor(),
    transforms.Normalize([0.5], [0.5])
])

dataset = CDMLStreamDataset("images.zip", transform=transform, is_image=True)

ZSTD Archive (25x Faster Decompression) โšก

# Just change the file extension โ€” everything else is identical!
dataset = CDMLStreamDataset("my_dataset.tar.zst", max_cache_mb=2048)

S3 Cloud Streaming (Zero Download) โ˜๏ธ

Stream terabytes of data directly from an S3 bucket without downloading anything. AWS credentials are automatically picked up from your environment or ~/.aws/credentials.

# Just use an s3:// URI!
dataset = CDMLStreamDataset(
    zip_path="s3://my-bucket/huge_dataset.zip",
    max_cache_mb=2048
)

GPU Direct Loader (NVIDIA VRAM Streaming) ๐ŸŽฎ

For the highest possible performance, cdmltrain bypasses PyTorch's DataLoader multiprocessing bottleneck using CUDA Pinned Memory:

from cdmltrain.gpu_loader import GPUDirectLoader

# Stream directly into GPU:0 VRAM using asynchronous DMA prefetching
loader = GPUDirectLoader(dataset, batch_size=64, device="cuda:0")

for batch in loader:
    # `batch` is already a CUDA Tensor! No need for `.to(device)`
    loss = model(batch) 

๐Ÿ”ฌ Data Scientist Debugging Tools

When a deep learning model crashes on Epoch 4, Batch 1400 because of a corrupt image inside the archive, you don't need to extract the 100GB ZIP to find it. cdmltrain provides instant debugging hooks:

1. Extract a Corrupt File by Index

Instantly extract the broken image to your disk to inspect it visually:

# Instantly fetch image #1400 and save it to the current folder
dataset.extract_sample_to_disk(idx=1400, export_path="./debug_folder/")
# Output: [CDML] Extracted file 'broken_dog.jpg' to -> ./debug_folder/broken_dog.jpg

2. Fetch a specific file by its Name

Want to look at the labels.csv file without touching the millions of images inside the ZIP?

# Returns raw bytes (or a PIL Image if is_image=True)
csv_bytes = dataset.get_by_filename("train_labels.csv")
print(csv_bytes.decode('utf-8')[:100])

๐Ÿ–ฅ๏ธ 3-Tier Architecture Fallback

cdmltrain auto-detects your system capabilities and selects the fastest engine:

โš™๏ธ Configuration Parameters

Parameter Type Default Description
zip_path str (required) Path to .zip, .tar.zst file, or S3 URI (s3://bucket/data.zip)
transform callable None PyTorch/torchvision transform
is_image bool False True enables PIL image decoding
max_cache_mb int 2048 Max RAM for caching (MB)

GPU Direct Loader Parameters (GPUDirectLoader):

Parameter Type Default Description
dataset Dataset (required) A CDMLStreamDataset instance
batch_size int 32 Number of items per batch
device str "cuda:0" Target CUDA device to stream into

max_cache_mb Guide:

Your RAM Recommended
4 GB (Colab Free) 512
8 GB (Laptop) 2048
16 GB (PC) 6000
32 GB+ (Server) 16000

๐Ÿ“Š Benchmarks (Real Tests)

ZSTD vs ZIP Speed (200 files ร— 10KB)

gantt
    title Files processed per second (Higher is better)
    dateFormat  X
    axisFormat %s
    
    section Baseline (ZIP)
    Tier 1/2 (29k/s)    :a1, 0, 29204
    
    section High-Perf (ZSTD)
    Tier 3 (739k/s) :a2, 0, 739653
Engine Speed Speedup
ZIP (Deflate) โ€” Tier 1/2 29,204 files/sec baseline
ZSTD โ€” Tier 3 739,653 files/sec ๐Ÿ”ฅ 25x faster
S3 Cloud Streaming โ€” Tier 4 Network Bound ๐Ÿ”ฅ 0 GB local disk space used

GPU Direct Loader (Google Colab T4)

Metric Value
GPU Tesla T4 (15.6 GB VRAM)
Batch device cuda:0 โ€” data streamed to VRAM
Throughput 17,512 items/sec
Epoch time (100 items) 0.0045s

Memory Safety Test

Test Result
Cache limit: 1MB, Data: 2MB โœ… Stayed under 1MB
Thread safety: 8 workers โœ… Zero race conditions
Corrupted ZIP โœ… Rejected cleanly
50MB single file โœ… Byte-exact in 0.108s
1000-file archive โœ… Indexed in 0.04s

๐Ÿ› Debugging / Inspection

Inspect any specific file without unzipping:

dataset.extract_sample_to_disk(idx=42, export_path="./inspection/")

๐Ÿ› ๏ธ Troubleshooting

ModuleNotFoundError: No module named 'cdmltrain'

git clone https://github.com/prem85642/cdmltrain.git && cd cdmltrain && pip install .

ModuleNotFoundError: No module named 'zstandard'

pip install zstandard

Microsoft Visual C++ 14.0 required (Windows)

Install C++ Build Tools. Or skip โ€” pure Python engine works fine.

Out of Memory on Colab

dataset = CDMLStreamDataset("data.zip", max_cache_mb=512)  # Reduce cache

Bad CRC-32 error

python -c "import zipfile; print(zipfile.ZipFile('file.zip').testzip())"
# None = healthy, anything else = re-download

PIL.UnidentifiedImageError

dataset = CDMLStreamDataset("data.zip", is_image=False)  # Not an image dataset

๐Ÿ–ฅ๏ธ OS Compatibility

Feature Windows Linux macOS
ZIP Engine (Tier 1) โœ… โœ… โœ…
ZSTD Engine (Tier 3) โœ… โœ… โœ…
GPU Direct Loader โœ… โœ… โœ…
C++ Fast Engine (Tier 2) โœ… pre-built โœ… compile via pip install . โœ… compile via pip install .

๐Ÿ“ Project Structure

cdmltrain/
โ”œโ”€โ”€ cdmltrain/
โ”‚   โ”œโ”€โ”€ __init__.py          # Package entry point
โ”‚   โ”œโ”€โ”€ core.py              # Tier 1: Python CoreStreamEngine
โ”‚   โ”œโ”€โ”€ dataset.py           # CDMLStreamDataset (auto-tier selection)
โ”‚   โ”œโ”€โ”€ zstd_engine.py       # Tier 3: ZSTD streaming engine
โ”‚   โ”œโ”€โ”€ s3_engine.py         # Tier 4: Cloud Network Streaming (S3) engine
โ”‚   โ”œโ”€โ”€ gpu_loader.py        # Tier 3: GPU Direct Loader (CUDA pinned memory)
โ”‚   โ””โ”€โ”€ src/
โ”‚       โ””โ”€โ”€ fast_core.cpp    # Tier 2: C++ FastCoreEngine (pybind11)
โ”œโ”€โ”€ demo.py                  # Quickstart demo
โ”œโ”€โ”€ quickstart.ipynb         # Jupyter Notebook tutorial
โ”œโ”€โ”€ test_enterprise_audit.py # Enterprise QA suite (8 tests)
โ”œโ”€โ”€ test_zstd_benchmark.py   # ZSTD vs ZIP benchmark
โ”œโ”€โ”€ test_zstd_compat.py      # Cross-format compatibility test
โ”œโ”€โ”€ test_gpu_loader.py       # GPU Direct Loader test
โ”œโ”€โ”€ setup.py                 # pip install configuration
โ”œโ”€โ”€ requirements.txt         # Dependencies
โ””โ”€โ”€ LICENSE                  # MIT License

๐Ÿค Contributing

Pull requests are welcome! For major changes, please open an issue first.


๐Ÿ“„ License

MIT License โ€” see LICENSE for details.

Made with โค๏ธ for the ML community โ€” because your model matters more than your storage bill.

Project details


Download files

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

Source Distribution

cdmltrain-1.1.1.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

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

cdmltrain-1.1.1-py3-none-any.whl (17.3 kB view details)

Uploaded Python 3

File details

Details for the file cdmltrain-1.1.1.tar.gz.

File metadata

  • Download URL: cdmltrain-1.1.1.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for cdmltrain-1.1.1.tar.gz
Algorithm Hash digest
SHA256 79bd432706d1d372bf27205c205add3bd385de43d9f3bb4fefe65bca957c3dac
MD5 793d512c39e6c1d466f41aee06ef0d1d
BLAKE2b-256 5296f772f281a8ee3184c0d33ad2bf175e91b93bc9a5d336054a235ada79822c

See more details on using hashes here.

File details

Details for the file cdmltrain-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: cdmltrain-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 17.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for cdmltrain-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f6ba307404077c7681d6b2be82e243eaf2689999839cf82e5040f0f08d6b6420
MD5 15fabab05e614583a83646823b00e49d
BLAKE2b-256 bc67426b694eadedc4b6c33eb43e221b03268623a903fba8bd584f61ca169e55

See more details on using hashes here.

Supported by

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