Skip to content

Commit cdcbab1

Browse files
committed
infra: add workflow to start GPU server for aggregation mode
1 parent d6e548b commit cdcbab1

5 files changed

Lines changed: 86 additions & 17 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: "Start Aggregation Mode Server"
2+
3+
# Starts the Paperspace GPU server that runs the aggregation mode.
4+
#
5+
# The server is kept powered off to avoid 24/7 billing. This workflow boots it
6+
# once a day; on boot the machine runs `aggregation_mode.service`, which executes
7+
# the SP1 aggregations and then powers the machine off again
8+
# (see infra/aggregation_mode/run.sh).
9+
on:
10+
schedule:
11+
# 15:00 UTC == 12:00 GMT-3, every day. GitHub Actions cron is always in UTC.
12+
- cron: "0 15 * * *"
13+
workflow_dispatch:
14+
15+
jobs:
16+
start-server:
17+
name: Start Paperspace aggregation server
18+
runs-on: ubuntu-latest
19+
steps:
20+
- name: Start Paperspace machine
21+
env:
22+
PAPERSPACE_API_KEY: ${{ vars.PAPERSPACE_API_KEY }}
23+
MACHINE_ID: ${{ vars.PAPERSPACE_MACHINE_ID }}
24+
run: |
25+
set -euo pipefail
26+
27+
if [ -z "${PAPERSPACE_API_KEY}" ] || [ -z "${MACHINE_ID}" ]; then
28+
echo "::error::PAPERSPACE_API_KEY and PAPERSPACE_MACHINE_ID variables must be set."
29+
exit 1
30+
fi
31+
32+
echo "Starting Paperspace machine ${MACHINE_ID}..."
33+
http_code=$(curl -sS -o response.json -w "%{http_code}" \
34+
-X PATCH "https://api.paperspace.com/v1/machines/${MACHINE_ID}/start" \
35+
-H "Authorization: Bearer ${PAPERSPACE_API_KEY}")
36+
37+
echo "Paperspace API responded with HTTP ${http_code}"
38+
cat response.json || true
39+
40+
# 2xx means the start request was accepted.
41+
if [ "${http_code}" -lt 200 ] || [ "${http_code}" -ge 300 ]; then
42+
echo "::error::Failed to start Paperspace machine (HTTP ${http_code})."
43+
exit 1
44+
fi
45+
46+
echo "Start request accepted. The machine will run the aggregation on boot and shut itself down afterwards."

infra/aggregation_mode/README.md

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,33 @@
11
# Aggregation Mode Setup
22

3+
## Overview
4+
5+
The aggregation mode runs on a Paperspace GPU server. To avoid paying for the GPU
6+
24/7, the server is kept powered off and is only started once a day:
7+
8+
1. The [`Start Aggregation Mode Server`](../../.github/workflows/aggregation_mode.yml)
9+
GitHub Actions workflow runs daily at 15:00 UTC (12:00 GMT-3) and starts the
10+
Paperspace machine via the Paperspace API.
11+
2. On boot, `aggregation_mode.service` runs automatically and executes
12+
[`run.sh`](run.sh), which runs the SP1 and Risc0 aggregations.
13+
3. When the aggregations finish, `run.sh` powers the machine off again
14+
(`sudo shutdown -h now`), so Paperspace stops billing it.
15+
16+
The workflow needs:
17+
18+
- `PAPERSPACE_API_KEY` repository **variable** — a Paperspace API key.
19+
- `PAPERSPACE_MACHINE_ID` repository **variable** — the id of the GPU machine.
20+
321
## Setup on Server with GPU
422

523
To setup the server with GPU, follow the steps in [aggregation_mode.sh](aggregation_mode.sh).
624

7-
After running all the steps, `aggregation_mode.timer` will execute every 24hs the `aggregation_mode.service`
25+
After running all the steps, `aggregation_mode.service` is enabled to run on every
26+
boot. There is no timer anymore — the daily schedule is driven by the GitHub Actions
27+
workflow described above.
828

929
## Check Service Status
1030

11-
To check the status of the timer, run:
12-
13-
```bash
14-
systemctl status aggregation_mode.timer --user
15-
```
16-
1731
To check the status of the service, run:
1832

1933
```bash
@@ -22,7 +36,7 @@ systemctl status aggregation_mode.service --user
2236

2337
## Start Service manually
2438

25-
If you need to start the service manually, without waiting for the timer, run:
39+
If you need to start the service manually (the machine is already on), run:
2640

2741
```bash
2842
systemctl start aggregation_mode.service --user
@@ -33,7 +47,7 @@ systemctl start aggregation_mode.service --user
3347
To check the logs of the service, run:
3448

3549
```bash
36-
journalctl -xfeu aggregation_mode.service --user
50+
journalctl -xfeu aggregation_mode.service --user
3751
```
3852

3953
Note: You can add `-n <n_of_lines>` to limit the number of lines to show.

infra/aggregation_mode/aggregation_mode.service

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ ExecStartPre=sleep 60
99
ExecStart=/home/user/run.sh
1010

1111
[Install]
12-
WantedBy=multi-user.target
12+
WantedBy=default.target

infra/aggregation_mode/aggregation_mode.sh

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -132,18 +132,19 @@ cp ./infra/aggregation_mode/run.sh $HOME/run.sh
132132
chmod 744 $HOME/run.sh
133133

134134
# Setup systemd service
135+
# The service is enabled to run on every boot (no timer). The machine is started
136+
# once a day by the GitHub Actions workflow (.github/workflows/aggregation_mode.yml),
137+
# runs the aggregation on startup and then shuts itself down (see run.sh).
135138
cp ./infra/aggregation_mode/aggregation_mode.service $HOME/.config/systemd/user/aggregation_mode.service
136-
cp ./infra/aggregation_mode/aggregation_mode.timer $HOME/.config/systemd/user/aggregation_mode.timer
137139

138-
#sudo systemctl enable aggregation_mode.service
139-
systemctl --user enable aggregation_mode.timer
140-
systemctl --user start aggregation_mode.timer
140+
systemctl --user daemon-reload
141+
systemctl --user enable aggregation_mode.service
141142

142143
# Run the proof_aggregator manually if you want
143144
systemctl --user start aggregation_mode.service
144145

145-
# Check timer status
146-
systemctl --user status aggregation_mode.timer
146+
# Check service status
147+
systemctl --user status aggregation_mode.service
147148

148149
# Check logs
149150
journalctl -xfeu aggregation_mode.service --user -n10

infra/aggregation_mode/run.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/bash
22

3-
SLEEP=5
3+
SLEEP=60
44

55
echo "Starting Aggregation Mode in $SLEEP seconds..."
66
sleep $SLEEP
@@ -13,3 +13,11 @@ echo "SP1 Aggregation Mode finished"
1313
echo "Starting Risc0 Aggregation Mode..."
1414
AGGREGATOR=risc0 /home/user/.cargo/bin/proof_aggregator_gpu /home/user/config/config-proof-aggregator-risc0.yaml
1515
echo "Risc0 Aggregation Mode finished"
16+
17+
# Aggregation finished: power off the machine so Paperspace stops billing it.
18+
# The GitHub Actions workflow (.github/workflows/aggregation_mode.yml) starts the
19+
# machine again on the next scheduled run, and aggregation_mode.service runs this
20+
# script automatically on boot.
21+
echo "Aggregation finished, shutting down the machine in 1 minute..."
22+
sleep $SLEEP
23+
sudo shutdown -h now

0 commit comments

Comments
 (0)