8000 GitHub - anihm136/gpu-runner · GitHub
[go: up one dir, main page]

Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

3 Commits

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, shutil for staging and local result copies, rsync for remote result downloads, 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; relative sync.local_path and results.local_path resolve against it. If no config is found, the runner uses defaults with the current directory as the root.

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 the YAML backend setting (default skypilot), unless --backend overrides it.
  • Stages code: copies sync.local_path into a staging directory, applying exclude patterns (see Sync below).
  • Provisions:
    • skypilot: uses the optional Python SDK to launch a sky.Task with the configured resources, environment, setup, staged workdir, and idle autostop. SkyPilot uploads the workdir to ~/sky_workdir. up waits for the readiness job to finish and attempts teardown if launch fails.
    • 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 saved state and fails if none is found.
  • Runs setup (if configured) before each run command, including when using --command. If setup fails, the run command is skipped. On SkyPilot, setup also runs during up.
    • skypilot: submits setup and run as separate sky.exec jobs and follows their logs until they exit.
    • local: runs subprocesses in the staged workdir with the configured environment merged into the local environment.
  • Copies results back:
    • skypilot: downloads <cluster>:<results.remote_path> to <results.local_path> with rsync over SSH; if results.cloud_storage is set, also runs an upload command on the cluster.
    • local: copies from <cluster-dir>/results, falling back to <cluster-dir>/work/results if the first path doesn't exist. results.remote_path and results.cloud_storage do not apply to this backend.
  • Logs and returns the exit code. SkyPilot saves that code in state; result transfer failures reported by the SkyPilot backend do not replace it.

5. down — teardown

  • skypilot: calls sky.down and waits for teardown.
  • local: deletes the cluster directory.
  • Clears the state file after the teardown call returns, even if the backend reports failure.

6. submit — one-shot

Uses a fresh cluster name with a random suffix. If up succeeds, it runs the experiment, then attempts teardown unless the run failed and keep_cluster_on_failure: true.


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 remove the literal .git exclusion. Matching uses fnmatch against both the full relative path and each path component; full .gitignore and .dockerignore syntax is not supported.

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-centr
73A2
al1-a
  use_spot: false
setup: |                            # before each run; also during SkyPilot up
  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)
  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 the optional SkyPilot SDK in the same Python environment as gpurun,
# with the extras needed for your provider:
pip install 'skypilot[huggingface,runpod]>=0.14.3'

Requires Python ≥3.10. The local backend does not require SkyPilot. For the SkyPilot backend, configure at least one provider (sky check) and have rsync and SSH available for result downloads.


Usage

gpu-runner and gpurun are interchangeable.

# 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 saved state (does not query the provider)
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.
  • Exclusions default to skipping .git, venvs, caches so uploads stay small.
  • Cloud result uploads are best-effort and require gsutil or aws on the cluster.

Development

uv sync --group dev
uv run pytest -q

Tests live in tests/ and cover config loading, staging and exclusions, state persistence, and the SkyPilot backend with a mocked SDK. They do not provision cloud resources.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0