Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

gpu-runner

gpu-runner is a CLI for running ML experiments on ephemeral GPU clusters. You write a small YAML config in your project, then either manage the cluster lifecycle in three steps (up, run, down) or do everything in one shot (submit).

It reuses existing tools rather than reimplementing them: SkyPilot for provisioning/teardown across clouds, rsync/scp + shutil for code and result transfer, and .dockerignore/.gitignore for exclusion rules.


How it works (end to end)

1. Config resolution

When you run any command, the CLI looks for gpu-runner.yaml / gpu-runner.yml (or dotfile variants) starting in the current directory and walking up to the filesystem root. You can override with -c path/to/file.yaml. The config is parsed into an ExperimentConfig (name, backend, resources, setup, run command, env, sync, results, etc.). The directory containing the config becomes the project root; all relative paths (sync.local_path, results.local_path) resolve against it.

2. State

Cluster state lives in <root>/.gpu-runner/state.json and contains: cluster name, backend, remote workdir, local staged code path, last run exit code. This is what lets up, run, and down be separate commands — each invocation reloads state instead of re-provisioning.

3. up — provision

  • Resolves the cluster name from config.name (sanitized).
  • Selects a backend from config.provider_backend (skypilot or local).
  • Stages code: copies sync.local_path into a staging directory, applying exclude patterns (see Sync below).
  • Provisions:
    • skypilot: writes a temporary SkyPilot task YAML (resources, envs, setup, a no-op run, workdir = staged dir, idle autostop) and runs sky launch -c <cluster> -y <yaml>. SkyPilot uploads the workdir to ~/sky_workdir on the cluster.
    • local: creates ~/.gpu-runner/clusters/<name>/work and stages code there.
  • Saves state with remote_workdir (~/sky_workdir for SkyPilot, local path for local).

4. run — execute + fetch results

  • Loads state; fails fast if no cluster is up.
  • Runs config.setup (if any) then config.run (or --command override):
    • skypilot: sky exec <cluster> "cd ~/sky_workdir && <cmd>".
    • local: subprocess in the staged workdir with merged env.
  • Records exit code in state.
  • Copies results back:
    • skypilot: scp -r <cluster>:<results.remote_path> <results.local_path>; if results.cloud_storage is set, also runs an upload command on the cluster.
    • local: copies from the cluster's results dir into results.local_path.
  • Prints exit code.

5. down — teardown

  • skypilot: sky down <cluster> -y.
  • local: deletes the cluster directory.
  • Clears state file.

6. submit — one-shot

Runs up → run → down. If the run fails and keep_cluster_on_failure: true, it skips teardown so you can debug. Otherwise it always tears down, even on failure, to avoid leaking cost.


Sync and exclusions

Code is staged with shutil.copytree using an ignore function. Exclusion patterns come from:

  1. sync.excludes in config,
  2. Files listed in sync.ignore_files (default .dockerignore, .gitignore) — each non-comment, non-blank line is treated as a pattern,
  3. Built-in defaults: .gpu-runner, .git, __pycache__, *.pyc, node_modules, .venv, venv.

Set sync.include_git: true to keep .git. Matching uses fnmatch against both the full relative path and each path component.

For SkyPilot, the staged directory is passed as workdir, so SkyPilot itself handles the upload to ~/sky_workdir. For the local backend, staging is the cluster.


Config reference

name: my-experiment                 # cluster/experiment name
backend: skypilot                   # skypilot | local
resources:
  accelerators: "A100:1"            # SkyPilot accelerator spec
  cpus: 4
  memory: "16"
  disk_size: 100
  image_id: "..."                   # optional VM image
  cloud: gcp                        # optional; auto-select if omitted
  region: us-central1
  zone: us-central1-a
  use_spot: false
setup: |                            # runs once at provision time
  pip install -r requirements.txt
run: python train.py                # default command for `run`
env:                                # injected into remote env
  WANDB_API_KEY: "..."
sync:
  local_path: .                     # source dir (relative to config)
  remote_path: ~/work
  excludes: ["*.log", "data/"]
  ignore_files: [".dockerignore", ".gitignore"]
  include_git: false
results:
  remote_path: ~/results            # where the experiment writes results
  local_path: ./results             # where to copy them locally
  cloud_storage: gs://bucket/prefix # optional remote upload target
idle_minutes_to_autostop: 30        # SkyPilot autostop
keep_cluster_on_failure: false

Install

pip install -e .
# Install SkyPilot separately, with the extras needed for your provider:
pip install 'skypilot[huggingface,runpod]>=0.14.3'

Requires Python ≥3.10. For the SkyPilot backend you also need SkyPilot configured for at least one cloud (sky check).


Usage

# three-step
gpu-runner up
gpu-runner run                      # or: gpu-runner run --command "python eval.py"
gpu-runner down

# one-shot
gpu-runner submit

# inspect
gpu-runner status

# override backend/config
gpu-runner --backend local submit
gpu-runner -c experiments/exp.yaml up

Backends

  • skypilot: provisions real ephemeral clusters via SkyPilot (GCP/AWS/Azure/Lambda/…). Multi-cloud, spot support, autostop.
  • local: runs in a local directory under ~/.gpu-runner/clusters/. Useful for developing and testing experiment code without a cluster.

Edge cases / design notes

  • State is file-based, so commands are composable in scripts and CI.
  • submit tears down even on failure unless keep_cluster_on_failure is set, preventing cost leaks.
  • Exclusions default to skipping .git, venvs, caches so uploads stay small.
  • Results copy is best-effort for cloud storage (uses gsutil/aws s3 on the cluster).
  • Exit codes propagate from the remote run command.

Development

uv sync --group dev
uv run pytest -q

Tests live in tests/ and cover sync staging/exclusion logic and config loading.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages