Skip to main content

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

Project description

cdmltrain ๐Ÿš€

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

MIT License Python 3.7+ 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)
๐Ÿ”ง 3-Tier Architecture Auto-selects best engine based on your hardware
๐ŸŽ๏ธ ZSTD Support .tar.zst archives โ€” 25x faster than ZIP deflate
๐ŸŽฎ GPU Direct Loader Streams data to CUDA VRAM with async prefetch
๐ŸŒ Cross-Platform Windows, Linux, macOS โ€” works everywhere

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

Your ZIP/ZSTD File
        โ”‚
        โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  Tier 1: Python CoreStreamEngine                    โ”‚
โ”‚  โœ… Works on ANY machine, no dependencies            โ”‚
โ”‚  โ†’ O(1) Index + LRU Cache + Thread Safety           โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Tier 2: C++ FastCoreEngine (pybind11)              โ”‚
โ”‚  โœ… Auto-enabled if C++ Build Tools installed        โ”‚
โ”‚  โ†’ Bypasses Python GIL, faster multi-worker reads   โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚  Tier 3: ZSTD Engine + GPU Direct Loader            โ”‚
โ”‚  โœ… pip install zstandard   (for .tar.zst files)     โ”‚
โ”‚  โœ… NVIDIA GPU (for direct VRAM streaming)           โ”‚
โ”‚  โ†’ 25x faster decompression + near-zero GPU latency โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
        โ”‚
        โ–ผ
  PyTorch DataLoader โ†’ Model Training

The library auto-detects your hardware and picks the best tier. You write the same code regardless.


๐Ÿ“ฆ Installation

Note: PyPI release coming soon. Install locally for now.

# Step 1: Clone the repo
git clone https://github.com/prem85642/cdmltrain.git
cd cdmltrain

# Step 2: Install
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)

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 or .tar.zst file
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)

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)

Engine Speed Speedup
ZIP (Deflate) โ€” Tier 1/2 29,204 files/sec baseline
ZSTD โ€” Tier 3 739,653 files/sec ๐Ÿ”ฅ 25x faster

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
โ”‚   โ”œโ”€โ”€ 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.0.0.tar.gz (18.4 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.0.0-py3-none-any.whl (14.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for cdmltrain-1.0.0.tar.gz
Algorithm Hash digest
SHA256 d67f1cd162c04e111e49d9f8db26f16e6f1dd61cc20a3f6913e6c869cd40e376
MD5 17042a3d030e7b04fecb402e150b102b
BLAKE2b-256 5bc5c23f1f9785785553a42a90c7f3136e8244b98600f2b32273648f44376a97

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for cdmltrain-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ccf36a807826cbb1b9f1e05d7e87f12a7e1d0959b01daa5042b333db761b5a2
MD5 315baa1f453beab96df9605197122bae
BLAKE2b-256 79b2434471468f003c41d42d28c374a520695efec619c3ba4d61ed7dd46600ba

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