Skip to main content

MX8: bounded data runtime (Rust) exposed to Python.

Project description

mx8 (Python)

MX8 is a bounded-memory data runtime exposed to Python (built with PyO3 + maturin).

The v0 focus is “don’t OOM”: MX8 enforces backpressure with hard caps (so prefetch can’t runaway).

Further docs:

  • Python API: ../../docs/python_api.md
  • v1 autotune API contract (planned): ../../docs/v1_autotune_api_contract.md
  • Vision labels/layout: ../../docs/vision_labels.md
  • Vision decode backend plan: ../../docs/vision_decode_backend_plan.md
  • S3/runtime tuning: ../../docs/s3_runtime_tuning.md
  • Memory contract: ../../docs/memory_contract.md
  • AI agent guide: ../../docs/ai_agent_guide.md
  • AI agent context (JSON): ../../docs/ai_agent_context.json
  • Troubleshooting: ../../docs/troubleshooting.md

Install (from wheel)

Once you have a wheel (from CI or local build):

  • python -m venv .venv && . .venv/bin/activate
  • pip install mx8-*.whl

Install (from PyPI)

  • python -m venv .venv && . .venv/bin/activate
  • pip install mx8
  • Optional vision/training deps: pip install pillow numpy torch

Quickstart (local, no S3)

import mx8

mx8.pack_dir(
    "/path/to/imagefolder",
    out="/path/to/mx8-dataset",
    shard_mb=512,
    label_mode="imagefolder",
    require_labels=True,
)

loader = mx8.vision.ImageFolderLoader(
    "/path/to/mx8-dataset@refresh",
    batch_size_samples=64,
    max_inflight_bytes=256 * 1024 * 1024,
    resize_hw=(224, 224),  # (H,W); optional
)

print(loader.classes)  # ["cat", "dog", ...] if labels.tsv exists

for images, labels in loader:
    pass

Zero-manifest load (raw prefix)

import mx8

loader = mx8.load(
    "s3://bucket/raw-prefix/",
    recursive=True,  # default
    profile="balanced",
)

for batch in loader:
    pass

Mix multiple loaders (v1.7 preview)

mx8.mix(...) composes existing loaders into one deterministic stream. weights are sampling proportions (not model-loss weights).

import mx8

loader_a = mx8.load("s3://bucket/dataset_a/@refresh", profile="balanced", autotune=True)
loader_b = mx8.load("s3://bucket/dataset_b/@refresh", profile="balanced", autotune=True)

mixed = mx8.mix(
    [loader_a, loader_b],
    weights=[1, 1],   # fairness baseline (50:50)
    seed=0,
    epoch=0,
)

for batch in mixed:
    pass

print(mixed.stats())

Skewed example:

mixed = mx8.mix([loader_a, loader_b], weights=[7, 3], seed=0, epoch=0)

seed and epoch define deterministic schedule behavior:

  • same seed + epoch => same source-pick sequence
  • same seed, different epoch => controlled schedule variation

starvation_window is an optional watchdog threshold in scheduler ticks used for starvation counters in mixed.stats(). Set MX8_MIX_SNAPSHOT=1 (and optional MX8_MIX_SNAPSHOT_PERIOD_TICKS=64) to emit periodic mix_snapshot proof events.

Bounded memory (v0)

Set a hard cap and periodically print high-water marks:

import mx8

loader = mx8.vision.ImageFolderLoader(
    "/path/to/mx8-dataset@refresh",
    batch_size_samples=64,
    max_inflight_bytes=256 * 1024 * 1024,
    max_queue_batches=8,
    prefetch_batches=4,
)

for step, (images, labels) in enumerate(loader):
    if step % 100 == 0:
        print(loader.stats())  # includes ram_high_water_bytes

Avoid patterns that intentionally accumulate batches:

# ❌ Don't do this (will grow RSS regardless of any loader)
all_batches = list(loader)

Labels (optional)

label_mode="imagefolder" is designed to scale:

  • Per-sample records reference a numeric label_id (u64), not a repeated string.
  • The human-readable mapping is stored once at out/_mx8/labels.tsv.

If your input layout is mixed (files directly under the prefix and subfolders), label_mode="auto" may disable ImageFolder labeling. To enforce ImageFolder semantics, use:

mx8.pack_dir(..., label_mode="imagefolder", require_labels=True)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mx8-1.0.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (11.8 MB view details)

Uploaded CPython 3.8+manylinux: glibc 2.17+ x86-64

mx8-1.0.0-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (21.0 MB view details)

Uploaded CPython 3.8+macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file mx8-1.0.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mx8-1.0.0-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 70f1963db09b8dfc0560966d9be79275f762d334c0c5cfa5dc69de884618552a
MD5 a9659809748522ba69d99636fec92ce6
BLAKE2b-256 ac1815fcc46b9a8a8d44bc8e1565120a40a9023f932d3620df60761dfd8cc676

See more details on using hashes here.

File details

Details for the file mx8-1.0.0-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for mx8-1.0.0-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 e82fb516c65d8c66e67d5437207f29f81683d519be2ef6663d17c54d92c397a4
MD5 568b582d22cda5613509b962b1cfe397
BLAKE2b-256 191434c6bafa03beacba132bf8bfb5ebba45d2c7bdf06a24919deb89700a9750

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