Arrakis / Blog / Train and fine-tune
GPU Runner for CI: Rent a GPU per Pipeline, Then Drop It
A GPU you keep around for CI bills 24 hours a day, however few minutes your pipelines use it. A GPU runner for CI should exist only while a job needs it: rent a machine from the pipeline, run the GPU tests over SSH, terminate it. The Arrakis API makes that safe to automate, because idempotency keys stop double rentals, removal times clean up after crashed jobs, and a capped token puts a ceiling on what CI can ever spend.
The shape of the job
Six steps, all plain HTTP and SSH, in any CI system:
- Make a throwaway SSH key for this run.
- Find a machine that fits, under a price ceiling.
- Rent it with an idempotency key and a removal time.
- Wait until it is RUNNING. Booting is free.
- Ship the code and run the GPU tests.
- Terminate it, pass or fail.
The token
Create one token for the pipeline under API & agents in the console: scopes read and rent, a spend cap, a longest rental of 2 hours and an expiry. Store it in your CI's secret store. In GitHub Actions, that is a repository secret passed to the step as the ARRAKIS_TOKEN environment variable.
Budget it with the right model. The cap counts every rental at its worst case (hourly price times removal hours), for the life of the token, whether the machine ran 5 minutes or 2 hours. So the number of runs a token can pay for is:
runs = cap / (price per hour x removal hours)
A $40 cap at $1 an hour with 2-hour removal times covers 20 runs. When it runs out, the rental gets a 402 and nothing is rented: a red build, not a surprise invoice. Rotate the token monthly with that month's budget. The full rules are in AI agent spend limits for GPUs; they apply to CI tokens the same way.
The script
This runs on any Linux CI runner with curl, jq and ssh. Swap in your CI's run id if you are not on GitHub Actions:
#!/usr/bin/env bash
set -euo pipefail # gpu-tests.sh: rent, test, give it back
API=https://arrakis.goodailabs.com
AUTH="Authorization: Bearer $ARRAKIS_TOKEN" # a capped CI token from your secret store
KEY="ci-$GITHUB_RUN_ID-$GITHUB_RUN_ATTEMPT" # the same on a retry, new on a re-run
keys=$(mktemp -d) # step 1: a throwaway key, outside the code
ssh-keygen -t ed25519 -N "" -f "$keys/ci" -q
node=$(curl -fsS -G "$API/v1/gpus" -H "$AUTH" \
--data-urlencode "gpu_type=RTX 4090" --data-urlencode "tier=on_demand" \
--data-urlencode "max_price_per_gpu_hour=1" --data-urlencode "sort=price" \
| jq -c '[.nodes[] | select(.gpu_count == 1)][0]') # step 2: one RTX 4090, $1 per GPU-hour at most
[ "$node" != null ] || { echo "no machine fits"; exit 1; }
inst=$(jq -n --argjson n "$node" --arg key "$KEY" --arg pub "$(cat "$keys/ci.pub")" \
'{node_id: $n.id, name: $key, ssh_public_key: $pub, termination_hours: 2,
max_price_per_gpu_hour: $n.price_per_gpu_hour, idempotency_key: $key}' \
| curl -fsS -X POST "$API/v1/instances" -H "$AUTH" -H "Content-Type: application/json" -d @- \
| jq -r .id) # step 3: rent with a removal time and a price ceiling
trap 'curl -fsS -X POST "$API/v1/instances/$inst/terminate" -H "$AUTH" > /dev/null' EXIT
for _ in $(seq 60); do # step 4: wait until it runs (booting is free)
state=$(curl -fsS "$API/v1/instances/$inst" -H "$AUTH" | jq -r .state)
case "$state" in RUNNING) break ;; FAILED|TERMINATED) echo "machine $state"; exit 1 ;; esac
sleep 10
done
[ "$state" = RUNNING ] || { echo "still $state after 10 minutes"; exit 1; }
ssh_cmd=$(curl -fsS "$API/v1/instances/$inst" -H "$AUTH" | jq -r .ssh_command)
SSH="$ssh_cmd -i $keys/ci -o StrictHostKeyChecking=accept-new"
tar czf - --exclude=.git . | $SSH 'mkdir -p /workspace/src && tar xzf - -C /workspace/src' # step 5
$SSH 'cd /workspace/src && pip install -q -r requirements.txt && pytest -m gpu'Why each piece is there
The idempotency key. CI retries things: a flaky network, a timeout on the rent call, a step retried by a wrapper. The same idempotency_key always returns the same machine, never a second bill. Building it from the run id and the attempt number means a retry inside one attempt finds the machine it already rented, and a fresh re-run of the workflow gets a fresh machine.
The removal time. The trap terminates the machine when the script exits, pass or fail. But a runner can be killed outright, and then no trap fires. termination_hours: 2 is the backstop: the machine removes itself at its removal time no matter what happened to the runner. Set it to the longest the suite can take, plus a margin.
The price ceiling. Search results can be a minute old. With max_price_per_gpu_hour, a rental at a higher live price rents nothing and gets a 409 with the new price. Your pipeline never pays more than the number it searched for.
The throwaway key. A new key per run, made in a temp folder outside the code you ship, and gone with the runner. No long-lived private key sits in your CI secrets, and a leaked one opens nothing once its machine is gone.
On-demand, not spot. A spot host can take the machine back at any time. In CI that shows up as a flaky test you will waste an afternoon on. Keep spot for training that checkpoints.
Pick the GPU and the image
Most GPU test suites need a CUDA device, not a monster. An RTX 4090 starts at the live price per GPU-hour right now and an L40S (48 GB) at the live price. Tests that load large models may need an H100 at the live price; size it with the GPU memory guide.
The machine boots the Arrakis PyTorch image unless you say otherwise: PyTorch 2.14.1, CUDA 13.0, Python 3.12. To test in your own environment, send "image": "ghcr.io/you/test-env:sha" with "start": "idle" in the rent body, or save a private image once and pass its template_id. Keep it lean: the first start downloads the image, and a 12 GB image can take 10 to 20 minutes on a slow network. More in your own Docker image on a GPU server.
Test data that outlives the runner
Private fixtures, such as golden outputs or the fine-tuned checkpoint your tests load, can live on a volume instead of riding along in the tarball every run. Add --data-urlencode "volumes=true" to the search and volume_id to the rent body, and they're at /mnt when the machine starts. Parallel pipelines can mount the same volume at once; let CI only read it, since the last write wins. Keep it small, too. Every run reads its fixtures again, reads are included only up to what the volume holds each month, and reads well beyond that may be charged per GB, with notice first. Public model weights come straight from Hugging Face. The pattern: persistent storage for cloud GPUs.
Money: batch, do not sprinkle
The first hour is charged when the machine starts running, and each started hour counts in full. A 6-minute GPU test pays an hour. Ten of them in ten separate jobs pay ten hours. So:
- Run every GPU suite in one rental per pipeline, not one rental per test file.
- Run the GPU stage on merges to main or nightly, not on every push to every branch.
- Fail fast before renting: lint and CPU tests first, the GPU last.
The full billing rules are in Billing, and every endpoint used above is in the API docs.
When it fails, it fails loudly
The API answers with meaningful codes, so the script's curl -f turns each into a red build with a reason: 402 when the balance or the cap cannot cover the rental, 409 when the price moved past your ceiling, 422 for bad input, 429 to slow down. In every one of those cases nothing was rented.
Ship GPU tests without a GPU on payroll
One token, one script, and your pipeline rents a GPU for exactly as long as it needs one. Create a capped CI token.
New here? Use code FIRST25 for $25 off your first deposit of $50 or more, until 31 December 2026.
Rent the GPUs in this post
- RTX 4090the live price /GPU-hourRent
- L40Sthe live price /GPU-hourRent
- H100the live price /GPU-hourRent
New here? Use code FIRST25 for $25 off your first deposit of $50 or more, until 31 December 2026.
Lowest price now, per GPU-hour. Billed per started hour; stop any time.