Skip to main content

Tiny Modal-shaped job harness — one declaration, multiple backends (local Docker / Brev / Modal)

Project description

runplz

PyPI

Tiny Modal-shaped job harness — one Python decoration, multiple backends.

# jobs/train.py
from runplz import App, BrevConfig, Image

app = App("my-job", brev=BrevConfig(auto_create=True))

image = (
    Image.from_registry("pytorch/pytorch:2.4.0-cuda12.1-cudnn9-runtime")
    .apt_install("rsync", "build-essential")
    .pip_install("pandas>=2.0", "scikit-learn")
    .pip_install_local_dir(".", editable=True)
)

@app.function(
    image=image,
    gpu="T4",
    min_cpu=4, min_memory=26, min_gpu_memory=16, min_disk=100,
    timeout=60 * 60,
)
def train():
    import subprocess
    subprocess.run(["bash", "scripts/train.sh"], check=True)

@app.local_entrypoint()
def main():
    train.remote()
runplz local  jobs/train.py
runplz brev   --instance my-box jobs/train.py
runplz modal  jobs/train.py

How it's structured

The CLI is the only entry point. runplz <backend> <script> does three things:

  1. Imports your script (finds the App instance at module scope).
  2. Binds the chosen backend to that App (the reason python script.py won't work — nothing has told the App where to dispatch).
  3. Calls whatever you've decorated with @app.local_entrypoint().

Inside that entrypoint you call train.remote(), which serializes a minimal dispatch (env vars + a path to your script) and runs on the selected backend. Args and kwargs must be JSON-serializable.

Decorators you'll use

  • @app.function(image=..., gpu=..., ...) — marks a function as running on the backend. Its body never executes locally (unless you call .local(); see below).
  • @app.local_entrypoint() — marks the driver that runs inside the CLI process, on your machine. Typical body: build args, call fn.remote(...) once, maybe inspect the result. There can be at most one per script.

Ways to invoke a function

  • train.remote(...) → dispatch on the currently-selected backend (what the CLI set). This is the normal case.
  • train.local(...) → run the body in this Python process. No container, no remote. Useful for pytest or a quick REPL sanity check where you don't want to shell out to docker/brev/modal.
  • train(...) → raises. Always go through .remote() or .local() so the dispatch is explicit.

What the CLI flags do

  • --instance <name>required for brev; the Brev box to attach to. If it doesn't exist and BrevConfig(auto_create=True), runplz provisions it (using the cheapest match for your resource constraints, or an explicit BrevConfig(instance_type=...) if you pinned one).
  • --no-buildlocal only; reuse the last tagged docker image instead of rebuilding.
  • --outputs-dir <path> — where to collect /out back to on the host (default ./out/).

Image DSL

Declared once, translated per backend:

Image.from_registry("pytorch/pytorch:2.4.0-cuda12.1-cudnn9-runtime")
    .apt_install("bzip2", "rsync")
    .pip_install("pandas>=2.0", index_url="https://...")
    .pip_install_local_dir(".", editable=True)
    .run_commands("echo hi")
  • Modal — rendered as a modal.Image.from_registry(...) chain; layers build on Modal's cluster and cache per-hash.
  • local — synthesized into a Dockerfile passed to docker build -f - with the repo as context (so pip_install_local_dir can COPY your source).
  • Brev (mode=vm) — same Dockerfile synthesis, shipped over rsync and built on the remote box.
  • Brev (mode=container) — the box IS the base image; the layer ops run inline over ssh. Lighter, and sidesteps a historical Brev GPU+docker flakiness (see docs/brev-ssh-bug-report.md).

You can also use Image.from_dockerfile("path/to/Dockerfile") to point at an existing Dockerfile you maintain; runplz just runs it.

Resource constraints

All memory/disk fields in GB:

@app.function(
    image=image,
    gpu="T4",            # modal-style label; "A100", "H100", "L4", ...
    min_cpu=4,
    min_memory=26,       # RAM
    min_gpu_memory=16,   # VRAM
    min_disk=100,
    timeout=60 * 60,
)

How they're honored per backend:

constraint local brev modal
gpu brev search --gpu-name @app.function(gpu=...)
min_cpu --min-vcpu cpu=
min_memory --min-ram memory= (converted to MB)
min_gpu_memory --min-vram baked into gpu string: A100-80GB
min_disk --min-disk (filter + provision) warned, dropped (no modal kwarg)

local ignores these — it uses whatever your machine has and auto-detects NVIDIA runtime via docker info.

On brev, the constraints drive brev search --sort price and runplz picks the cheapest match. Override with BrevConfig(instance_type="...") when you need a specific shape.

Install

pip install runplz                 # core (local + brev)
pip install 'runplz[modal]'        # add Modal support

The core dependency set is empty. Backends shell out to system CLIs:

  • localdocker
  • brevbrev, docker (or skipped in mode="container"), ssh, rsync
  • modalmodal>=1.1,<2 Python package

Outputs

Write to $RUNPLZ_OUT inside your function. runplz collects that directory back to ./out/ on the host (rsync on brev, tar-return on modal, bind-mount on local). On modal, returns are capped at ~256 MB — if you're writing more, switch to modal.Volume for now (a runplz-native volume abstraction is TODO).

Caveats

  • .remote() args must be JSON-serializable. No closures, no custom objects. Deliberate: the remote dispatch is env vars + a path.
  • Your job script is imported by path at runtime (not installed as a package), so it can live anywhere in the repo.
  • One App per script. Multiple Apps in one file is ambiguous for the CLI loader and errors.

Tests

pytest tests/

~120 offline tests — DSL rendering, BrevConfig validation, Modal GPU-label translation, instance picker with mocked subprocess, CLI guards.

License

Apache 2.0 — see LICENSE.

Project details


Download files

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

Source Distribution

runplz-1.4.2.tar.gz (49.2 kB view details)

Uploaded Source

Built Distribution

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

runplz-1.4.2-py3-none-any.whl (35.4 kB view details)

Uploaded Python 3

File details

Details for the file runplz-1.4.2.tar.gz.

File metadata

  • Download URL: runplz-1.4.2.tar.gz
  • Upload date:
  • Size: 49.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for runplz-1.4.2.tar.gz
Algorithm Hash digest
SHA256 ff0bd5bb74285358a998ea7bc05ba5340d154491e3aa8e3ae6ae0303834da030
MD5 df4ded4660bce45e749a62e4bde2c43d
BLAKE2b-256 8c34c06485dbd987a5f5ef394516ddd5a5a0f397f945f7a5afefd1e13abd7654

See more details on using hashes here.

File details

Details for the file runplz-1.4.2-py3-none-any.whl.

File metadata

  • Download URL: runplz-1.4.2-py3-none-any.whl
  • Upload date:
  • Size: 35.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.6

File hashes

Hashes for runplz-1.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9bebba7d782cab2717729a18cecec6996ff3b6b8483b1d7c6135ca560e4f07f2
MD5 5aa93428560f471c63ffa14b03611350
BLAKE2b-256 cbb6f046819c002517d9d083948c579c744be4ab4b1e6bb680871c97352d367f

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