Tiny Modal-shaped job harness — one declaration, multiple backends (local Docker / Brev / Modal)
Project description
runplz
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:
- Imports your script (finds the
Appinstance at module scope). - Binds the chosen backend to that
App(the reasonpython script.pywon't work — nothing has told theAppwhere to dispatch). - 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, callfn.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 forpytestor 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 forbrev; the Brev box to attach to. If it doesn't exist andBrevConfig(auto_create=True), runplz provisions it (using the cheapest match for your resource constraints, or an explicitBrevConfig(instance_type=...)if you pinned one).--no-build— local only; reuse the last tagged docker image instead of rebuilding.--outputs-dir <path>— where to collect/outback 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 (sopip_install_local_dircanCOPYyour 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:
local→dockerbrev→brev,docker(or skipped inmode="container"),ssh,rsyncmodal→modal>=1.1,<2Python 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
Appper script. MultipleApps 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file runplz-1.5.0.tar.gz.
File metadata
- Download URL: runplz-1.5.0.tar.gz
- Upload date:
- Size: 50.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
70cb3e024a9616768490e163b8490d25d59443b411dc5c783c46f173969f3c6b
|
|
| MD5 |
d5158c99946577c33f438141be38a042
|
|
| BLAKE2b-256 |
0a07612b7292aae3dbe98990a4ce8a56beff75062a6a80e2e33c1eb4642adf87
|
File details
Details for the file runplz-1.5.0-py3-none-any.whl.
File metadata
- Download URL: runplz-1.5.0-py3-none-any.whl
- Upload date:
- Size: 36.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ae264cc675cc5e9a58f9958a3901ccdcfd6bbbb794a6bfba142c5f1aa5a9385
|
|
| MD5 |
5ac6d70b5e6eae83c57b5faad183066f
|
|
| BLAKE2b-256 |
ea8710fc4ad1c81e4d0e0b149e19ddafa6200d8bdf8cbf1e7de6d1dc0c44f932
|