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.
๐ฅ 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d67f1cd162c04e111e49d9f8db26f16e6f1dd61cc20a3f6913e6c869cd40e376
|
|
| MD5 |
17042a3d030e7b04fecb402e150b102b
|
|
| BLAKE2b-256 |
5bc5c23f1f9785785553a42a90c7f3136e8244b98600f2b32273648f44376a97
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ccf36a807826cbb1b9f1e05d7e87f12a7e1d0959b01daa5042b333db761b5a2
|
|
| MD5 |
315baa1f453beab96df9605197122bae
|
|
| BLAKE2b-256 |
79b2434471468f003c41d42d28c374a520695efec619c3ba4d61ed7dd46600ba
|