Registry / data / mosaicml-streaming

mosaicml-streaming

JSON →
library0.13.0pypypi✓ verified 85d ago

MosaicML Streaming (StreamingDataset) provides PyTorch-compatible datasets that can be efficiently streamed from cloud-based object stores (S3, GCS, Azure Blob Storage, Hugging Face Hub) or local filesystems. It enables training on large datasets without needing to download them entirely beforehand, improving data loading performance and reducing storage costs. The library is actively maintained with frequent updates, currently at version 0.13.0.

pip install mosaicml-streaming
INSTALL
IMPORT
SIG · MOSAICML-STREAMING
M
mosaicml-streaming
datapythonv0.13.0
Install
Import
Disk
Pass rate
0/ 10
Env Coverage0 / 10
glibc
3.93.13
musl
3.93.13
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
musl
glibc
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.
Debug
Known issues
breakingPython 3.9 support was deprecated in `v0.12.0`. Users on Python 3.9 must upgrade their Python version to 3.10 or higher (3.12+ is fully supported) to use `mosaicml-streaming` versions 0.12.0 and above.
fix
Upgrade Python environment to 3.10 or later.
affects: >=0.12.0
gotchaProper authentication/credentials are critical for streaming from cloud object stores (S3, GCS, Azure Blob, HF Hub). Incorrectly configured credentials are a common source of errors.
fix
Ensure environment variables (e.g., `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, `AZURE_STORAGE_ACCOUNT_NAME`, `AZURE_STORAGE_ACCOUNT_KEY`, `HF_TOKEN`) or cloud provider CLI configurations are correctly set for the target remote storage. Consult cloud provider documentation for specific setup.
affects: All
gotchaEarlier versions (<0.8.1) could experience dataloader hangs between epochs, significantly impacting training time. This issue was resolved in v0.8.1.
fix
Upgrade `mosaicml-streaming` to version 0.8.1 or newer to benefit from the fix.
affects: <0.8.1
gotchaPrior to v0.10.0, the library created a new cloud client for each download, potentially leading to 'too many open sockets' errors or excessive cloud authentication requests. Version 0.10.0 introduced client reuse.
fix
Upgrade `mosaicml-streaming` to version 0.10.0 or newer to utilize reusable cloud download clients and improve stability.
affects: <0.10.0
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.
fix
Ensure 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.
fix
Provide 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.
fix
Verify 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.
fix
Clean 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.
Agent activity
25 hits · last 30 days
node
22
OpenAI (training)
1
Resources
mosaicml-streaming — pip install mosaicml-streaming · libregistry