Metadata-Version: 2.5
Name: gpu-rich
Version: 0.0.2
Summary: Free GPUs, driven from your terminal by your AI agent.
Project-URL: Homepage, https://github.com/mohamed2394/gpu-rich
Project-URL: Repository, https://github.com/mohamed2394/gpu-rich
Project-URL: Issues, https://github.com/mohamed2394/gpu-rich/issues
License-Expression: Apache-2.0
License-File: LICENSE
Requires-Python: >=3.11
Requires-Dist: kaggle>=2.2
Requires-Dist: pydantic>=2.6
Requires-Dist: rich>=13
Requires-Dist: six
Requires-Dist: typer>=0.12
Provides-Extra: all
Requires-Dist: huggingface-hub>=1.0; extra == 'all'
Requires-Dist: modal>=1.6; extra == 'all'
Provides-Extra: hf
Requires-Dist: huggingface-hub>=1.0; extra == 'hf'
Provides-Extra: modal
Requires-Dist: modal>=1.6; extra == 'modal'
Description-Content-Type: text/markdown

# gpu-rich

Free GPUs, driven from your terminal by your AI agent.

`gpu-rich` sends a Python script or a Jupyter notebook to a free or cheap GPU (Kaggle, Google Colab, Modal, Hugging Face Jobs, NVIDIA Brev, Vast.ai, or your own machine over SSH). It follows the run, and it brings the results back to your folder. A searchable index of public notebooks and fine-tuning recipes helps your coding agent find something to run.

It is made for students and people who start with machine learning and have no GPU budget.

![A 28-second demo: an agent gets a request, gpu-rich picks the free Kaggle GPU, trains a model and brings the results back](https://raw.githubusercontent.com/mohamed2394/gpu-rich/main/docs/img/demo.gif)

Every terminal line and number in the demo comes from a real run on a free Kaggle T4.

## Status

Alpha, on [PyPI](https://pypi.org/project/gpu-rich/). Commands and JSON fields can still change.

The table says how far each backend is tested. "Tested with real runs" means that a full job ran on a real account: submit, logs, results, cancel.

| Backend | Cost | State |
|---|---|---|
| `kaggle` | free, about 30 GPU hours each week | tested with real runs |
| `colab` | free when a GPU is available; uses compute units when your account has them | tested with real runs on an account with compute units; the free path is not tested yet |
| `modal` | paid, 30 USD of monthly credits on the Starter plan | tested with real runs |
| `hf` (Hugging Face Jobs) | paid | experimental: built from documentation, never run on a real account |
| `brev` (NVIDIA Brev) | paid | experimental: built from documentation, never run on a real account |
| `vast` (Vast.ai) | paid, live marketplace price | experimental: built from documentation, never run on a real account |
| `ssh:<host>` | your own machine | tested against a local fake host only |
| `local` | this machine | for smoke tests |

The Colab backend works on Linux and macOS only, because the official Colab CLI does not support Windows.

## Install

You need Python 3.11 or newer and [uv](https://docs.astral.sh/uv/).

```bash
uv tool install gpu-rich
gpu-rich doctor
```

To try it without an install, run `uvx gpu-rich doctor`.

`gpu-rich doctor` lists every backend and gives one fix line for each backend that is not ready.

## Your first run, on a free Kaggle GPU

1. Create a Kaggle account and verify your phone number in the Kaggle settings. Kaggle gives GPU time to verified accounts only.
2. Go to kaggle.com > Settings > API and create a token. Save it to `~/.kaggle/access_token`.
3. Run `gpu-rich doctor`. The `kaggle` line must start with `ok`.
4. Run the example. It fine-tunes a small text classifier with LoRA in about 5 minutes.

```bash
curl -LO https://raw.githubusercontent.com/mohamed2394/gpu-rich/main/examples/finetune_lora.py
gpu-rich run finetune_lora.py
```

The results come back to `./gpu-rich-runs/RUN_ID/outputs/`: `metrics.json` and the LoRA adapter.

The Kaggle queue is slow at times. `gpu-rich` cancels a run that does not start in 5 minutes and submits it again, because a new submission usually starts in seconds.

## Quickstart for a person (60 seconds)

```bash
gpu-rich doctor                      # which backends are ready, and how to fix the others
gpu-rich plan train.py               # which backend would run it, and the cost
gpu-rich run train.py --detach       # start it; prints a run id
gpu-rich wait RUN_ID --timeout 300   # wait up to 5 minutes; run it again until the run ends
gpu-rich pull RUN_ID                 # results in ./gpu-rich-runs/RUN_ID/
```

Stop a run with `gpu-rich cancel RUN_ID`.

## Quickstart for an agent

Install the skill pack into your project, then start a new agent session:

```bash
gpu-rich skills install
```

This writes `.agents/skills/gpu-rich/` (read by Codex CLI, Gemini CLI, Qwen Code and Cursor) and `.claude/skills/gpu-rich/` (read by Claude Code). Use `--global` to install it for all your projects, and `--agent NAME` for one agent only.

Then ask your agent, for example: "Fine-tune a small model on my data in data/train.csv. I have no GPU."

The agent checks the backends, prepares the job, runs it detached, waits in bounded steps, fixes failures such as out-of-memory errors, and brings the results back.

## Commands

Put `--json` before the command to get one JSON document on stdout (for agents and scripts).

| Command | What it does |
|---|---|
| `gpu-rich doctor` | Checks sign-in and quota for every backend, and says how to fix each problem. |
| `gpu-rich backends` | Lists the machines each backend offers, with price and quota. |
| `gpu-rich plan FILE` | Dry run: which backend would run the job, why, and the cost. |
| `gpu-rich run FILE` | Runs a script or a notebook. Use `--detach` to return at once. |
| `gpu-rich status [RUN]` | One run, or the recent runs. |
| `gpu-rich logs [RUN]` | The job's log. `-f` follows it, `--tail N` keeps the last lines. |
| `gpu-rich wait [RUN]` | Waits at most `--timeout` seconds, then prints the run. |
| `gpu-rich pull [RUN]` | Downloads the outputs, `result.json` and the executed notebook. |
| `gpu-rich cancel [RUN]` | Stops a run and frees the remote machine. |
| `gpu-rich search QUERY` | Searches the recipe catalog. |
| `gpu-rich show ID` | Shows one catalog entry: link, licence, needs. |
| `gpu-rich fetch ID` | Downloads a catalog entry from its upstream link. |
| `gpu-rich report [RUN]` | Shares the test result of a catalog run, when you agree. |
| `gpu-rich catalog info` / `update` | Shows or updates the local catalog index. |
| `gpu-rich skills install` / `path` / `show` | Installs or shows the agent skill pack. |

Exit codes: 0 ok, 1 the run failed, 2 wrong usage, 3 sign-in problem, 4 no backend or quota, 5 platform error.

## The job header

A script says what it needs in a [PEP 723](https://peps.python.org/pep-0723/) header. The same file still runs with plain `uv run train.py`.

```python
# /// script
# requires-python = ">=3.11"
# dependencies = ["transformers", "datasets", "peft"]
#
# [tool.gpu-rich]
# gpu = "T4"
# max_hours = 2
# outputs = ["outputs"]
# include = ["data/train.csv"]
# secrets = ["HF_TOKEN"]
# ///
```

- `outputs`: what comes back. Write your results under `outputs/`.
- `include`: extra local files to send with the job.
- `secrets`: names of environment variables. The values come from your shell, never from the file.
- `max_hours`: the job stops at this time.

Notebooks keep the same keys in their metadata under `gpu-rich`. The full format is in [skills/gpu-rich/references/job-format.md](https://github.com/mohamed2394/gpu-rich/blob/main/skills/gpu-rich/references/job-format.md).

## Rules the tool follows

- It uses the official CLI or API of each platform.
- It supports one account per platform.
- It ships no tunnel, no keep-alive trick and no model serving.
- It never starts a paid backend unless you allow it.
- It never writes a token into the code it sends.

## Money safety

- Free backends come first. A paid backend runs only with `--allow-paid` or `--budget USD` on the command, or `budget_usd` in `~/.gpu-rich/config.toml`.
- `plan` shows the estimated cost before you run anything.
- Every job has a time limit (`max_hours`).
- `cancel` stops the remote machine. Check `gpu-rich status` for runs you forgot.
- Colab uses your compute units when your account has a balance. Modal, Hugging Face Jobs and Brev cost money.

## For contributors

- Tests: `uv run --group dev pytest`. Live tests against real platforms run only with `GPU_RICH_LIVE=1`.
- Adding a platform: [docs/adding-a-backend.md](https://github.com/mohamed2394/gpu-rich/blob/main/docs/adding-a-backend.md).
- Release check with a real agent: [docs/agent-e2e.md](https://github.com/mohamed2394/gpu-rich/blob/main/docs/agent-e2e.md).
- The design: [docs/plan.html](https://github.com/mohamed2394/gpu-rich/blob/main/docs/plan.html).

The catalog is an index of 2,049 public notebooks and scripts from 19 repositories. It links to them and does not copy them. Most entries are not tested on these backends yet, so a recipe can fail because of its own dependencies.

## A note on the language

The tool is written in Python, because the platform SDKs are Python and ML students already have it. Once everything is stable, a rewrite in Rust is inevitable. lol.

## Licence

Apache-2.0. See [LICENSE](https://github.com/mohamed2394/gpu-rich/blob/main/LICENSE). The recipe catalog links to third-party notebooks; each one keeps its own licence.
