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.3-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.3-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.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for mx8-1.0.3-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 546f5f0148e9e2b4d9507cf8fc87da9e15370c8fd6585b7c399daf180721d02a
MD5 33fd71c066c4622120e4d9d05552020a
BLAKE2b-256 58290ff66c9bbc2bc5305bb212276666bc8020402e19a6ef98e5701de8424705

See more details on using hashes here.

File details

Details for the file mx8-1.0.3-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.3-cp38-abi3-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 2640a1459e4b0afa2ba7ec6211907f0b4b7cc01a30332ca3ca16093e9b653657
MD5 d1a6e8fd05f2eab6fdb6a7436e4b7703
BLAKE2b-256 cc6afd4808e4d9d9a57f0c12f19e299dc3f28efeda27800ed56523b2fb3b6691

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