Install & Compatibility
Where this runs
tested against v0.13.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
py 3.10
✕ build_error
✕ timeout
py 3.11
✕ build_error
✕ timeout
py 3.12
✕ build_error
✕ timeout
py 3.13
✕ build_error
3/4 runs
py 3.9
✕ build_error
✕ timeout
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
StreamingDataset
✓ from streaming import StreamingDataset
MDSWriter
✓ from streaming import MDSWriter
Used for creating MosaicML Streaming (MDS) datasets.
This quickstart demonstrates how to initialize `StreamingDataset` and integrate it with `torch.utils.data.DataLoader`. It sets up a minimal local MDS dataset for immediate testing. For cloud usage, ensure the `remote` parameter points to your cloud object storage path and that necessary cloud provider credentials are correctly configured in your environment.
import os
import torch
from streaming import StreamingDataset
from torch.utils.data import DataLoader
import json
# Define local paths for quickstart demonstration
# In a real scenario, 'remote' would point to your cloud MDS dataset
# (e.g., "s3://my-bucket/data" or "gs://my-bucket/data").
# Ensure cloud credentials are set in environment variables for cloud remotes.
local_remote_path = "quickstart_mds_data"
local_cache_path = "quickstart_mds_cache"
# --- Create a dummy MDS dataset for local testing if it doesn't exist ---
# For actual use, you'd generate MDS datasets with `streaming.MDSWriter`
# or point to existing ones in cloud storage.
if not os.path.exists(local_remote_path):
print(f"Creating dummy MDS data in '{local_remote_path}'...")
os.makedirs(local_remote_path)
# A minimal `index.json` is required by StreamingDataset
index_data = {
"version": 2,
"shards": [
{"shard": 0, "samples": 2, "hash": "dummy_hash", "size": 100,
"raw_data_size": 80, "zip_data_size": 20, "compression": None,
"format": None}
]
}
with open(os.path.join(local_remote_path, 'index.json'), 'w') as f:
json.dump(index_data, f)
# A minimal shard file is also expected, though its content won't be processed
# in this simplified example without actual schema.
with open(os.path.join(local_remote_path, '00000.mds'), 'wb') as f:
f.write(b'dummy_data_content_for_shard_0')
print("Dummy MDS data created.")
else:
print(f"Using existing dummy MDS data in '{local_remote_path}'.")
os.makedirs(local_cache_path, exist_ok=True)
# --- End of dummy MDS creation ---
# 1. Initialize the StreamingDataset
dataset = StreamingDataset(
local=local_cache_path, # Local cache directory for downloaded shards
remote=local_remote_path, # Path to your MDS dataset (local or cloud)
shuffle=True,
batch_size=1, # Adjust batch size for internal buffering
# Other parameters like `predownload` can be tuned for performance
)
# 2. Create a PyTorch DataLoader
dataloader = DataLoader(
dataset=dataset,
batch_size=1, # DataLoader batch size
num_workers=0, # Use 0 workers for simple local testing to avoid multiprocessing issues
)
# 3. Iterate over the data
print(f"Dataset has {len(dataset)} samples.")
for i, batch in enumerate(dataloader):
# In this dummy setup, 'batch' will be raw bytes as no actual data schema is defined.
# With a real MDS dataset, this would be structured data (e.g., dicts, tensors).
print(f"Batch {i}: {batch}")
if i >= 1: # Process a few batches for demonstration
break
# Note: For production use, remember to configure cloud credentials
# (e.g., via environment variables like AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY,
# or cloud provider CLI configs) if 'remote' points to cloud storage.
Errors
Common errors & fixes
ImportError: cannot import name 'StreamingDataset' from 'streaming'
The `StreamingDataset` class is typically imported from the `streaming` package directly, but older or incorrect usage might attempt to import it from a submodule or an incorrectly named package.
fixEnsure you are importing `StreamingDataset` directly from the `streaming` top-level package.
```python
from streaming import StreamingDataset
```
ValueError: Reused local directory.
This error often occurs when multiple processes or runs attempt to use the same local directory for caching streaming data, leading to conflicts. This is particularly common in distributed training setups where local directories might not be unique per process.
fixProvide a unique `local` directory for each worker or training run, or ensure proper cleanup of the local directory between runs. Alternatively, set `cleanup=True` (if available and appropriate for your use case) to allow the library to manage cleanup.
```python
import os
from streaming import StreamingDataset
# For multi-process/distributed training, ensure unique local paths
worker_id = os.environ.get('RANK', '0') # Or a similar unique identifier
local_cache_dir = f'/tmp/my_dataset_cache_{worker_id}'
dataset = StreamingDataset(
remote='s3://my-bucket/path-to-dataset',
local=local_cache_dir,
shuffle=True
)
``` FileNotFoundError: [Errno 2] No such file or directory: '/tmp/mds_data/train/index.json'
This error indicates that the `StreamingDataset` cannot find the `index.json` file, which is crucial for defining the dataset structure and shards. This can happen if the `remote` or `local` path is incorrect, the dataset was not properly created in MDS format, or there are permission issues.
fixVerify that the `remote` and `local` paths provided to `StreamingDataset` are correct and point to a directory containing a valid MDS dataset (which includes `index.json`). Ensure that the MDS dataset was written successfully using `MDSWriter` and uploaded to the specified remote location if applicable. Check file permissions for the local cache directory.
```python
from streaming import StreamingDataset
remote_path = 's3://my-mds-datasets/train_data' # Ensure this path is correct and contains index.json
local_cache_path = '/tmp/streaming_cache'
dataset = StreamingDataset(
remote=remote_path,
local=local_cache_path,
shuffle=True
)
``` RuntimeError: Internal error: shared memory registered does not match local leader
This error typically arises in distributed training environments due to issues with stale or misconfigured shared memory segments used by `mosaicml-streaming` for inter-worker communication. It often indicates leftover shared memory from a previous, possibly crashed, training run.
fixClean up stale shared memory segments before starting a new training run. The `streaming.base.util.clean_stale_shared_memory()` function is provided for this purpose.
```python
import streaming.base.util as util
# Call this before initializing your StreamingDataset and Dataloader
util.clean_stale_shared_memory()
from streaming import StreamingDataset, StreamingDataLoader
# ... (your dataset and dataloader setup)
```
Upgrade
Version history
0.13.0latest on PyPI · released Jul 15, 2025
Audit
Dependencies
torchrequiredRequired for PyTorch compatibility and DataLoader integration.