Skip to main content

DatasetRT

CI Coverage Docs PyPI Python versions License: MIT

Cache preprocessing once. Change subsets and sampling weights without rewriting payloads.

DatasetRT is a Rust-powered dataset cache for Python machine learning pipelines. Store serialized training records in immutable disk shards, then use a separate Polars DataFrame to analyze, filter, and rebalance the training population.

  • Reuse preprocessing: reopen existing caches without rebuilding records.
  • Change experiments: edit subsets, class balance, or hard-example weights through metadata while cached payloads stay unchanged.
  • Control reads: Rust owns indexed reads, deterministic sampling, native workers, and bounded prefetching. Your code owns decoding and transforms.

Documentation · PyTorch tutorial · Benchmarks · Compare tools

Installation

DatasetRT supports standard CPython 3.10 through 3.15. Prebuilt wheels are available for Linux (x86-64 and ARM64) and macOS (Intel and Apple Silicon). PyTorch is optional.

Install dataset-rt, import dataset_rt.

uv add dataset-rt

Or with pip:

pip install dataset-rt

Quickstart

Define a data source as an iterable that packs each Python record with pickle or dill and yields CacheInput. Put large dictionaries, arrays, and nested structures in the packed payload; keep fields used for filtering and weighting in primitive metadata columns.

This complete example caches a dictionary per sample and unpacks it on read. Save it as quickstart.py, then run uv run quickstart.py after installing DatasetRT. Replace the source with your own preprocessing and serialization.

import pickle
from collections.abc import Iterator
from pathlib import Path

from pydantic import TypeAdapter
from typing_extensions import TypedDict

import dataset_rt as drt


class TrainingRecord(TypedDict):
    """Describe the dictionary stored inside each serialized payload."""

    text: str
    tokens: list[int]


RECORD_ADAPTER = TypeAdapter(TrainingRecord)


class TextSamples:
    """Pack preprocessed records, preserving labels as queryable metadata."""

    name = "train_records_v1"

    def __iter__(self) -> Iterator[drt.CacheInput]:
        """Stream payload bytes without building an in-memory dataset."""
        for text, label in [("  Hello world  ", 0), ("Dataset caching", 1)]:
            normalized = text.strip().lower()
            record = TrainingRecord(
                text=normalized, tokens=[ord(char) for char in normalized]
            )
            yield drt.CacheInput(
                data=pickle.dumps(record, protocol=pickle.HIGHEST_PROTOCOL),
                metadata={"label": label},
            )


runtime = drt.DatasetRuntime(num_workers=4)
result = runtime.from_cache_sources(
    TextSamples(),
    Path("cache"),
    reader_config=drt.ReaderConfig(seed=42, shuffle=True),
)

match result:
    case drt.CacheSourcesDatasetSuccess(dataset, results):
        pass
    case error:
        raise RuntimeError(error)

for sample in dataset:
    record = RECORD_ADAPTER.validate_python(pickle.loads(sample.data))
    print(record["text"], record["tokens"], sample.metadata["label"])

Run it again to reuse cache/train_records_v1 without repeating preprocessing. Use a new source name or cache root when preprocessing or source contents change; reuse does not automatically detect those changes. Shuffled reads sample with replacement, so this example can emit the same record twice.

pickle is included with Python. You can use dill.dumps() and dill.loads() instead after installing dill when your record types require it. The source packs the record, DatasetRT stores its bytes, and your read transform unpacks it. See the serialization guide.

Payloads and Metadata

Each dataset has two connected parts:

Part Contains Used for
Payload store Serialized bytes, typically dictionaries or large Python structures packed with pickle or dill Read and unpack the samples needed for training
Metadata table Sample identities, primitive attributes such as labels and splits, and sampling weights Analyze the population, filter samples, and control how often each sample is drawn

The Python API exposes the metadata table as a Polars DataFrame. The payloads remain in indexed disk shards, linked to metadata by (cache_id, sample_id). New caches use Zstd(level=3) compression for independent records; existing caches keep their recorded codec. See the compression guide for other codecs and reader compatibility.

For example, create a development subset by editing only the metadata:

metadata = dataset.get_metadata()

dev_run = metadata.head(100)
dataset.update_metadata(dev_run)

Future reads draw from that subset, and your read transform unpacks sample.data.

Rows in the active metadata table are the rows DatasetRT samples from. Remove rows for a fast development run, duplicate rows or update weight for class balancing and OHEM, add extra columns for training annotations, and let Rust validate that every row still maps to an immutable cache sample.

Why It Exists

Training experiments often reuse the same expensive preprocessed records while changing which samples they use. Keeping metadata separate from large serialized payloads makes those changes possible without reading every payload:

  • Analyze: inspect class counts, splits, or stored quality scores using the metadata table.
  • Filter: select development subsets or exclude records without making new copies of the cache.
  • Weight: rebalance classes or prioritize hard examples by changing sampling weights while payload bytes remain immutable.
  • Read quickly: Rust performs indexed payload reads with native workers and bounded prefetching; Python unpacks and transforms the delivered records.
  • Save RAM across loading processes: workers map a shared immutable metadata snapshot and cache indexes read-only with mmap. The OS can share their backing pages on the same host, avoiding a full private copy of those buffers per worker.
  • Reproduce: repeat sampling from identical cache contents, active metadata, seed, and stream history.

See the reader measurements for startup, throughput, and memory results. End-to-end speed also depends on storage, payload size, unpacking, transforms, and worker configuration. Weights, sampling state, decoded records, and prefetched batches still consume memory per worker; see the multiprocessing memory guide.

The Core Idea

DatasetRT exposes the active metadata, including sampling weights, as a Polars table:

cache_id | sample_id | <stored metadata columns...> | weight | <extra columns...>

Each row points to a stored payload; the payload itself is not a DataFrame cell. Analyze or edit this table without unpickling the sample records. For example, assign inverse-frequency class weights:

import polars as pl

metadata = dataset.get_metadata()

balanced = (
    metadata.join(
        metadata.group_by("label").agg(pl.len().alias("class_count")),
        on="label",
    )
    .with_columns((1.0 / pl.col("class_count")).alias("weight"))
    .drop("class_count")
)

dataset.update_metadata(balanced)

update_metadata() is runtime-only. It does not rewrite metadata.arrow, index.bin, shards, or manifests. Future iterators use the updated active table; already-created iterators keep their snapshot.

With drt.ReaderConfig(shuffle=True), DatasetRT performs deterministic weighted multinomial sampling with replacement over the active table. With shuffle=False, it emits active rows in cyclic table order, including duplicates. Use dataset.set_epoch_len(n) to make future iterators emit a finite window of n samples. Ordered reads continue through the active table cyclically across iterator boundaries, while shuffled reads continue a deterministic multinomial draw stream. Updating metadata resets the stream and sets the epoch length to the new table row count. Call set_epoch_len afterward to override it.

When To Use It

Use DatasetRT when you care about:

  • restart speed after expensive preprocessing
  • deterministic training-data order
  • class balancing, OHEM, or metadata-driven sampling
  • safe development subsets without separate cache copies
  • cache integrity and bounded native prefetching

It is not trying to be a training framework, image decoder, tensor format, or model-specific data pipeline. It is the cache and sampling layer underneath those pieces.

Documentation

Status

DatasetRT is production infrastructure for immutable dataset caching. The core cache lifecycle, immutable storage format, runtime metadata table, deterministic weighted sampling, and Rust-owned reader/writer prefetching are in place.

Contributing and Citation

See CONTRIBUTING.md for setup, validation, and reporting issues. If DatasetRT contributes to your research, use CITATION.cff and report the exact version or commit used. Released under the MIT license.

@software{stupakov_datasetrt_2026,
  author = {Stupakov, Vadym},
  title = {DatasetRT: Dataset Caching for Machine Learning},
  year = {2026},
  url = {https://github.com/Red-Eyed/DatasetRT}
}

Metadata

Release files for dataset-rt 0.5.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dataset-rt 0.5.14
File Size Uploaded Provenance Actions
dataset_rt-0.5.14.tar.gz 800.3 kB Without provenance Details for dataset_rt-0.5.14.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for dataset-rt 0.5.14
File Actions
dataset_rt-0.5.14-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.10 abi3 Linux glibc 2.17+ x86-64 Details for dataset_rt-0.5.14-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
dataset_rt-0.5.14-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.10 abi3 Linux glibc 2.17+ ARM64 Details for dataset_rt-0.5.14-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
dataset_rt-0.5.14-cp310-abi3-macosx_11_0_arm64.whl CPython 3.10 abi3 macOS 11.0+ ARM64 Details for dataset_rt-0.5.14-cp310-abi3-macosx_11_0_arm64.whl
dataset_rt-0.5.14-cp310-abi3-macosx_10_12_x86_64.whl CPython 3.10 abi3 macOS 10.12+ x86-64 Details for dataset_rt-0.5.14-cp310-abi3-macosx_10_12_x86_64.whl

Total release size: 15.4 MB

Release files / dataset_rt-0.5.14.tar.gz

Download URL dataset_rt-0.5.14.tar.gz
Size 800.3 kB
Tags Source
SHA-256 checksum
How to use checksums
0c548865f81dda06b1b97c75a9256327f17d8a373c3ee6e80a3517b2b8227b1b
BLAKE2b-256 checksum
How to use checksums
dfd65c69946223b26f65e8df3d3d20b9f5a7e73cb93cce55b9748dcfe3711e95
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / dataset_rt-0.5.14-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL dataset_rt-0.5.14-cp310-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 4.9 MB
Tags CPython 3.10 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
27a2ad737266251628b95763f6e99e82c0955e14fc2f3fe45874d4865e56abc6
BLAKE2b-256 checksum
How to use checksums
cc50b59656c3a702a3595d785261352c906b6c7b104f5d24d5021ea1844b3a82
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / dataset_rt-0.5.14-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL dataset_rt-0.5.14-cp310-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 4.6 MB
Tags CPython 3.10 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
a815ed50d46b3cc53f8f27649917b21e1c5a4df0522c98d1027204bc84c2ed8e
BLAKE2b-256 checksum
How to use checksums
f0679567e2e0d405451d1bd61325cf04f7bed2b3d239bb0f58d84da634d34721
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / dataset_rt-0.5.14-cp310-abi3-macosx_11_0_arm64.whl

Download URL dataset_rt-0.5.14-cp310-abi3-macosx_11_0_arm64.whl
Size 2.5 MB
Tags CPython 3.10 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
5d2e8511a9d0f5533e2bce40408fe4b461ae9826172a047371c992b4eb04d25e
BLAKE2b-256 checksum
How to use checksums
aeec1ffec011fa4eaf900647e456852c4d1f81d7fbf6640ffdc9a72510597ebc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / dataset_rt-0.5.14-cp310-abi3-macosx_10_12_x86_64.whl

Download URL dataset_rt-0.5.14-cp310-abi3-macosx_10_12_x86_64.whl
Size 2.6 MB
Tags CPython 3.10 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
f483515ff3ed8068c978cb5a1506473de463774adf62bd9c4b4805fc4fc6c439
BLAKE2b-256 checksum
How to use checksums
b26e6af91fa933d862b8d60b12d4d26cc4463080d7c36a28a423a1b3812f7fd7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.1 {"installer":{"name":"uv","version":"0.12.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for dataset-rt 0.5.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.5.14 This release

5 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page