Keep s3-maze Harbor-native
#1
by lewtun HF Staff - opened
This view is limited to 50 files because it contains too many changes. See the raw diff here.
- README.md +25 -150
- budget.py +1 -1
- check.py +6 -114
- eval/metrics.py +0 -404
- generate.py +1 -1
- legion/registries.conf +0 -13
- legion/spec.template.yaml +0 -73
- legion/sweep/README.md +0 -87
- legion/sweep/health-log.sh +0 -27
- legion/sweep/plot.py +0 -293
- legion/sweep/serve-vllm.sbatch +0 -33
- legion/sweep/setaside.py +0 -96
- legion/sweep/sweep.py +0 -570
- legion/team.md +0 -1
- legion/team.py +0 -101
- tasks/maze-t01/environment/docker-compose.yaml +2 -2
- tasks/maze-t01/environment/maze/service.py +1 -1
- tasks/maze-t01/environment/maze/success.py +1 -2
- tasks/maze-t02/environment/docker-compose.yaml +2 -2
- tasks/maze-t02/environment/maze/service.py +1 -1
- tasks/maze-t02/environment/maze/success.py +1 -2
- tasks/maze-t03/environment/docker-compose.yaml +2 -2
- tasks/maze-t03/environment/maze/service.py +1 -1
- tasks/maze-t03/environment/maze/success.py +1 -2
- tasks/maze-t04/environment/docker-compose.yaml +2 -2
- tasks/maze-t04/environment/maze/service.py +1 -1
- tasks/maze-t04/environment/maze/success.py +1 -2
- tasks/maze-t05/environment/docker-compose.yaml +2 -2
- tasks/maze-t05/environment/maze/service.py +1 -1
- tasks/maze-t05/environment/maze/success.py +1 -2
- tasks/maze-t06/environment/docker-compose.yaml +2 -2
- tasks/maze-t06/environment/maze/service.py +1 -1
- tasks/maze-t06/environment/maze/success.py +1 -2
- tasks/maze-t07/environment/docker-compose.yaml +2 -2
- tasks/maze-t07/environment/maze/service.py +1 -1
- tasks/maze-t07/environment/maze/success.py +1 -2
- tasks/maze-t08/environment/docker-compose.yaml +2 -2
- tasks/maze-t08/environment/maze/service.py +1 -1
- tasks/maze-t08/environment/maze/success.py +1 -2
- tasks/maze-t09/environment/docker-compose.yaml +2 -2
- tasks/maze-t09/environment/maze/service.py +1 -1
- tasks/maze-t09/environment/maze/success.py +1 -2
- tasks/maze-t10/environment/docker-compose.yaml +2 -2
- tasks/maze-t10/environment/maze/service.py +1 -1
- tasks/maze-t10/environment/maze/success.py +1 -2
- tasks/maze-t11/environment/docker-compose.yaml +2 -2
- tasks/maze-t11/environment/maze/service.py +1 -1
- tasks/maze-t11/environment/maze/success.py +1 -2
- tasks/maze-t12/environment/docker-compose.yaml +2 -2
- tasks/maze-t12/environment/maze/service.py +1 -1
README.md
CHANGED
|
@@ -18,14 +18,9 @@ A [Harbor](https://harborframework.com) environment that measures whether a swar
|
|
| 18 |
**communicates when it pays off**: any agent can find the exit alone, but the maze is too large
|
| 19 |
for one agent's move budget, so sharing what each one has explored lets a team search it in
|
| 20 |
time. It adapts the parallel-exploration task of
|
| 21 |
-
[s³: Simple Scaling of Swarms via Cooperative Multi-agent RL](https://arxiv.org/abs/2611.08615)
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
agents are Pi with Legion's board, and the board is what we measure. Its companion,
|
| 25 |
-
[s3-aggregation](https://huggingface.co/datasets/HuggingFaceSwarms/s3-aggregation), needs
|
| 26 |
-
communication instead.
|
| 27 |
-
|
| 28 |
-
**This dataset is private for now.**
|
| 29 |
|
| 30 |
## The task
|
| 31 |
|
|
@@ -67,16 +62,10 @@ tasks/maze-tNN/
|
|
| 67 |
environment/docker-compose.yaml main (the agent) and maze, on an internal network only main reaches
|
| 68 |
environment/agent/ main's image: its Dockerfile and the `maze` command, nothing else
|
| 69 |
environment/maze/ the service's image: tree.json (private), engine.py, service.py,
|
| 70 |
-
success.py (
|
| 71 |
tests/ the grader's own image: test.sh, grade.py, expected.json
|
| 72 |
solution/solve.sh an oracle that walks the shortest path with `maze move`
|
| 73 |
template/ the files every task shares (generate.py copies them)
|
| 74 |
-
legion/
|
| 75 |
-
spec.template.yaml what every team's Legion run shares: model, board rules, loop, limits
|
| 76 |
-
team.py writes one team's spec (the HF cluster, or local docker)
|
| 77 |
-
registries.conf podman pulls Docker Hub images through mirror.gcr.io
|
| 78 |
-
sweep/ the scaling sweep (every tree at N = 1..16, one model per grid): its README
|
| 79 |
-
eval/metrics.py one row per team from Legion run directories
|
| 80 |
generate.py writes tasks/ from its seed (115)
|
| 81 |
budget.py the move-budget table below, from the service's own engine
|
| 82 |
check.py the checks that need no model
|
|
@@ -114,17 +103,15 @@ doesn't count), it writes 0 before it checks anything, never writes through a li
|
|
| 114 |
Python runs isolated (`python3 -I -S`). It keeps copies of `moves.jsonl` and `final.json` in
|
| 115 |
`/logs/verifier/` for the metrics.
|
| 116 |
|
| 117 |
-
**
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
from the service's state. Legion polls it every 30 s per agent, then interrupts the turns,
|
| 122 |
-
releases the workers and grades each agent's Trial.
|
| 123 |
|
| 124 |
## The move budget
|
| 125 |
|
| 126 |
Simulated with the service's own engine (`template/environment/maze/engine.py`: every move
|
| 127 |
-
goes through the same `Walk` the service holds), without
|
| 128 |
`python budget.py` over the 32 trees, for N agents and a per-agent budget:
|
| 129 |
|
| 130 |
- **(a)** one agent, depth-first: the first door it hasn't been through, in the listed order,
|
|
@@ -186,91 +173,21 @@ habits of 1, 0.8, 0.5 and 0 (`--habit 0`: independent random orders), and at N =
|
|
| 186 |
(c) is what sharing explored branches can buy. The budget is in every task's tree, grader,
|
| 187 |
instruction and `task.toml` (`move_budget`).
|
| 188 |
|
| 189 |
-
## Run
|
| 190 |
|
| 191 |
-
The maze
|
| 192 |
-
|
| 193 |
-
team in rootless podman with `podman-compose` (hopper-cpu has podman 4.9.3; the B200 nodes'
|
| 194 |
-
podman 3.4.4 can't create Legion's per-agent networks), and a local board on that worker, new
|
| 195 |
-
each run. Legion's [`experiments/s3-maze/spec.yaml`](https://github.com/huggingface/legion/tree/main/experiments/s3-maze)
|
| 196 |
-
runs one team (`TREE`, default `maze-t01`, and `N`, default 4) at the revision it pins; Legion's
|
| 197 |
-
`docs/tasks.md` ("s3-maze") has the commands. For any other team, `legion/team.py` writes the
|
| 198 |
-
spec from `legion/spec.template.yaml`, run from Legion's checkout:
|
| 199 |
|
| 200 |
```sh
|
| 201 |
-
|
| 202 |
-
hf download HuggingFaceSwarms/s3-maze --repo-type dataset --revision <sha> --local-dir $DS
|
| 203 |
-
uv run python $DS/legion/team.py --tree 7 --agents 4 --out runs/src/maze-t07-n04
|
| 204 |
-
uv run legion init $PWD/runs/maze-t07-n04 --from runs/src/maze-t07-n04 --profile cluster.env --secrets secrets.env
|
| 205 |
-
export LEGION_RUN_DIR=$PWD/runs/maze-t07-n04
|
| 206 |
-
uv run legion launch $LEGION_RUN_DIR/experiment
|
| 207 |
-
uv run legion status maze-t07-n04 # STOPPED ON SUCCESS once an agent gets out
|
| 208 |
-
uv run legion stop maze-t07-n04 --release # ends the controller (and a run nobody won)
|
| 209 |
-
uv run python $DS/eval/metrics.py $LEGION_RUN_DIR
|
| 210 |
```
|
| 211 |
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
(Docker Hub's pull limit hits the cluster's shared address hard); and a mode-600 secrets file
|
| 215 |
-
with `HF_TOKEN` (reads this private dataset and the run's bucket), `HF_INFERENCE_TOKEN` (a
|
| 216 |
-
fine-grained token with only "Make calls to Inference Providers", which goes into the agents'
|
| 217 |
-
containers: never the same token), `NAMESPACE` and `BUCKET` (a private bucket for the run's
|
| 218 |
-
state). The worker gets a CPU per agent and two more, at 1900 MB per CPU. hopper-cpu
|
| 219 |
-
autoscales: a scale-up from 0 can take about 15 minutes.
|
| 220 |
-
|
| 221 |
-
With stop on success, the run ends when the first agent reaches the exit: Legion grades every
|
| 222 |
-
Trial as it releases the worker, and the worker copies the grading (with the move logs) and the
|
| 223 |
-
board export to `<run dir>/results/` (Legion's `LEGION_RESULTS_DIR`), where `metrics.py` reads
|
| 224 |
-
them. A run that nobody wins ends its loop after 45 minutes or 6 rounds, and doesn't end by
|
| 225 |
-
itself on Slurm: `legion stop --release` drains the worker, which is when its Trials are graded.
|
| 226 |
-
|
| 227 |
-
### The board rules
|
| 228 |
-
|
| 229 |
-
The same for every eval run, since they shape how agents talk (`legion/spec.template.yaml`):
|
| 230 |
-
one channel, `#general`, and no more (`max_channels: 1`); an agent is woken by a mention or a
|
| 231 |
-
reply in its thread; a post is at most 1000 characters, at least 5 s after the agent's previous
|
| 232 |
-
one, and at most 40 per agent. Podman enforces them in each agent's rule proxy.
|
| 233 |
-
|
| 234 |
-
### The protocol hint
|
| 235 |
-
|
| 236 |
-
`team.py --hint` adds `legion/team.md` as the team's `team_file`, which Legion appends to each
|
| 237 |
-
agent's instructions: "Before you go through a door, read the board and post which door you are
|
| 238 |
-
taking; pick one no teammate has claimed; post when a branch is a dead end." Without it, the
|
| 239 |
-
team gets the neutral instructions.
|
| 240 |
|
| 241 |
-
|
| 242 |
|
| 243 |
-
|
| 244 |
-
per run directory (one team), as s3-aggregation's does, with the maze's fields added from the
|
| 245 |
-
move logs the grader keeps:
|
| 246 |
-
|
| 247 |
-
| field | |
|
| 248 |
-
| --- | --- |
|
| 249 |
-
| `task`, `agents`, `revision`, `stop_reason`, `duration_s` | the team and how its run ended |
|
| 250 |
-
| `success` | any agent's reward is 1 (`null`: no rewards found) |
|
| 251 |
-
| `rewards` | each agent's reward: its latest Trial's verifier result |
|
| 252 |
-
| `tokens`, `cost_usd` | the team's tokens (input, output, cache, reasoning) and cost |
|
| 253 |
-
| `posts`, `other_posts` | the team's board posts in the run; posts by anyone else |
|
| 254 |
-
| `per_agent` | each agent's reward, tokens, posts and turns |
|
| 255 |
-
| `edges` | the message graph: sender -> each teammate it mentions (a group mention names every member) or messages directly (a DM, or a private channel of the two) |
|
| 256 |
-
| `centralization` | the paper's (Appendix M): the sum over agents of (k* - k_j) / (N - 1)^2, k_j the in-degree; `null` for N = 1 |
|
| 257 |
-
| `reciprocity` | the fraction of edges whose reverse exists; `null` without edges |
|
| 258 |
-
| `moves`, `refused_moves` | each agent's accepted and refused moves (over all its Trials) |
|
| 259 |
-
| `rooms`, `rooms_union` | the rooms each agent visited (the start included), and the team's together |
|
| 260 |
-
| `room_overlap` | the paper's (Appendix M): (V - U) / V, V = sum_i (\|R_i\| - 1), U = \|union of the R_i\| - 1: 0 when no two agents visit the same room, near 1 when all walk the same path; `null` when no agent moved |
|
| 261 |
-
| `exit_reached_by` | the agents whose walk reached the exit |
|
| 262 |
-
| `first_exit` | the first agent to reach the exit, how long after the team's Trials started, with how many moves of its own, and the team's moves by then; `null` when no agent got out |
|
| 263 |
-
| `missing` | what the run directory lacks (an agent's reward or move log, a move log's unreadable line, the board export), and where its spec and its Trials disagree |
|
| 264 |
-
|
| 265 |
-
A reward and a move log count only from a Trial whose `result.json` holds Harbor's verifier
|
| 266 |
-
result: the agent's container can write into its `verifier/` folder while it works, and only
|
| 267 |
-
the verifier's run replaces what is there. A Slurm run has no local bundle, so there the tokens
|
| 268 |
-
come from Harbor's Trial results (no reasoning split), and `stop_reason`, `cost_usd` and the
|
| 269 |
-
turns are `null`. Its task and roster come from `experiment/spec.yaml` as the run resolved it:
|
| 270 |
-
`${VAR}`s from `cluster.env` then `run.env`, else their defaults. Every agent the spec planned
|
| 271 |
-
is in the row, so one whose results are missing is flagged rather than dropped; so are Trials
|
| 272 |
-
of an agent the spec didn't plan, or of another task than it selects (e.g. a run directory
|
| 273 |
-
whose `run.env` is gone, read with the defaults).
|
| 274 |
|
| 275 |
## Checks
|
| 276 |
|
|
@@ -278,15 +195,10 @@ The checks that need no model, in one command, on a machine with podman (or dock
|
|
| 278 |
Trials (`uv` installs Harbor 0.25.0):
|
| 279 |
|
| 280 |
```sh
|
| 281 |
-
uv run check.py --env podman #
|
| 282 |
uv run check.py --env none # without the Trials
|
| 283 |
```
|
| 284 |
|
| 285 |
-
On the HF cluster, from Legion's checkout, with rootless podman set up as a worker has it:
|
| 286 |
-
`srun -p hopper-cpu -c 8 --mem=15G bash -c 'source scripts/slurm/podman-node.sh &&
|
| 287 |
-
CONTAINERS_REGISTRIES_CONF=$DS/legion/registries.conf .venv/bin/python $DS/check.py --env podman;
|
| 288 |
-
podman_node_cleanup'`.
|
| 289 |
-
|
| 290 |
1. **Generator:** `generate.py` reproduces `tasks/` byte for byte, and another seed gives other
|
| 291 |
trees, which record that seed in their `task.toml` and regenerate from it. Each tree has 391 rooms with distinct 4-digit labels, is a tree (390 two-way doors,
|
| 292 |
all reachable), has 27 dead ends all 30 moves from the start, one of them the exit; the
|
|
@@ -322,15 +234,8 @@ podman_node_cleanup'`.
|
|
| 322 |
`maze` command and names no room, nor do the instruction, `task.toml` or the compose file;
|
| 323 |
the exit is named only in the service's `tree.json`, `tests/expected.json` and
|
| 324 |
`solution/solve.sh`; no folder beside `tasks/` holds a tree.
|
| 325 |
-
5. **
|
| 326 |
-
|
| 327 |
-
`${N:-4}`): with no env files the row's task is `maze-t01` and its team four agents;
|
| 328 |
-
`run.env` (over `cluster.env`) sets another tree and team size; a team with one agent's
|
| 329 |
-
results gone keeps that agent and flags its reward and move log as missing; and the row
|
| 330 |
-
flags Trials of another task than the spec selects (a `run.env` gone) and of an agent the
|
| 331 |
-
spec didn't plan.
|
| 332 |
-
6. **Trials** (`--env podman` or `docker`, on `maze-t01`, with agents that need no model):
|
| 333 |
-
- a walker runs Legion's success check in the maze service (false), walks the shortest path
|
| 334 |
with `maze move`, runs it again (true), and scores 1, with the move log and the export in
|
| 335 |
its verifier's folder;
|
| 336 |
- Harbor's oracle agent (`solution/solve.sh`) scores 1;
|
|
@@ -341,50 +246,20 @@ podman_node_cleanup'`.
|
|
| 341 |
`/logs/artifacts` and `/logs/verifier`, a `reward.txt` of 1, a `json.py` and a
|
| 342 |
`sitecustomize`, makes three moves short of the exit, and scores 0.
|
| 343 |
|
| 344 |
-
Last run on a hopper-cpu node (podman 4.9.3), before the Legion rename: all checks passed.
|
| 345 |
-
|
| 346 |
-
## Dummy run
|
| 347 |
-
|
| 348 |
-
One team, `maze-t01` with N = 4, from the pre-rename `experiments/s3-maze/spec.yaml` (dataset revision
|
| 349 |
-
`0f1fe651`, whose `tasks/` are this revision's) on the HF cluster on 2026-11-17:
|
| 350 |
-
`Qwen/Qwen3.8-27B` on the HF router (deepinfra), one hopper-cpu worker of 6 CPUs running the
|
| 351 |
-
four Trials in rootless podman, and a local board.
|
| 352 |
-
|
| 353 |
-
- **The team found the exit.** agent-003 reached it after 154 moves, 10 min 22 s after the
|
| 354 |
-
Trials started. Legion's success check saw it 27 s later, held the run, interrupted the other
|
| 355 |
-
agents and released the worker; every Trial was graded within a minute and the worker ended,
|
| 356 |
-
at 11:50 UTC. Only agent-003 scored 1.
|
| 357 |
-
- **They split the tree on the board** without being told to: agents posted the corridors they
|
| 358 |
-
walked, claimed branches at junctions, reported each dead end and re-planned around a silent
|
| 359 |
-
teammate; agent-003 took the last unclaimed branch at the start room, and found the exit there.
|
| 360 |
-
- **The budget binds.** agent-002 wrote a search script that walked into one dead end and then
|
| 361 |
-
bounced between it and its neighbour until its 200th move, and posted once.
|
| 362 |
-
- **The metrics row** (`eval/metrics.py` on the run directory): `success` true; rewards 0, 0, 1,
|
| 363 |
-
0; posts 7, 1, 12, 10; moves 101, 200, 154, 158 (one refused); rooms 52, 31, 93, 89, 211
|
| 364 |
-
together; room overlap 0.195; no @-mentions or DMs, so no edges (centralization 0,
|
| 365 |
-
reciprocity `null`); 413k input, 6.86M cached and 70k output tokens, about $1.20 on deepinfra;
|
| 366 |
-
nothing missing.
|
| 367 |
-
|
| 368 |
## Known limits
|
| 369 |
|
| 370 |
- **HF Sandboxes can't run it:** each agent's Trial is two containers (the agent's and its maze
|
| 371 |
service), and HF Sandboxes run one container per Trial. It needs multi-container support
|
| 372 |
there, as AgentEscapeBench does. Until then it runs on docker or podman (the HF cluster).
|
| 373 |
-
- **
|
| 374 |
-
|
| 375 |
-
- **A new Trial starts a new maze.** If an agent's Trial fails and Legion starts another (or a
|
| 376 |
-
worker is relaunched), that agent gets a fresh copy of the maze at the start, with a fresh
|
| 377 |
-
budget, while its Pi session remembers the old walk. `metrics.py` counts moves over all of an
|
| 378 |
-
agent's Trials, and its reward is its latest Trial's.
|
| 379 |
-
- **The first exit ends the run, not the episode at once:** Legion checks every 30 s, so the
|
| 380 |
-
other agents may move for up to about 30 s more before their turns are interrupted.
|
| 381 |
- **The grader trusts the maze service.** The agent reaches it only through `maze look` and
|
| 382 |
`maze move` (an internal network, two routes, bodies up to 4 KiB); an agent that could reach
|
| 383 |
the service any other way could forge its record. The service runs without capabilities, with
|
| 384 |
a pids and memory limit, so flooding it only hurts the agent's own maze.
|
| 385 |
-
- **The move log's `agent`**
|
| 386 |
-
|
| 387 |
- **Not the paper's setup:** a per-agent move budget instead of a token allowance (looking and
|
| 388 |
refused moves are free), a message board instead of `message`/`read_messages` tools with
|
| 389 |
-
notifications,
|
| 390 |
observation, and N = 1 is a solo control.
|
|
|
|
| 18 |
**communicates when it pays off**: any agent can find the exit alone, but the maze is too large
|
| 19 |
for one agent's move budget, so sharing what each one has explored lets a team search it in
|
| 20 |
time. It adapts the parallel-exploration task of
|
| 21 |
+
[s³: Simple Scaling of Swarms via Cooperative Multi-agent RL](https://arxiv.org/abs/2611.08615).
|
| 22 |
+
The companion [s3-aggregation](https://huggingface.co/datasets/HuggingFaceSwarms/s3-aggregation)
|
| 23 |
+
requires communication to obtain the teammates' private numbers.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
|
| 25 |
## The task
|
| 26 |
|
|
|
|
| 62 |
environment/docker-compose.yaml main (the agent) and maze, on an internal network only main reaches
|
| 63 |
environment/agent/ main's image: its Dockerfile and the `maze` command, nothing else
|
| 64 |
environment/maze/ the service's image: tree.json (private), engine.py, service.py,
|
| 65 |
+
success.py (exit status), export.py (the collect hook)
|
| 66 |
tests/ the grader's own image: test.sh, grade.py, expected.json
|
| 67 |
solution/solve.sh an oracle that walks the shortest path with `maze move`
|
| 68 |
template/ the files every task shares (generate.py copies them)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
generate.py writes tasks/ from its seed (115)
|
| 70 |
budget.py the move-budget table below, from the service's own engine
|
| 71 |
check.py the checks that need no model
|
|
|
|
| 103 |
Python runs isolated (`python3 -I -S`). It keeps copies of `moves.jsonl` and `final.json` in
|
| 104 |
`/logs/verifier/` for the metrics.
|
| 105 |
|
| 106 |
+
**Exit status.** Run `python3 -I -S /app/success.py` in the maze service to read the exit state.
|
| 107 |
+
It prints JSON with a `success` boolean and, when available, evidence with `exit_reached`,
|
| 108 |
+
`moves` and `reached_at`. A team runner can use this signal to end the search before grading
|
| 109 |
+
the Trials.
|
|
|
|
|
|
|
| 110 |
|
| 111 |
## The move budget
|
| 112 |
|
| 113 |
Simulated with the service's own engine (`template/environment/maze/engine.py`: every move
|
| 114 |
+
goes through the same `Walk` the service holds), without containers:
|
| 115 |
`python budget.py` over the 32 trees, for N agents and a per-agent budget:
|
| 116 |
|
| 117 |
- **(a)** one agent, depth-first: the first door it hasn't been through, in the listed order,
|
|
|
|
| 173 |
(c) is what sharing explored branches can buy. The budget is in every task's tree, grader,
|
| 174 |
instruction and `task.toml` (`move_budget`).
|
| 175 |
|
| 176 |
+
## Run a Harbor task
|
| 177 |
|
| 178 |
+
The maze uses two containers per Trial, so use Docker or Podman. Validate the search and
|
| 179 |
+
grader with Harbor's oracle:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
```sh
|
| 182 |
+
uv run --with harbor==0.25.0 harbor run --path tasks/maze-t01 --agent oracle --env docker
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
```
|
| 184 |
|
| 185 |
+
For a cooperative run, give each participant its own Trial of the same task and supply a
|
| 186 |
+
shared message board. The team succeeds if any participant earns 1.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
|
| 188 |
+
The maintained team recipe connects the exit status and a shared board. [Legion experiment](https://github.com/huggingface/legion/tree/main/experiments/s3-maze)
|
| 189 |
|
| 190 |
+
The prior sweep and metrics are archived with the original run setup. [Dataset revision `3421ea2`](https://huggingface.co/datasets/HuggingFaceSwarms/s3-maze/tree/3421ea2d46e8963e59cf3690da6ea47739eefb2f)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
|
| 192 |
## Checks
|
| 193 |
|
|
|
|
| 195 |
Trials (`uv` installs Harbor 0.25.0):
|
| 196 |
|
| 197 |
```sh
|
| 198 |
+
uv run check.py --env podman # include the Trials
|
| 199 |
uv run check.py --env none # without the Trials
|
| 200 |
```
|
| 201 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 202 |
1. **Generator:** `generate.py` reproduces `tasks/` byte for byte, and another seed gives other
|
| 203 |
trees, which record that seed in their `task.toml` and regenerate from it. Each tree has 391 rooms with distinct 4-digit labels, is a tree (390 two-way doors,
|
| 204 |
all reachable), has 27 dead ends all 30 moves from the start, one of them the exit; the
|
|
|
|
| 234 |
`maze` command and names no room, nor do the instruction, `task.toml` or the compose file;
|
| 235 |
the exit is named only in the service's `tree.json`, `tests/expected.json` and
|
| 236 |
`solution/solve.sh`; no folder beside `tasks/` holds a tree.
|
| 237 |
+
5. **Trials** (`--env podman` or `docker`, on `maze-t01`, with agents that need no model):
|
| 238 |
+
- a walker runs the exit status check in the maze service (false), walks the shortest path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
with `maze move`, runs it again (true), and scores 1, with the move log and the export in
|
| 240 |
its verifier's folder;
|
| 241 |
- Harbor's oracle agent (`solution/solve.sh`) scores 1;
|
|
|
|
| 246 |
`/logs/artifacts` and `/logs/verifier`, a `reward.txt` of 1, a `json.py` and a
|
| 247 |
`sitecustomize`, makes three moves short of the exit, and scores 0.
|
| 248 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 249 |
## Known limits
|
| 250 |
|
| 251 |
- **HF Sandboxes can't run it:** each agent's Trial is two containers (the agent's and its maze
|
| 252 |
service), and HF Sandboxes run one container per Trial. It needs multi-container support
|
| 253 |
there, as AgentEscapeBench does. Until then it runs on docker or podman (the HF cluster).
|
| 254 |
+
- **A new Trial starts a new maze.** It starts with a fresh position and move budget.
|
| 255 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 256 |
- **The grader trusts the maze service.** The agent reaches it only through `maze look` and
|
| 257 |
`maze move` (an internal network, two routes, bodies up to 4 KiB); an agent that could reach
|
| 258 |
the service any other way could forge its record. The service runs without capabilities, with
|
| 259 |
a pids and memory limit, so flooding it only hurts the agent's own maze.
|
| 260 |
+
- **The move log's `agent`** identifies the Trial's compose project.
|
| 261 |
+
|
| 262 |
- **Not the paper's setup:** a per-agent move budget instead of a token allowance (looking and
|
| 263 |
refused moves are free), a message board instead of `message`/`read_messages` tools with
|
| 264 |
+
notifications, the moves left in every
|
| 265 |
observation, and N = 1 is a solo control.
|
budget.py
CHANGED
|
@@ -3,7 +3,7 @@
|
|
| 3 |
|
| 4 |
Simulates searches on the 32 trees in tasks/ with the maze service's own engine
|
| 5 |
(template/environment/maze/engine.py: every move goes through engine.Walk, which refuses what
|
| 6 |
-
the service refuses), without
|
| 7 |
by team size N and per-agent move budget, as the Markdown table in README.md:
|
| 8 |
|
| 9 |
- (a) one agent, depth-first: it takes the first door it hasn't been through, in the order the
|
|
|
|
| 3 |
|
| 4 |
Simulates searches on the 32 trees in tasks/ with the maze service's own engine
|
| 5 |
(template/environment/maze/engine.py: every move goes through engine.Walk, which refuses what
|
| 6 |
+
the service refuses), without containers, and prints the success rate of each strategy
|
| 7 |
by team size N and per-agent move budget, as the Markdown table in README.md:
|
| 8 |
|
| 9 |
- (a) one agent, depth-first: it takes the first door it hasn't been through, in the order the
|
check.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
# /// script
|
| 2 |
# requires-python = ">=3.12"
|
| 3 |
-
# dependencies = ["harbor==0.25.0"
|
| 4 |
# ///
|
| 5 |
"""s3-maze's checks that need no model (huggingface/legion#115, section 5):
|
| 6 |
|
|
@@ -27,7 +27,7 @@
|
|
| 27 |
no answer names a room other than the current one and its doors (or what the agent asked
|
| 28 |
for); the exit is named only once the agent stands in it. The move log has one record per
|
| 29 |
move request, refused ones included, each with agent, from, to and time, and its accepted
|
| 30 |
-
moves are the walk. success.py
|
| 31 |
and true after, and false for a missing or linked state file; export.py writes the service's
|
| 32 |
record for the grader; a restarted service resumes the walk. The `maze` command prints the
|
| 33 |
service's JSON and exits 0, 1 for a refused move, 2 for a usage error.
|
|
@@ -48,16 +48,8 @@
|
|
| 48 |
Dockerfile and the `maze` command, and names no room; nor do the instruction, task.toml or
|
| 49 |
the compose file; the exit is named only in environment/maze/tree.json, tests/expected.json
|
| 50 |
and solution/solve.sh; and no folder beside tasks/ holds a tree.
|
| 51 |
-
5.
|
| 52 |
-
|
| 53 |
-
maze-t01 and its team four agents; `run.env` (over `cluster.env`) sets another tree and team
|
| 54 |
-
size, also with comments after quoted and unquoted values (read as legion reads them); a team
|
| 55 |
-
with one agent's results gone keeps that agent and flags its reward and move
|
| 56 |
-
log as missing; and the row flags Trials of another task than the spec selects (a `run.env`
|
| 57 |
-
gone) and of an agent the spec didn't plan, and a winning move log whose last line was cut
|
| 58 |
-
off.
|
| 59 |
-
6. Trials (`--env`), on maze-t01, with agents that need no model:
|
| 60 |
-
- a walker checks legion's success_check in the maze service (false), walks the shortest path
|
| 61 |
with `maze move`, checks it again (true), and scores 1; the verifier's folder then holds
|
| 62 |
the move log and the export;
|
| 63 |
- Harbor's oracle agent (solution/solve.sh) scores 1;
|
|
@@ -92,9 +84,7 @@ HERE = Path(__file__).resolve().parent
|
|
| 92 |
sys.dont_write_bytecode = True # nothing new in tasks/ or template/
|
| 93 |
sys.path.insert(0, str(HERE))
|
| 94 |
sys.path.insert(0, str(HERE / "template" / "environment" / "maze"))
|
| 95 |
-
sys.path.insert(0, str(HERE / "eval"))
|
| 96 |
import generate as g # noqa: E402
|
| 97 |
-
import metrics # noqa: E402
|
| 98 |
from engine import Maze, Walk # noqa: E402
|
| 99 |
|
| 100 |
LABEL = re.compile(rf"R\d{{{g.DIGITS}}}")
|
|
@@ -681,108 +671,13 @@ def check_files() -> None:
|
|
| 681 |
check(holders == {"environment/maze/tree.json", "tests/expected.json",
|
| 682 |
"solution/solve.sh"}, f"{task.name}: the exit is named in {holders}")
|
| 683 |
beside = {p.name for p in HERE.iterdir() if p.is_dir()} - {
|
| 684 |
-
"tasks", "template", "
|
| 685 |
check(not beside, f"folders beside tasks/: {sorted(beside)}")
|
| 686 |
check(not LABEL.search("".join(p.read_text(errors="ignore")
|
| 687 |
for p in (HERE / "template").rglob("*") if p.is_file())),
|
| 688 |
"template/ names a room")
|
| 689 |
|
| 690 |
|
| 691 |
-
# ------------------------------------------------------------------ metrics
|
| 692 |
-
|
| 693 |
-
# The example spec's lines that metrics.py reads (Legion's experiments/s3-maze/spec.yaml)
|
| 694 |
-
RUN_SPEC = """name: ${RUN_NAME:-s3-maze}
|
| 695 |
-
naming: consecutive-id
|
| 696 |
-
task:
|
| 697 |
-
repo: https://huggingface.co/datasets/HuggingFaceSwarms/s3-maze
|
| 698 |
-
selector: ${TREE:-maze-t01}
|
| 699 |
-
revision: REVISION
|
| 700 |
-
agents:
|
| 701 |
-
count: ${N:-4}
|
| 702 |
-
"""
|
| 703 |
-
|
| 704 |
-
|
| 705 |
-
def run_dir(root: Path, work: Path, tree: str, walks: dict[str, bool],
|
| 706 |
-
env_files: dict[str, str]) -> Path:
|
| 707 |
-
"""A Slurm run's directory, as `legion init` and the workers leave it: the spec, the env
|
| 708 |
-
files and, per agent in `walks`, one Trial of `tree` (the exit reached or not) graded by the
|
| 709 |
-
task's own grader on the maze service's own export."""
|
| 710 |
-
task = HERE / "tasks" / tree
|
| 711 |
-
layout = tree_of(task)
|
| 712 |
-
(root / "experiment").mkdir(parents=True)
|
| 713 |
-
(root / "experiment" / "spec.yaml").write_text(RUN_SPEC)
|
| 714 |
-
for name, text in env_files.items():
|
| 715 |
-
(root / name).write_text(text)
|
| 716 |
-
for k, (agent, wins) in enumerate(walks.items()):
|
| 717 |
-
rooms = g.shortest_path(layout) if wins else dead_end_walk(layout, 20)
|
| 718 |
-
source = evidence(task, work, f"{root.name}-{agent}", rooms)
|
| 719 |
-
trial = root / "results" / "s3-maze" / agent / "trials" / f"s3-maze-{agent}-t1"
|
| 720 |
-
env = {**os.environ, "EVIDENCE_DIR": str(source), "VERIFIER_DIR": str(trial / "verifier")}
|
| 721 |
-
subprocess.run(["bash", str(task / "tests" / "test.sh")], env=env, capture_output=True,
|
| 722 |
-
timeout=60, check=True)
|
| 723 |
-
reward = float((trial / "verifier" / "reward.txt").read_text())
|
| 724 |
-
(trial / "result.json").write_text(json.dumps({
|
| 725 |
-
"task_name": f"HuggingFaceSwarms/{tree}", "trial_name": trial.name,
|
| 726 |
-
"started_at": f"2026-11-17T11:38:1{k}+00:00",
|
| 727 |
-
"finished_at": "2026-11-17T11:50:04+00:00",
|
| 728 |
-
"agent_result": {"n_input_tokens": 1000, "n_cache_tokens": 800, "n_output_tokens": 50},
|
| 729 |
-
"verifier_result": {"rewards": {"reward": reward}}}))
|
| 730 |
-
return root
|
| 731 |
-
|
| 732 |
-
|
| 733 |
-
def check_metrics(work: Path) -> int:
|
| 734 |
-
team4 = {f"agent-{k:03d}": k == 3 for k in range(1, 5)}
|
| 735 |
-
cases = { # name: (tree, walks, env files, task, agents, missing besides the board export)
|
| 736 |
-
"defaults": ("maze-t01", team4, {}, "maze-t01", 4, []),
|
| 737 |
-
"run.env": ("maze-t02", {"agent-001": True, "agent-002": False},
|
| 738 |
-
{"cluster.env": "N=3\nTREE=maze-t05\n",
|
| 739 |
-
"run.env": "#TREE=maze-t01\nTREE=maze-t02\nN=2\nRUN_NAME=s3-maze-b\n"},
|
| 740 |
-
"maze-t02", 2, []),
|
| 741 |
-
# comments after values, read as legion's read_env_file does: a quoted value ends at
|
| 742 |
-
# its quote, an unquoted one at ` #`
|
| 743 |
-
"comments in env files": ("maze-t02", {"agent-001": True, "agent-002": False},
|
| 744 |
-
{"cluster.env": "export N=3 # three\nTREE=maze-t05 # five\n",
|
| 745 |
-
"run.env": "TREE=\"maze-t02\" # group\nN=2 # pair\n"
|
| 746 |
-
"RUN_NAME='s3-maze-c' # name\n"},
|
| 747 |
-
"maze-t02", 2, []),
|
| 748 |
-
"an agent's results gone": ("maze-t01", {a: w for a, w in team4.items()
|
| 749 |
-
if a != "agent-004"}, {}, "maze-t01", 4,
|
| 750 |
-
["reward: agent-004", "move log: agent-004"]),
|
| 751 |
-
"run.env gone": ("maze-t02", {"agent-001": True, "agent-002": False}, {}, "maze-t01", 4,
|
| 752 |
-
["task: the spec selects 'maze-t01', the Trials ran maze-t02",
|
| 753 |
-
"reward: agent-003", "reward: agent-004", "move log: agent-003",
|
| 754 |
-
"move log: agent-004"]),
|
| 755 |
-
"an unplanned agent": ("maze-t01", {"agent-001": True, "agent-002": False,
|
| 756 |
-
"agent-003": False}, {"run.env": "N=2\n"},
|
| 757 |
-
"maze-t01", 2,
|
| 758 |
-
["agents: Trials of agents the spec didn't plan: agent-003"]),
|
| 759 |
-
}
|
| 760 |
-
for case, (tree, walks, env_files, task, agents, missing) in cases.items():
|
| 761 |
-
name = "run-" + re.sub(r"\W+", "-", case)
|
| 762 |
-
r = metrics.row(run_dir(work / name, work, tree, walks, env_files))
|
| 763 |
-
expected_rewards = {a: float(w) for a, w in walks.items() if a in r["rewards"]}
|
| 764 |
-
check(r["task"] == task and r["agents"] == agents and len(r["rewards"]) == agents,
|
| 765 |
-
f"metrics, {case}: task {r['task']!r}, {r['agents']} agents, not {task!r}, {agents}")
|
| 766 |
-
check(sorted(r["missing"]) == sorted(missing + ["board export"]),
|
| 767 |
-
f"metrics, {case}: missing {r['missing']}")
|
| 768 |
-
check({a: v for a, v in r["rewards"].items() if v is not None} == expected_rewards
|
| 769 |
-
and r["success"] is any(expected_rewards.values()),
|
| 770 |
-
f"metrics, {case}: rewards {r['rewards']}")
|
| 771 |
-
moved = {a: 30 if w else 20 for a, w in walks.items() if a in r["rewards"]}
|
| 772 |
-
check({a: n for a, n in r["moves"].items() if a in moved} == moved,
|
| 773 |
-
f"metrics, {case}: moves {r['moves']}")
|
| 774 |
-
# a winning move log whose last line was cut off (a Trial stopped mid-write): its moves and
|
| 775 |
-
# its exit are unknown, so the row flags it as missing rather than counting 29 moves
|
| 776 |
-
root = run_dir(work / "run-a-cut-off-move-log", work, "maze-t01",
|
| 777 |
-
{"agent-001": True, "agent-002": False}, {"run.env": "N=2\n"})
|
| 778 |
-
log = root / "results/s3-maze/agent-001/trials/s3-maze-agent-001-t1/verifier/moves.jsonl"
|
| 779 |
-
log.write_text(log.read_text().rstrip("\n")[:-20])
|
| 780 |
-
r = metrics.row(root)
|
| 781 |
-
check(any(m.startswith("move log: agent-001 (line 30 of 30 unreadable)") for m in r["missing"]),
|
| 782 |
-
f"metrics, a cut-off move log: missing {r['missing']}")
|
| 783 |
-
return len(cases) + 1
|
| 784 |
-
|
| 785 |
-
|
| 786 |
# ------------------------------------------------------------------ Trials
|
| 787 |
|
| 788 |
# Runs in the agent's container as `python3 -c PROBE_PY <base64 config>`; its config travels
|
|
@@ -1029,15 +924,12 @@ def main() -> int:
|
|
| 1029 |
before = len(failures)
|
| 1030 |
check_files()
|
| 1031 |
print(f"4. no-cheat (files): {len(failures) - before} failures")
|
| 1032 |
-
before = len(failures)
|
| 1033 |
-
cases = check_metrics(work)
|
| 1034 |
-
print(f"5. metrics: {len(failures) - before} failures; {cases} run directories")
|
| 1035 |
if args.env != "none":
|
| 1036 |
before = len(failures)
|
| 1037 |
jobs = args.jobs_dir or work / "jobs"
|
| 1038 |
jobs.mkdir(parents=True, exist_ok=True)
|
| 1039 |
report = asyncio.run(check_trials(args.env, jobs, work))
|
| 1040 |
-
print(f"
|
| 1041 |
f"{json.dumps(report)}")
|
| 1042 |
for failure in failures:
|
| 1043 |
print("FAIL:", failure)
|
|
|
|
| 1 |
# /// script
|
| 2 |
# requires-python = ">=3.12"
|
| 3 |
+
# dependencies = ["harbor==0.25.0"]
|
| 4 |
# ///
|
| 5 |
"""s3-maze's checks that need no model (huggingface/legion#115, section 5):
|
| 6 |
|
|
|
|
| 27 |
no answer names a room other than the current one and its doors (or what the agent asked
|
| 28 |
for); the exit is named only once the agent stands in it. The move log has one record per
|
| 29 |
move request, refused ones included, each with agent, from, to and time, and its accepted
|
| 30 |
+
moves are the walk. success.py says false until the exit is reached
|
| 31 |
and true after, and false for a missing or linked state file; export.py writes the service's
|
| 32 |
record for the grader; a restarted service resumes the walk. The `maze` command prints the
|
| 33 |
service's JSON and exits 0, 1 for a refused move, 2 for a usage error.
|
|
|
|
| 48 |
Dockerfile and the `maze` command, and names no room; nor do the instruction, task.toml or
|
| 49 |
the compose file; the exit is named only in environment/maze/tree.json, tests/expected.json
|
| 50 |
and solution/solve.sh; and no folder beside tasks/ holds a tree.
|
| 51 |
+
5. Trials (`--env`), on maze-t01, with agents that need no model:
|
| 52 |
+
- a walker checks success.py in the maze service (false), walks the shortest path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
with `maze move`, checks it again (true), and scores 1; the verifier's folder then holds
|
| 54 |
the move log and the export;
|
| 55 |
- Harbor's oracle agent (solution/solve.sh) scores 1;
|
|
|
|
| 84 |
sys.dont_write_bytecode = True # nothing new in tasks/ or template/
|
| 85 |
sys.path.insert(0, str(HERE))
|
| 86 |
sys.path.insert(0, str(HERE / "template" / "environment" / "maze"))
|
|
|
|
| 87 |
import generate as g # noqa: E402
|
|
|
|
| 88 |
from engine import Maze, Walk # noqa: E402
|
| 89 |
|
| 90 |
LABEL = re.compile(rf"R\d{{{g.DIGITS}}}")
|
|
|
|
| 671 |
check(holders == {"environment/maze/tree.json", "tests/expected.json",
|
| 672 |
"solution/solve.sh"}, f"{task.name}: the exit is named in {holders}")
|
| 673 |
beside = {p.name for p in HERE.iterdir() if p.is_dir()} - {
|
| 674 |
+
"tasks", "template", ".cache", "__pycache__", ".git"}
|
| 675 |
check(not beside, f"folders beside tasks/: {sorted(beside)}")
|
| 676 |
check(not LABEL.search("".join(p.read_text(errors="ignore")
|
| 677 |
for p in (HERE / "template").rglob("*") if p.is_file())),
|
| 678 |
"template/ names a room")
|
| 679 |
|
| 680 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 681 |
# ------------------------------------------------------------------ Trials
|
| 682 |
|
| 683 |
# Runs in the agent's container as `python3 -c PROBE_PY <base64 config>`; its config travels
|
|
|
|
| 924 |
before = len(failures)
|
| 925 |
check_files()
|
| 926 |
print(f"4. no-cheat (files): {len(failures) - before} failures")
|
|
|
|
|
|
|
|
|
|
| 927 |
if args.env != "none":
|
| 928 |
before = len(failures)
|
| 929 |
jobs = args.jobs_dir or work / "jobs"
|
| 930 |
jobs.mkdir(parents=True, exist_ok=True)
|
| 931 |
report = asyncio.run(check_trials(args.env, jobs, work))
|
| 932 |
+
print(f"5. Trials on {args.env} ({PROBE_TASK}): {len(failures) - before} failures; "
|
| 933 |
f"{json.dumps(report)}")
|
| 934 |
for failure in failures:
|
| 935 |
print("FAIL:", failure)
|
eval/metrics.py
DELETED
|
@@ -1,404 +0,0 @@
|
|
| 1 |
-
"""One row per team from s³ runs (huggingface/legion#115): `uv run eval/metrics.py
|
| 2 |
-
RUN_DIR [RUN_DIR ...] [--out rows.jsonl]`.
|
| 3 |
-
|
| 4 |
-
s3-aggregation's eval/metrics.py, with s3-maze's move-log metrics added (`maze_moves` in
|
| 5 |
-
EXTRAS). A run directory is one team: a local run's bundle (`.legion/<swarm>-<time>/`,
|
| 6 |
-
docs/local.md), or a Slurm run's directory (`legion init`'s RUN_DIR, docs/slurm.md), where the
|
| 7 |
-
workers copy what a run is graded on into `results/`. Under either, each agent's Trials
|
| 8 |
-
(`<agent>/trials/<swarm>-<agent>-tN/`: Harbor's `result.json` and `verifier/`) and the board
|
| 9 |
-
export (`resources/message_board/{board.jsonl,channels.json}`) are found anywhere. Each row (one
|
| 10 |
-
JSON line; README.md has every field):
|
| 11 |
-
- the task and team size, how the run ended, and `success`: any agent's reward is 1;
|
| 12 |
-
- per agent: its reward (its latest Trial with a verifier result), tokens and board posts;
|
| 13 |
-
- the message graph: an edge from a sender to each teammate it mentions (`@agent-002`; a group
|
| 14 |
-
mention such as `@all` names every member) or messages directly (a DM or a private channel of
|
| 15 |
-
the two), with in-degree centralization and reciprocity as in the s³ paper's Appendix M. A
|
| 16 |
-
post that mentions no one adds no edge;
|
| 17 |
-
- for the maze: each agent's moves, the rooms it visited and the team's room overlap, from the
|
| 18 |
-
move logs the grader keeps in each Trial's `verifier/`;
|
| 19 |
-
- `missing`: what the run directory lacks (an agent's reward or move log, the board export) or
|
| 20 |
-
where its spec and its Trials disagree, so a row never passes for complete when it is not.
|
| 21 |
-
|
| 22 |
-
A reward and a move log count only from a Trial whose `result.json` holds Harbor's verifier
|
| 23 |
-
result: the agent's container can write into `verifier/` while it works, and only the
|
| 24 |
-
verifier's run replaces what is there.
|
| 25 |
-
|
| 26 |
-
A local run's `run.json` gives the spec, the agents, their tokens (summed over models), the
|
| 27 |
-
cost and how the run ended. A Slurm run has no such bundle: the task and the roster come from
|
| 28 |
-
its `experiment/spec.yaml` as the run resolved it (its `${VAR}`s from `cluster.env` and
|
| 29 |
-
`run.env`, else their defaults), each agent's tokens from its Trials' results (no reasoning
|
| 30 |
-
split), and the run's span from its Trials. Every agent the spec planned has a row entry, so
|
| 31 |
-
one without results shows in `missing`; so do Trials of an unplanned agent or of another task
|
| 32 |
-
than the spec selects (e.g. a run directory whose `run.env` is gone, read with the defaults).
|
| 33 |
-
The board may hold earlier runs' messages (a reused Space): only those posted within the run's
|
| 34 |
-
span count.
|
| 35 |
-
"""
|
| 36 |
-
|
| 37 |
-
import argparse
|
| 38 |
-
import fnmatch
|
| 39 |
-
import json
|
| 40 |
-
import re
|
| 41 |
-
import sys
|
| 42 |
-
from collections import Counter
|
| 43 |
-
from collections.abc import Callable
|
| 44 |
-
from datetime import datetime
|
| 45 |
-
from pathlib import Path
|
| 46 |
-
|
| 47 |
-
import yaml
|
| 48 |
-
|
| 49 |
-
TOKEN_FIELDS = ("input", "output", "cache_read", "cache_write", "reasoning")
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
def load_json(path: Path):
|
| 53 |
-
return json.loads(path.read_text(encoding="utf-8"))
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
def epoch(value) -> float:
|
| 57 |
-
return float(value) if isinstance(value, int | float) else datetime.fromisoformat(
|
| 58 |
-
value).timestamp()
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
def bundle(run_dir: Path) -> dict | None:
|
| 62 |
-
"""A local run's run.json; None for a Slurm run (its controller's run.json, in the bucket,
|
| 63 |
-
holds neither the spec nor the agents)."""
|
| 64 |
-
path = run_dir / "run.json"
|
| 65 |
-
doc = load_json(path) if path.is_file() else {}
|
| 66 |
-
return doc if "spec" in doc and "agents" in doc else None
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
def all_trials(run_dir: Path) -> dict[str, list[Path]]:
|
| 70 |
-
"""Each agent's Trial directories, oldest first: `<agent>/trials/<swarm>-<agent>-t<N>/`
|
| 71 |
-
(a local run's agents/_harbor/, a Slurm run's results/<swarm>/), one per Trial name."""
|
| 72 |
-
found: dict[str, dict[str, tuple[int, Path]]] = {}
|
| 73 |
-
for trial in run_dir.rglob("trials/*"):
|
| 74 |
-
agent = trial.parent.parent.name
|
| 75 |
-
m = re.fullmatch(rf"(?:.+-)?{re.escape(agent)}-t(\d+)", trial.name)
|
| 76 |
-
if m and trial.is_dir():
|
| 77 |
-
found.setdefault(agent, {}).setdefault(trial.name, (int(m[1]), trial))
|
| 78 |
-
return {a: [p for _, p in sorted(t.values())] for a, t in sorted(found.items())}
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
def results(trials: list[Path]) -> list[dict]:
|
| 82 |
-
return [load_json(t / "result.json") for t in trials if (t / "result.json").is_file()]
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
def verified(trial: Path) -> dict | None:
|
| 86 |
-
"""Harbor's verifier rewards for a Trial, or None when its verifier didn't run."""
|
| 87 |
-
result = trial / "result.json"
|
| 88 |
-
if not result.is_file() or result.is_symlink():
|
| 89 |
-
return None
|
| 90 |
-
return (load_json(result).get("verifier_result") or {}).get("rewards") or None
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
def reward(trials: list[Path]) -> float | None:
|
| 94 |
-
"""The reward of the agent's latest Trial that has one."""
|
| 95 |
-
for trial in reversed(trials):
|
| 96 |
-
rewards = verified(trial)
|
| 97 |
-
if rewards and "reward" in rewards:
|
| 98 |
-
return float(rewards["reward"])
|
| 99 |
-
return None
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
def bundle_tokens(agent: dict) -> dict[str, int]:
|
| 103 |
-
usage = dict.fromkeys(TOKEN_FIELDS, 0)
|
| 104 |
-
for by_model in (agent.get("tokens") or {}).values():
|
| 105 |
-
for key in TOKEN_FIELDS:
|
| 106 |
-
usage[key] += int(by_model.get(key) or 0)
|
| 107 |
-
return usage
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
def trial_tokens(trials: list[Path]) -> dict[str, int]:
|
| 111 |
-
"""Harbor's counts: its input includes the cached tokens."""
|
| 112 |
-
usage = dict.fromkeys(TOKEN_FIELDS, 0)
|
| 113 |
-
for result in results(trials):
|
| 114 |
-
agent = result.get("agent_result") or {}
|
| 115 |
-
cached = int(agent.get("n_cache_tokens") or 0)
|
| 116 |
-
usage["input"] += int(agent.get("n_input_tokens") or 0) - cached
|
| 117 |
-
usage["cache_read"] += cached
|
| 118 |
-
usage["output"] += int(agent.get("n_output_tokens") or 0)
|
| 119 |
-
return usage
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
def board(run_dir: Path, start: float, end: float) -> tuple[list[dict], dict[int, dict], bool]:
|
| 123 |
-
"""(the run's messages, oldest first, channels by id, whether an export was found)."""
|
| 124 |
-
messages, channels, found = {}, {}, False
|
| 125 |
-
for export in run_dir.rglob("resources/message_board/board.jsonl"):
|
| 126 |
-
found = True
|
| 127 |
-
listing = export.with_name("channels.json")
|
| 128 |
-
for channel in load_json(listing) if listing.is_file() else []:
|
| 129 |
-
channels[channel["id"]] = channel
|
| 130 |
-
for line in export.read_text(encoding="utf-8").splitlines():
|
| 131 |
-
if line.strip():
|
| 132 |
-
record = json.loads(line)
|
| 133 |
-
message = record["message"] | {"channel_id": record["channel_id"]}
|
| 134 |
-
if start <= epoch(message["created_at"]) <= end:
|
| 135 |
-
messages[message["id"]] = message
|
| 136 |
-
return sorted(messages.values(), key=lambda m: m["id"]), channels, found
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
def sender(message: dict) -> str | None:
|
| 140 |
-
return (message.get("sender") or {}).get("external_id")
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
def edges(messages: list[dict], channels: dict[int, dict], team: list[str]) -> set[tuple]:
|
| 144 |
-
"""(sender, receiver) for each teammate a message mentions or is sent to directly."""
|
| 145 |
-
members = set(team)
|
| 146 |
-
out = set()
|
| 147 |
-
for message in messages:
|
| 148 |
-
source = sender(message)
|
| 149 |
-
if source not in members:
|
| 150 |
-
continue
|
| 151 |
-
targets = {m.get("external_id") for m in message.get("mentions") or []}
|
| 152 |
-
channel = channels.get(message["channel_id"]) or {}
|
| 153 |
-
if channel.get("kind") in ("dm", "private"):
|
| 154 |
-
inside = {m.get("external_id") for m in channel.get("members") or []} & members
|
| 155 |
-
if len(inside) == 2 and source in inside: # a DM, or a private channel of the two
|
| 156 |
-
targets |= inside
|
| 157 |
-
out |= {(source, target) for target in targets & members if target != source}
|
| 158 |
-
return out
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
def centralization(graph: set[tuple], team: list[str]) -> float | None:
|
| 162 |
-
"""Appendix M: sum over agents of (k* - k_j) / (N - 1)^2, k_j agent j's in-degree and k*
|
| 163 |
-
the largest: 0 when everyone receives from as many teammates, 1 when one agent receives
|
| 164 |
-
from everyone and no one else from anyone. None for a team of one."""
|
| 165 |
-
n = len(team)
|
| 166 |
-
if n < 2:
|
| 167 |
-
return None
|
| 168 |
-
degree = Counter(target for _, target in graph)
|
| 169 |
-
k = [degree[a] for a in team]
|
| 170 |
-
return sum(max(k) - kj for kj in k) / (n - 1) ** 2
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
def reciprocity(graph: set[tuple]) -> float | None:
|
| 174 |
-
"""Appendix M: the fraction of edges whose reverse edge exists. None without edges."""
|
| 175 |
-
return sum((b, a) in graph for a, b in graph) / len(graph) if graph else None
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
def maze_moves(run_dir: Path, team: list[str], trials: dict[str, list[Path]]) -> dict:
|
| 179 |
-
"""s3-maze: from each agent's move logs (`verifier/moves.jsonl`, with the export's
|
| 180 |
-
`final.json` for its start room), its accepted and refused moves, the rooms it visited
|
| 181 |
-
(R_i: the start and every room it moved into, over all its Trials) and whether it reached
|
| 182 |
-
the exit; and the team's room overlap, Appendix M's (V - U) / V with V = sum_i (|R_i| - 1)
|
| 183 |
-
and U = |union of the R_i| - 1: 0 when no two agents visit the same room, near 1 when all
|
| 184 |
-
walk the same path; None when no agent moved. And the first exit: which agent reached it,
|
| 185 |
-
how long after the team's Trials started (the earliest `started_at`), with how many moves of
|
| 186 |
-
its own, and how many moves the whole team had made by then (`first_exit`, None when no
|
| 187 |
-
agent got out). Empty for a run without move logs (not a maze)."""
|
| 188 |
-
per_agent, union, missing, any_log = {}, set(), [], False
|
| 189 |
-
accepted, exits = [], [] # (time, agent) of every accepted move; (time, agent, its moves)
|
| 190 |
-
for name in team:
|
| 191 |
-
rooms, moves, refused, reached, logs = set(), 0, 0, False, 0
|
| 192 |
-
for trial in trials.get(name, []):
|
| 193 |
-
log, final = trial / "verifier" / "moves.jsonl", trial / "verifier" / "final.json"
|
| 194 |
-
if verified(trial) is None or not log.is_file() or log.is_symlink():
|
| 195 |
-
continue
|
| 196 |
-
logs += 1
|
| 197 |
-
export = {}
|
| 198 |
-
if final.is_file() and not final.is_symlink():
|
| 199 |
-
export = load_json(final)
|
| 200 |
-
rooms.add(export.get("start"))
|
| 201 |
-
reached |= export.get("reached") is True
|
| 202 |
-
last, own = None, 0
|
| 203 |
-
lines = log.read_text(encoding="utf-8").splitlines()
|
| 204 |
-
for i, line in enumerate(lines):
|
| 205 |
-
try:
|
| 206 |
-
record = json.loads(line) if line.strip() else {}
|
| 207 |
-
except ValueError: # e.g. cut off when the Trial stopped mid-write: the moves
|
| 208 |
-
# (or the exit) after it are unknown, so the run doesn't count
|
| 209 |
-
missing.append(f"move log: {name} (line {i + 1} of {len(lines)} unreadable)")
|
| 210 |
-
continue
|
| 211 |
-
if record.get("ok") is True:
|
| 212 |
-
moves += 1
|
| 213 |
-
own += 1
|
| 214 |
-
rooms |= {record["from"], record["to"]}
|
| 215 |
-
last = (epoch(record["time"]), record["to"])
|
| 216 |
-
accepted.append((last[0], name))
|
| 217 |
-
elif record:
|
| 218 |
-
refused += 1
|
| 219 |
-
if export.get("reached") is True and last and last[1] == export.get("room"):
|
| 220 |
-
exits.append((last[0], name, own))
|
| 221 |
-
rooms.discard(None)
|
| 222 |
-
any_log |= logs > 0
|
| 223 |
-
if not logs:
|
| 224 |
-
missing.append(f"move log: {name}")
|
| 225 |
-
per_agent[name] = {"moves": moves, "refused": refused, "rooms": len(rooms),
|
| 226 |
-
"reached_exit": reached}
|
| 227 |
-
union |= rooms
|
| 228 |
-
if not any_log:
|
| 229 |
-
return {}
|
| 230 |
-
v = sum(max(a["rooms"] - 1, 0) for a in per_agent.values())
|
| 231 |
-
first_exit = None
|
| 232 |
-
if exits:
|
| 233 |
-
at, who, own = min(exits)
|
| 234 |
-
started = [epoch(r["started_at"]) for ts in trials.values() for r in results(ts)
|
| 235 |
-
if r.get("started_at")]
|
| 236 |
-
first_exit = {"agent": who, "agent_moves": own,
|
| 237 |
-
"team_moves": sum(1 for t, _ in accepted if t <= at),
|
| 238 |
-
"after_s": round(at - min(started), 1) if started else None}
|
| 239 |
-
return {"moves": {n: a["moves"] for n, a in per_agent.items()},
|
| 240 |
-
"first_exit": first_exit,
|
| 241 |
-
"refused_moves": {n: a["refused"] for n, a in per_agent.items()},
|
| 242 |
-
"rooms": {n: a["rooms"] for n, a in per_agent.items()},
|
| 243 |
-
"rooms_union": len(union),
|
| 244 |
-
"room_overlap": (v - (len(union) - 1)) / v if v else None,
|
| 245 |
-
"exit_reached_by": [n for n, a in per_agent.items() if a["reached_exit"]],
|
| 246 |
-
"missing_moves": missing}
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
# Per-environment metrics: f(run_dir, team, Trial dirs by agent) -> extra row fields.
|
| 250 |
-
EXTRAS: list[Callable[[Path, list[str], dict[str, list[Path]]], dict]] = [maze_moves]
|
| 251 |
-
|
| 252 |
-
|
| 253 |
-
def local_run(run: dict) -> dict:
|
| 254 |
-
"""What a local bundle says about the run."""
|
| 255 |
-
harbor = next((t.get("harbor") or {} for t in run["spec"]["types"].values()), {})
|
| 256 |
-
task = (harbor.get("config") or {}).get("task") or {}
|
| 257 |
-
agents = sorted(run["agents"], key=lambda a: a["name"])
|
| 258 |
-
return {"swarm": run.get("swarm"), "task": task, "team": [a["name"] for a in agents],
|
| 259 |
-
"start": epoch(run["started_at"]), "end": epoch(run["ended_at"]),
|
| 260 |
-
"stop_reason": run.get("stop_reason"), "duration_s": run.get("duration_s"),
|
| 261 |
-
"cost_usd": (run.get("totals") or {}).get("cost_usd"),
|
| 262 |
-
"tokens": {a["name"]: bundle_tokens(a) for a in agents},
|
| 263 |
-
"turns": {a["name"]: a.get("turns_completed") for a in agents}}
|
| 264 |
-
|
| 265 |
-
|
| 266 |
-
PLACEHOLDER = re.compile(r"\$\{([A-Z_][A-Z0-9_]*)(?::-([^}]*))?\}")
|
| 267 |
-
|
| 268 |
-
|
| 269 |
-
def env_value(raw: str) -> str:
|
| 270 |
-
"""A `NAME=value` line's value as Legion reads it (specrender.read_env_file): a quoted value
|
| 271 |
-
ends at its closing quote (what follows is a comment), an unquoted one at ` #`."""
|
| 272 |
-
value = raw.strip()
|
| 273 |
-
if value and value[0] in "'\"" and (end := value.find(value[0], 1)) > 0:
|
| 274 |
-
return value[1:end]
|
| 275 |
-
return re.split(r"\s+#", raw, maxsplit=1)[0].strip()
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
def run_values(run_dir: Path) -> dict[str, str]:
|
| 279 |
-
"""The run's `cluster.env` then `run.env` (later wins), as the jobs read them: what fills
|
| 280 |
-
the spec's `${VAR}`s. Lines Legion would refuse (no `=`, a bad name) are skipped."""
|
| 281 |
-
values = {}
|
| 282 |
-
for name in ("cluster.env", "run.env"):
|
| 283 |
-
path = run_dir / name
|
| 284 |
-
for line in path.read_text().splitlines() if path.is_file() else []:
|
| 285 |
-
line = line.strip()
|
| 286 |
-
if not line or line.startswith("#"):
|
| 287 |
-
continue
|
| 288 |
-
key, sep, raw = line.removeprefix("export ").partition("=")
|
| 289 |
-
if sep and re.fullmatch(r"[A-Za-z_][A-Za-z0-9_]*", key.strip()):
|
| 290 |
-
values[key.strip()] = env_value(raw)
|
| 291 |
-
return values
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
def expand(text: str, values: dict[str, str]) -> str:
|
| 295 |
-
"""`${VAR}` and `${VAR:-default}` in the spec's text, as Legion fills them (empty = unset)."""
|
| 296 |
-
return PLACEHOLDER.sub(lambda m: values.get(m[1]) or (m[2] if m[2] is not None else m[0]),
|
| 297 |
-
text)
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
def slurm_run(run_dir: Path, trials: dict[str, list[Path]]) -> dict:
|
| 301 |
-
"""What a Slurm run's directory says: its spec as the run resolved it (`legion init`'s copy
|
| 302 |
-
of the experiment, its `${VAR}`s filled from `cluster.env` then `run.env`, else their
|
| 303 |
-
defaults) and the Trials the workers kept. The spec gives the task and the roster: every
|
| 304 |
-
agent it planned is in the row, so one whose results are missing is flagged, not dropped.
|
| 305 |
-
`problems` says where the spec and the Trials disagree (e.g. a `run.env` that is gone, its
|
| 306 |
-
values replaced by the defaults)."""
|
| 307 |
-
path = run_dir / "experiment" / "spec.yaml"
|
| 308 |
-
spec = (yaml.safe_load(expand(path.read_text(), run_values(run_dir)))
|
| 309 |
-
if path.is_file() else None) or {}
|
| 310 |
-
problems = [] if spec else ["spec: no experiment/spec.yaml"]
|
| 311 |
-
agents = spec.get("agents") or {}
|
| 312 |
-
count = agents.get("count") if type(agents.get("count")) is int else None
|
| 313 |
-
if spec and count is None:
|
| 314 |
-
problems.append(f"spec: agents.count is {agents.get('count')!r}, not a number")
|
| 315 |
-
if spec.get("naming") == "consecutive-id" and count is not None:
|
| 316 |
-
team = [f"agent-{k:03d}" for k in range(1, count + 1)]
|
| 317 |
-
else:
|
| 318 |
-
team = list(trials)
|
| 319 |
-
if count is not None and len(team) < count:
|
| 320 |
-
problems.append(f"agents: {len(team)} of the {count} planned have Trials")
|
| 321 |
-
if outside := sorted(set(trials) - set(team)):
|
| 322 |
-
problems.append(f"agents: Trials of agents the spec didn't plan: {', '.join(outside)}")
|
| 323 |
-
times = [(epoch(r["started_at"]), epoch(r["finished_at"]))
|
| 324 |
-
for ts in trials.values() for r in results(ts)
|
| 325 |
-
if r.get("started_at") and r.get("finished_at")]
|
| 326 |
-
start, end = (min(t[0] for t in times), max(t[1] for t in times)) if times else (0, 0)
|
| 327 |
-
ran = sorted({r["task_name"].split("/")[-1] for ts in trials.values() for r in results(ts)
|
| 328 |
-
if r.get("task_name")})
|
| 329 |
-
task = spec.get("task") or {"selector": ran[0] if len(ran) == 1 else None}
|
| 330 |
-
selector = task.get("selector") or ""
|
| 331 |
-
if odd := [name for name in ran if not fnmatch.fnmatchcase(name, selector)]:
|
| 332 |
-
problems.append(f"task: the spec selects {selector!r}, the Trials ran {', '.join(odd)}")
|
| 333 |
-
swarm = next((t.name.removesuffix(f"-{a}-t{t.name.rsplit('-t', 1)[1]}")
|
| 334 |
-
for a, ts in trials.items() for t in ts), spec.get("name"))
|
| 335 |
-
return {"swarm": swarm, "task": task, "team": team, "start": start, "end": end,
|
| 336 |
-
"stop_reason": None, "duration_s": round(end - start, 1) if times else None,
|
| 337 |
-
"cost_usd": None, "tokens": {a: trial_tokens(trials.get(a, [])) for a in team},
|
| 338 |
-
"turns": dict.fromkeys(team), "problems": problems}
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
def row(run_dir: Path) -> dict:
|
| 342 |
-
trials = all_trials(run_dir)
|
| 343 |
-
run = bundle(run_dir)
|
| 344 |
-
info = local_run(run) if run is not None else slurm_run(run_dir, trials)
|
| 345 |
-
team = info["team"]
|
| 346 |
-
messages, channels, exported = board(run_dir, info["start"], info["end"])
|
| 347 |
-
posts = Counter(sender(m) for m in messages)
|
| 348 |
-
graph = edges(messages, channels, team)
|
| 349 |
-
per_agent, missing = {}, list(info.get("problems", []))
|
| 350 |
-
for name in team:
|
| 351 |
-
value = reward(trials.get(name, []))
|
| 352 |
-
if value is None:
|
| 353 |
-
missing.append(f"reward: {name}")
|
| 354 |
-
per_agent[name] = {"reward": value, "tokens": info["tokens"][name],
|
| 355 |
-
"posts": posts[name], "turns": info["turns"][name]}
|
| 356 |
-
if not exported:
|
| 357 |
-
missing.append("board export")
|
| 358 |
-
rewards = [a["reward"] for a in per_agent.values() if a["reward"] is not None]
|
| 359 |
-
task = info["task"]
|
| 360 |
-
out = {
|
| 361 |
-
"run": run_dir.name,
|
| 362 |
-
"swarm": info["swarm"],
|
| 363 |
-
"task": re.sub(r"-s\*$", "", task.get("selector") or "") or None, # a team's slots
|
| 364 |
-
"dataset": task.get("repo"),
|
| 365 |
-
"revision": task.get("revision"),
|
| 366 |
-
"agents": len(team),
|
| 367 |
-
"stop_reason": info["stop_reason"],
|
| 368 |
-
"duration_s": info["duration_s"],
|
| 369 |
-
"success": any(r == 1 for r in rewards) if rewards else None,
|
| 370 |
-
"rewards": {name: a["reward"] for name, a in per_agent.items()},
|
| 371 |
-
"tokens": {key: sum(a["tokens"][key] for a in per_agent.values())
|
| 372 |
-
for key in TOKEN_FIELDS},
|
| 373 |
-
"cost_usd": info["cost_usd"],
|
| 374 |
-
"posts": sum(posts[name] for name in team),
|
| 375 |
-
"other_posts": sum(n for who, n in posts.items() if who not in team),
|
| 376 |
-
"per_agent": per_agent,
|
| 377 |
-
"edges": sorted([a, b] for a, b in graph),
|
| 378 |
-
"centralization": centralization(graph, team),
|
| 379 |
-
"reciprocity": reciprocity(graph),
|
| 380 |
-
"missing": missing,
|
| 381 |
-
}
|
| 382 |
-
for extra in EXTRAS:
|
| 383 |
-
fields = extra(run_dir, team, trials)
|
| 384 |
-
out["missing"] += fields.pop("missing_moves", [])
|
| 385 |
-
out |= fields
|
| 386 |
-
return out
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
def main(argv=None) -> int:
|
| 390 |
-
parser = argparse.ArgumentParser(description="One row per team (JSON lines) from s³ runs.")
|
| 391 |
-
parser.add_argument("run_dirs", nargs="+", type=Path)
|
| 392 |
-
parser.add_argument("--out", type=Path, help="append the rows here (default: stdout)")
|
| 393 |
-
args = parser.parse_args(argv)
|
| 394 |
-
rows = [json.dumps(row(d)) for d in args.run_dirs]
|
| 395 |
-
if args.out:
|
| 396 |
-
with args.out.open("a", encoding="utf-8") as f:
|
| 397 |
-
f.write("".join(r + "\n" for r in rows))
|
| 398 |
-
else:
|
| 399 |
-
print("\n".join(rows))
|
| 400 |
-
return 0
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
if __name__ == "__main__":
|
| 404 |
-
sys.exit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
generate.py
CHANGED
|
@@ -186,7 +186,7 @@ services:
|
|
| 186 |
pids_limit: 64
|
| 187 |
mem_limit: 256m
|
| 188 |
networks:
|
| 189 |
-
default: {{}} # main's
|
| 190 |
maze:
|
| 191 |
internal: true
|
| 192 |
"""
|
|
|
|
| 186 |
pids_limit: 64
|
| 187 |
mem_limit: 256m
|
| 188 |
networks:
|
| 189 |
+
default: {{}} # main's egress network
|
| 190 |
maze:
|
| 191 |
internal: true
|
| 192 |
"""
|
legion/registries.conf
DELETED
|
@@ -1,13 +0,0 @@
|
|
| 1 |
-
# podman's registries for the workers (CONTAINERS_REGISTRIES_CONF in the cluster profile):
|
| 2 |
-
# Docker Hub images through Google's pull-through mirror first, since each worker job pulls the
|
| 3 |
-
# task's base image into its own storage and the cluster's shared address meets Docker Hub's
|
| 4 |
-
# unauthenticated pull limit (toomanyrequests). Docker Hub stays the fallback.
|
| 5 |
-
unqualified-search-registries = ["docker.io"]
|
| 6 |
-
short-name-mode = "permissive"
|
| 7 |
-
|
| 8 |
-
[[registry]]
|
| 9 |
-
prefix = "docker.io"
|
| 10 |
-
location = "docker.io"
|
| 11 |
-
|
| 12 |
-
[[registry.mirror]]
|
| 13 |
-
location = "mirror.gcr.io"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
legion/spec.template.yaml
DELETED
|
@@ -1,73 +0,0 @@
|
|
| 1 |
-
# s3-maze: N agents search their own copies of one tree of rooms for its exit, and the first one
|
| 2 |
-
# out ends the run. The template of every team's spec: team.py fills in the tree (TREE), the
|
| 3 |
-
# team (TEAM, e.g. maze-t07-n04) and this dataset's revision (REVISION), sizes the workers to the
|
| 4 |
-
# team, and merges one of `where:` into it.
|
| 5 |
-
# Don't launch this file; README.md.
|
| 6 |
-
name: ${RUN_NAME:-TEAM} # team.py: the team's name
|
| 7 |
-
model: Qwen/Qwen3.8-27B
|
| 8 |
-
naming: consecutive-id # agent-001 .. agent-00N, all on the one tree
|
| 9 |
-
inference:
|
| 10 |
-
hf_router:
|
| 11 |
-
provider: deepinfra
|
| 12 |
-
api_key_env: HF_INFERENCE_TOKEN # inference only: never the workers' HF_TOKEN
|
| 13 |
-
task:
|
| 14 |
-
repo: https://huggingface.co/datasets/HuggingFaceSwarms/s3-maze # private for now
|
| 15 |
-
selector: TREE # maze-t01 .. maze-t32: one task per tree
|
| 16 |
-
revision: REVISION # team.py: --revision, default the Hub's head
|
| 17 |
-
agents:
|
| 18 |
-
count: 1 # team.py: N
|
| 19 |
-
# The first agent to reach the exit ends the run. The check runs in that agent's maze service
|
| 20 |
-
# (read-only, every 30 s), never in its container.
|
| 21 |
-
stop_on_success: true
|
| 22 |
-
success_check:
|
| 23 |
-
service: maze
|
| 24 |
-
command: python3 -I -S /app/success.py
|
| 25 |
-
resources:
|
| 26 |
-
# The board rules: identical for every eval run, since they shape how agents talk (the same
|
| 27 |
-
# as s3-aggregation's). Enforced by each agent's rule proxy (docker and podman).
|
| 28 |
-
message_board:
|
| 29 |
-
channels:
|
| 30 |
-
- general
|
| 31 |
-
wake:
|
| 32 |
-
- mention
|
| 33 |
-
- thread
|
| 34 |
-
rules:
|
| 35 |
-
max_len: 1000
|
| 36 |
-
min_post_gap: 5s
|
| 37 |
-
max_posts: 40
|
| 38 |
-
max_channels: 1
|
| 39 |
-
workers:
|
| 40 |
-
agents_per_worker: 1 # team.py: N, the whole team on one worker and board
|
| 41 |
-
turn_timeout: 20m
|
| 42 |
-
loop:
|
| 43 |
-
prompt: Continue the task until it is complete, then stop.
|
| 44 |
-
every: turn_end
|
| 45 |
-
while:
|
| 46 |
-
until: 45m
|
| 47 |
-
max_rounds: 6
|
| 48 |
-
limits:
|
| 49 |
-
run_timeout_seconds: 3600
|
| 50 |
-
agent_max_turns: 150 # model calls per prompt
|
| 51 |
-
|
| 52 |
-
# Where the team runs: team.py merges one of these into the spec (--where). Each agent is a
|
| 53 |
-
# compose stack (its container and its maze service), so docker or podman: HF Sandboxes run one
|
| 54 |
-
# container per Trial.
|
| 55 |
-
where:
|
| 56 |
-
# Local docker, with the controller, the one worker and the board on this machine.
|
| 57 |
-
docker:
|
| 58 |
-
environment:
|
| 59 |
-
backend: docker
|
| 60 |
-
# The HF cluster: a Slurm worker on hopper-cpu running the team in rootless podman (podman
|
| 61 |
-
# 4.9), with a local board on that worker (a new one each run). Results reach
|
| 62 |
-
# <run dir>/results/ (Legion's docs/slurm.md "Results").
|
| 63 |
-
cluster:
|
| 64 |
-
namespace: ${NAMESPACE}
|
| 65 |
-
bucket: ${BUCKET} # the run's checkpoint bucket, hf://buckets/<ns>/<name>
|
| 66 |
-
compute:
|
| 67 |
-
kind: slurm
|
| 68 |
-
partition: ${SLURM_PARTITION:-} # the cluster profile's
|
| 69 |
-
cpus: 4 # team.py: N + 2, at least 4
|
| 70 |
-
mem: 7600M # team.py: 1900 MB per CPU (hopper-cpu allows 2000)
|
| 71 |
-
time: '2:00:00'
|
| 72 |
-
environment:
|
| 73 |
-
backend: podman
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
legion/sweep/README.md
DELETED
|
@@ -1,87 +0,0 @@
|
|
| 1 |
-
# s3-maze scaling sweep
|
| 2 |
-
|
| 3 |
-
The s³ paper's maze results (Figure 4 bottom: success against swarm size) with Legion: every tree
|
| 4 |
-
of this dataset at N = 1, 2, 4, 8 and 16 agents, one team each, every team its own Legion run on
|
| 5 |
-
the HF cluster, for one model per grid. The results for `Qwen/Qwen3.5-27B` and
|
| 6 |
-
`Qwen/Qwen3.5-2B` are on Legion's `s3-maze-results` branch (`experiments/s3-maze/results/`) and in
|
| 7 |
-
huggingface/legion#123's description; the raw runs are in the private
|
| 8 |
-
`HuggingFaceSwarms/s3-maze-results`.
|
| 9 |
-
|
| 10 |
-
| File | |
|
| 11 |
-
| --- | --- |
|
| 12 |
-
| `serve-vllm.sbatch` | one model server: vLLM on one B200 (s3-aggregation's image and parsers) with thinking off, `MODEL` and `PORT` from the environment |
|
| 13 |
-
| `sweep.py` | runs one model's grid, one command, resumable: a row per team in `<root>/rows.jsonl` |
|
| 14 |
-
| `health-log.sh` | each model server's prefix-cache hit rate and load every minute, to `servers.jsonl` (`--health`) |
|
| 15 |
-
| `plot.py` | `scaling.png`, `teams.csv`, `by_n.csv` and `by_n.md` from the rows, one series per grid (`NAME=ROOT@light` draws one lighter) |
|
| 16 |
-
| `setaside.py` | why each attempt in `rows-discarded.jsonl` didn't count |
|
| 17 |
-
|
| 18 |
-
## Run it
|
| 19 |
-
|
| 20 |
-
From Legion's checkout (at or after `0401df9`, legion#129), with this dataset on the shared disk (`DS`; the workers read
|
| 21 |
-
`legion/registries.conf`) and the private-repo credential helper exported (Legion's docs/slurm.md):
|
| 22 |
-
|
| 23 |
-
```sh
|
| 24 |
-
sbatch -p hopper-b200 -J s3-maze-vllm-27b-8011 --export=ALL,MODEL=Qwen/Qwen3.5-27B,PORT=8011 \
|
| 25 |
-
-o vllm-%j.log $DS/legion/sweep/serve-vllm.sbatch # one per GPU; the log ends with its URL
|
| 26 |
-
uv run python $DS/legion/sweep/sweep.py --model Qwen/Qwen3.5-27B --tag q27- --revision <sha> \
|
| 27 |
-
--urls http://<node>:8011/v1,http://<node>:8012/v1,... --per-server 12 --parallel 50 \
|
| 28 |
-
--root runs/q27 --health servers.jsonl --dataset HuggingFaceSwarms/s3-maze-results
|
| 29 |
-
uv run $DS/legion/sweep/plot.py --series Qwen3.5-27B=runs/q27 --series Qwen3.5-2B=runs/q2 --out results
|
| 30 |
-
```
|
| 31 |
-
|
| 32 |
-
Each team is team.py's cluster spec with the model on the servers (`urls`): `compute: slurm`, one
|
| 33 |
-
worker on hopper-cpu running the team's compose Trials in rootless podman with a local board,
|
| 34 |
-
and `stop_on_success`. The worker gets a CPU per agent, a quarter of one per maze service and two
|
| 35 |
-
more (at least 4), at 1900 MB per CPU. The driver inits and launches a team, waits for the first
|
| 36 |
-
exit (and the grading) or the end of the loop, releases it (`legion stop --release`, which also
|
| 37 |
-
ends its controller), and appends metrics.py's row with the team's exit branch and wall time.
|
| 38 |
-
`--hint` gives every team the protocol hint (`team.py --hint`); the board allows `#general`
|
| 39 |
-
only (`max_channels: 1`).
|
| 40 |
-
|
| 41 |
-
## What counts
|
| 42 |
-
|
| 43 |
-
A run counts only when its worker started within 2 minutes of its launch (the loop's 45 minutes
|
| 44 |
-
count from the launch), on one worker incarnation, with its controller kept, every agent's
|
| 45 |
-
reward and move log and the board export, and no agent's model server thrashing for 5 minutes or
|
| 46 |
-
more during it (below). Anything else is the infrastructure's: the team runs again as
|
| 47 |
-
`<task>-rK`, and `setaside.py` says why. A worker still not started 3 minutes after its launch
|
| 48 |
-
is released at once, so its team reruns without waiting out its time cap. A rerun's server
|
| 49 |
-
capacity is reserved under the `-rK` name it runs as, since legion hashes agents by run and name.
|
| 50 |
-
What the model does (no move, no post, no exit) is a result. A restarted driver adopts the teams
|
| 51 |
-
in flight and keeps each team's own start time.
|
| 52 |
-
|
| 53 |
-
## Model servers: thinking, KV cache and names
|
| 54 |
-
|
| 55 |
-
Every server sets `enable_thinking: false` as its chat template's default
|
| 56 |
-
(`--default-chat-template-kwargs`): the Qwen3.5 templates' defaults differ (the 27B thinks by
|
| 57 |
-
default, the 2B doesn't), and s3 runs compare models with thinking off. Check one response per
|
| 58 |
-
server before a grid starts: no `reasoning` field and no `<think>` in the content.
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
One B200 holds about 1.7M tokens of a 27B model's KV cache, and a maze agent's context grows past
|
| 62 |
-
100k tokens. A server with more such agents than fit evicts their cached prefixes and recomputes
|
| 63 |
-
each agent's whole context on every call (its prefix-cache hit rate falls from ~95% to a few
|
| 64 |
-
percent, and calls take minutes): the loop's time limit, not the move budget, then decides the
|
| 65 |
-
run. So:
|
| 66 |
-
|
| 67 |
-
- **at most `--per-server` agents per server** (9 to 19 for the 27B model, read again from
|
| 68 |
-
`<root>/per_server` before each launch, so it can change while the grid runs; the 2B model's
|
| 69 |
-
smaller cache entries, ~13M tokens per B200, fit a whole grid on one GPU);
|
| 70 |
-
- **every team gets the whole shared list.** Legion (from huggingface/legion#129, `0401df9`)
|
| 71 |
-
sends each agent to a server by hashing its run and its name over the URLs, so teams with
|
| 72 |
-
`naming: consecutive-id` spread over the servers instead of every team's `agent-001` calling
|
| 73 |
-
the same one. The driver hashes a new team's agents the same way and starts it once the
|
| 74 |
-
servers they land on are under the cap. (The sweeps before #129 gave each team its own subset
|
| 75 |
-
of the servers instead, to the same end.)
|
| 76 |
-
- **runs on a thrashing server don't count**: `health-log.sh` logs each server's hit rate every
|
| 77 |
-
minute, and a run whose agents' server had under 50% while prefilling 200k+ tokens in 5 or more
|
| 78 |
-
minutes runs again (`health-log.sh servers.jsonl <host:port> ...`).
|
| 79 |
-
|
| 80 |
-
## Workers: memory
|
| 81 |
-
|
| 82 |
-
Rootless podman on hopper-cpu can't hold a container to a memory limit, so a runaway process in
|
| 83 |
-
one agent's container (the 2B model's agents sometimes start one) grows the whole worker until
|
| 84 |
-
Legion's memory guard drains or preempts it, and the team runs again on a second incarnation.
|
| 85 |
-
For the 2B grid, `--cpus-per-agent 2` doubles each agent's share of the worker (and its memory,
|
| 86 |
-
at 1900 MB per CPU) and `--memory-ladder 0.97,0.98,0.99` lets the worker go closer to its limit
|
| 87 |
-
before the guard acts.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
legion/sweep/health-log.sh
DELETED
|
@@ -1,27 +0,0 @@
|
|
| 1 |
-
#!/bin/bash
|
| 2 |
-
# Every 60 s, each model server's requests, prompt tokens, prefix-cache hit rate, running and
|
| 3 |
-
# waiting requests over the last minute, one JSON line per server to OUT (sweep.py --health):
|
| 4 |
-
# health-log.sh servers.jsonl 10.53.14.57:8011 10.53.14.57:8012 ...
|
| 5 |
-
OUT=$1
|
| 6 |
-
shift
|
| 7 |
-
declare -A last
|
| 8 |
-
while true; do
|
| 9 |
-
for s in "$@"; do
|
| 10 |
-
now=$(curl -s -m 5 "$s/metrics" | awk '
|
| 11 |
-
/^vllm:request_success_total\{/ {a+=$2} /^vllm:prompt_tokens_total\{/ {p+=$2}
|
| 12 |
-
/^vllm:prefix_cache_hits_total\{/ {h+=$2} /^vllm:prefix_cache_queries_total\{/ {q+=$2}
|
| 13 |
-
/^vllm:num_requests_running\{/ {r+=$2} /^vllm:num_requests_waiting\{/ {w+=$2}
|
| 14 |
-
END {print a+0, p+0, h+0, q+0, r+0, w+0}')
|
| 15 |
-
if [ -n "${last[$s]}" ] && [ -n "$now" ]; then
|
| 16 |
-
python3 -c "
|
| 17 |
-
import json, sys, time
|
| 18 |
-
a0, p0, h0, q0, _, _ = map(float, sys.argv[1].split())
|
| 19 |
-
a1, p1, h1, q1, r, w = map(float, sys.argv[2].split())
|
| 20 |
-
print(json.dumps({'t': time.time(), 'server': sys.argv[3], 'requests': a1 - a0, 'prompt': p1 - p0,
|
| 21 |
-
'hit_rate': (h1 - h0) / (q1 - q0) if q1 > q0 else None, 'running': r, 'waiting': w}))
|
| 22 |
-
" "${last[$s]}" "$now" "$s" >> "$OUT"
|
| 23 |
-
fi
|
| 24 |
-
last[$s]=$now
|
| 25 |
-
done
|
| 26 |
-
sleep 60
|
| 27 |
-
done
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
legion/sweep/plot.py
DELETED
|
@@ -1,293 +0,0 @@
|
|
| 1 |
-
# /// script
|
| 2 |
-
# requires-python = ">=3.12"
|
| 3 |
-
# dependencies = ["matplotlib>=3.8"]
|
| 4 |
-
# ///
|
| 5 |
-
"""The s3-maze sweep's figure, CSVs and table from sweep.py's rows (`<root>/rows.jsonl`):
|
| 6 |
-
|
| 7 |
-
uv run legion/sweep/plot.py --series Qwen3.5-27B=<root> --series Qwen3.5-2B=<root> --out <dir>
|
| 8 |
-
|
| 9 |
-
- `scaling.png`, eight panels, one series per model, after the s³ paper's maze results
|
| 10 |
-
(Figure 4, bottom: success against swarm size; Figure 5c: success by the branch that holds
|
| 11 |
-
the exit; Appendix M: room overlap):
|
| 12 |
-
- success (%) against N, with 95% Wilson intervals over the trees, and best-of-N from the
|
| 13 |
-
model's own N = 1 rate (1 - (1 - p1)^N, the paper's independent-attempts baseline) dashed;
|
| 14 |
-
- the team's moves and the time (from its Trials' start) to the first exit, over the teams
|
| 15 |
-
that got out: median and interquartile range;
|
| 16 |
-
- room overlap, (V - U) / V, mean and 95% interval (N >= 2);
|
| 17 |
-
- input and generated tokens per team (log scale): median and interquartile range;
|
| 18 |
-
- board posts per agent: mean and 95% interval;
|
| 19 |
-
- success by which of the start room's three doors, in the listed order, leads to the exit,
|
| 20 |
-
over every N >= 2 team (95% Wilson intervals).
|
| 21 |
-
- `teams.csv` (one row per team), `by_n.csv` and `by_n.md` (per model and N).
|
| 22 |
-
"""
|
| 23 |
-
|
| 24 |
-
import argparse
|
| 25 |
-
import csv
|
| 26 |
-
import json
|
| 27 |
-
import math
|
| 28 |
-
import statistics
|
| 29 |
-
import sys
|
| 30 |
-
from pathlib import Path
|
| 31 |
-
|
| 32 |
-
SURFACE, INK, INK_2, GRID = "#fcfcfb", "#0b0b0b", "#52514e", "#e4e3df"
|
| 33 |
-
SERIES = ["#2a78d6", "#eb6834", "#1baf7a"]
|
| 34 |
-
LIGHT: set[str] = set() # the series drawn lighter (`--series NAME=ROOT@light`)
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
def wilson(k: int, n: int, z: float = 1.96) -> tuple[float, float]:
|
| 38 |
-
if n == 0:
|
| 39 |
-
return (math.nan, math.nan)
|
| 40 |
-
p = k / n
|
| 41 |
-
centre = (p + z * z / (2 * n)) / (1 + z * z / n)
|
| 42 |
-
half = z * math.sqrt(p * (1 - p) / n + z * z / (4 * n * n)) / (1 + z * z / n)
|
| 43 |
-
return (max(0.0, centre - half), min(1.0, centre + half))
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
def mean_ci(values: list[float]) -> tuple[float, float, float]:
|
| 47 |
-
if not values:
|
| 48 |
-
return (math.nan, math.nan, math.nan)
|
| 49 |
-
m = statistics.fmean(values)
|
| 50 |
-
half = 1.96 * statistics.stdev(values) / math.sqrt(len(values)) if len(values) > 1 else 0.0
|
| 51 |
-
return (m, m - half, m + half)
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
def quartiles(values: list[float]) -> tuple[float, float, float]:
|
| 55 |
-
if not values:
|
| 56 |
-
return (math.nan, math.nan, math.nan)
|
| 57 |
-
q = statistics.quantiles(values, n=4) if len(values) > 1 else [values[0]] * 3
|
| 58 |
-
return (statistics.median(values), q[0], q[2])
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
def team_row(r: dict) -> dict:
|
| 62 |
-
t, first = r["tokens"], r.get("first_exit") or {}
|
| 63 |
-
return {"task": r["task"], "tree": r["tree"], "agents": r["agents"],
|
| 64 |
-
"exit_branch": r["exit_branch"], "success": int(bool(r["success"])),
|
| 65 |
-
"exit_by": first.get("agent"), "exit_after_s": first.get("after_s"),
|
| 66 |
-
"exit_team_moves": first.get("team_moves"),
|
| 67 |
-
"exit_agent_moves": first.get("agent_moves"),
|
| 68 |
-
"moves": sum((r.get("moves") or {}).values()),
|
| 69 |
-
"refused_moves": sum((r.get("refused_moves") or {}).values()),
|
| 70 |
-
"room_overlap": r.get("room_overlap"), "rooms_union": r.get("rooms_union"),
|
| 71 |
-
"input_uncached": t["input"], "cached": t["cache_read"], "output": t["output"],
|
| 72 |
-
"posts": r["posts"], "posts_per_agent": r["posts"] / r["agents"],
|
| 73 |
-
"edges": len(r["edges"]), "outcome": r.get("outcome"), "wall_s": r.get("wall_s"),
|
| 74 |
-
"duration_s": r["duration_s"], "reruns": r.get("reruns", 0),
|
| 75 |
-
"worker_wait_s": r.get("worker_wait_s"), "run": r["run"]}
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
def by_n(teams: list[dict]) -> list[dict]:
|
| 79 |
-
"""Per N. A tree with no team that counted at that N (every attempt set aside) is
|
| 80 |
-
`missing`: left out of the rates, not a failure."""
|
| 81 |
-
out, p1 = [], None
|
| 82 |
-
trees = {t["tree"] for t in teams}
|
| 83 |
-
for n in sorted({t["agents"] for t in teams}):
|
| 84 |
-
group = [t for t in teams if t["agents"] == n]
|
| 85 |
-
missing = sorted(trees - {t["tree"] for t in group})
|
| 86 |
-
won = [t for t in group if t["success"]]
|
| 87 |
-
k = len(won)
|
| 88 |
-
low, high = wilson(k, len(group))
|
| 89 |
-
if n == 1:
|
| 90 |
-
p1 = k / len(group)
|
| 91 |
-
overlap = [t["room_overlap"] for t in group if t["room_overlap"] is not None]
|
| 92 |
-
moves, minutes = (quartiles([t["exit_team_moves"] for t in won]),
|
| 93 |
-
quartiles([t["exit_after_s"] / 60 for t in won]))
|
| 94 |
-
out.append({
|
| 95 |
-
"agents": n, "teams": len(group), "missing": len(missing),
|
| 96 |
-
"missing_trees": " ".join(f"t{x:02d}" for x in missing),
|
| 97 |
-
"successes": k, "success_rate": k / len(group),
|
| 98 |
-
"ci_low": low, "ci_high": high,
|
| 99 |
-
"best_of_n_from_n1": 1 - (1 - p1) ** n if p1 is not None else math.nan,
|
| 100 |
-
"exit_team_moves_median": moves[0], "exit_team_moves_q1": moves[1],
|
| 101 |
-
"exit_team_moves_q3": moves[2],
|
| 102 |
-
"exit_agent_moves_median": quartiles([t["exit_agent_moves"] for t in won])[0],
|
| 103 |
-
"exit_minutes_median": minutes[0], "exit_minutes_q1": minutes[1],
|
| 104 |
-
"exit_minutes_q3": minutes[2],
|
| 105 |
-
"moves_per_agent": statistics.fmean(t["moves"] / n for t in group),
|
| 106 |
-
"room_overlap": statistics.fmean(overlap) if overlap else math.nan,
|
| 107 |
-
"input_per_team": statistics.fmean(t["input_uncached"] + t["cached"] for t in group),
|
| 108 |
-
"output_per_team": statistics.fmean(t["output"] for t in group),
|
| 109 |
-
"input_per_team_median": statistics.median(t["input_uncached"] + t["cached"]
|
| 110 |
-
for t in group),
|
| 111 |
-
"output_per_team_median": statistics.median(t["output"] for t in group),
|
| 112 |
-
"posts_per_agent": statistics.fmean(t["posts_per_agent"] for t in group),
|
| 113 |
-
"wall_minutes_median": statistics.median(t["wall_s"] / 60 for t in group
|
| 114 |
-
if t["wall_s"] is not None),
|
| 115 |
-
"reruns": sum(t["reruns"] for t in group)})
|
| 116 |
-
return out
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
def write_csv(path: Path, rows: list[dict]) -> None:
|
| 120 |
-
with path.open("w", newline="") as f:
|
| 121 |
-
writer = csv.DictWriter(f, fieldnames=list(rows[0]), lineterminator="\n")
|
| 122 |
-
writer.writeheader()
|
| 123 |
-
writer.writerows(rows)
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
def table(series) -> str:
|
| 127 |
-
lines = [("| model | N | teams | success | 95% CI | best-of-N from N=1 | team moves to exit "
|
| 128 |
-
"| minutes to exit | moves per agent | median input / output tokens per team "
|
| 129 |
-
"| posts per agent | room overlap |"),
|
| 130 |
-
"|---|---|---|---|---|---|---|---|---|---|---|---|"]
|
| 131 |
-
for model, _, summary in series:
|
| 132 |
-
for s in summary:
|
| 133 |
-
def num(x, f="{:.0f}"):
|
| 134 |
-
return "-" if x is None or (isinstance(x, float) and math.isnan(x)) else f.format(x)
|
| 135 |
-
gone = f" ({s['missing']} missing)" if s["missing"] else ""
|
| 136 |
-
lines.append(
|
| 137 |
-
f"| {model} | {s['agents']} | {s['teams']}{gone} | {s['successes']}/{s['teams']} "
|
| 138 |
-
f"({100 * s['success_rate']:.0f}%) | {100 * s['ci_low']:.0f}-"
|
| 139 |
-
f"{100 * s['ci_high']:.0f}% | {num(100 * s['best_of_n_from_n1'], '{:.0f}%')} "
|
| 140 |
-
f"| {num(s['exit_team_moves_median'])} | {num(s['exit_minutes_median'], '{:.1f}')} "
|
| 141 |
-
f"| {s['moves_per_agent']:.0f} | {s['input_per_team_median'] / 1e6:.1f}M / "
|
| 142 |
-
f"{s['output_per_team_median'] / 1e3:.0f}k | {s['posts_per_agent']:.1f} "
|
| 143 |
-
f"| {num(s['room_overlap'], '{:.2f}')} |")
|
| 144 |
-
return "\n".join(lines) + "\n"
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
def panels(teams: list[dict], summary: list[dict]) -> list[tuple]:
|
| 148 |
-
"""(label, x values, [(middle, low, high)], y scale, dashed reference or None)."""
|
| 149 |
-
ns = [s["agents"] for s in summary]
|
| 150 |
-
group = {n: [t for t in teams if t["agents"] == n] for n in ns}
|
| 151 |
-
won = {n: [t for t in group[n] if t["success"]] for n in ns}
|
| 152 |
-
multi = [n for n in ns if n > 1]
|
| 153 |
-
branches = [1, 2, 3]
|
| 154 |
-
by_branch = [[t for t in teams if t["agents"] > 1 and t["exit_branch"] == b] for b in branches]
|
| 155 |
-
return [
|
| 156 |
-
("Success (%)", ns, [(100 * s["success_rate"], 100 * s["ci_low"], 100 * s["ci_high"])
|
| 157 |
-
for s in summary], (0, 105),
|
| 158 |
-
[100 * s["best_of_n_from_n1"] for s in summary]),
|
| 159 |
-
("Team moves to the first exit", ns,
|
| 160 |
-
[quartiles([t["exit_team_moves"] for t in won[n]]) for n in ns], None, None),
|
| 161 |
-
("Minutes to the first exit", ns,
|
| 162 |
-
[quartiles([t["exit_after_s"] / 60 for t in won[n]]) for n in ns], None, None),
|
| 163 |
-
("Room overlap", multi,
|
| 164 |
-
[mean_ci([t["room_overlap"] for t in group[n] if t["room_overlap"] is not None])
|
| 165 |
-
for n in multi], (0, 1), None),
|
| 166 |
-
("Input tokens per team", ns,
|
| 167 |
-
[quartiles([t["input_uncached"] + t["cached"] for t in group[n]]) for n in ns], "log",
|
| 168 |
-
None),
|
| 169 |
-
("Generated tokens per team", ns, [quartiles([t["output"] for t in group[n]]) for n in ns],
|
| 170 |
-
"log", None),
|
| 171 |
-
("Board posts per agent", ns, [mean_ci([t["posts_per_agent"] for t in group[n]])
|
| 172 |
-
for n in ns], None, None),
|
| 173 |
-
("Success (%) by the exit's branch, N ≥ 2", branches,
|
| 174 |
-
[(100 * sum(t["success"] for t in g) / len(g) if g else math.nan,
|
| 175 |
-
*(100 * v for v in wilson(sum(t["success"] for t in g), len(g)))) for g in by_branch],
|
| 176 |
-
(0, 105), None),
|
| 177 |
-
]
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
def tokens(value: float, _=None) -> str:
|
| 181 |
-
for size, unit in ((1e6, "M"), (1e3, "k")):
|
| 182 |
-
if value >= size:
|
| 183 |
-
return f"{value / size:g}{unit}"
|
| 184 |
-
return f"{value:g}"
|
| 185 |
-
|
| 186 |
-
|
| 187 |
-
def figure(path: Path, series, title: str) -> None:
|
| 188 |
-
import matplotlib
|
| 189 |
-
|
| 190 |
-
matplotlib.use("Agg")
|
| 191 |
-
import matplotlib.pyplot as plt
|
| 192 |
-
from matplotlib.ticker import FixedLocator, FuncFormatter, NullFormatter
|
| 193 |
-
|
| 194 |
-
plt.rcParams.update({"font.size": 10, "axes.edgecolor": GRID, "axes.labelcolor": INK_2,
|
| 195 |
-
"xtick.color": INK_2, "ytick.color": INK_2, "text.color": INK})
|
| 196 |
-
fig, grid = plt.subplots(2, 4, figsize=(17, 7.8), facecolor=SURFACE)
|
| 197 |
-
axes = grid.flatten()
|
| 198 |
-
xs_by_panel: dict[int, set] = {}
|
| 199 |
-
colours, c = [], -1 # a light series (`@light`) takes the colour of the series before it
|
| 200 |
-
for model, _, _ in series:
|
| 201 |
-
c += model not in LIGHT or c < 0
|
| 202 |
-
colours.append(SERIES[c])
|
| 203 |
-
for k, (model, teams, summary) in enumerate(series):
|
| 204 |
-
light = model in LIGHT
|
| 205 |
-
look = ({"alpha": 0.4, "linewidth": 1.3, "markersize": 4, "elinewidth": 1.0} if light
|
| 206 |
-
else {"linewidth": 2, "markersize": 6, "elinewidth": 1.4})
|
| 207 |
-
step = (k - (len(series) - 1) / 2) # side by side, so the bars don't hide each other
|
| 208 |
-
for i, (ax, (label, xs, points, scale, reference)) in enumerate(
|
| 209 |
-
zip(axes, panels(teams, summary), strict=True)):
|
| 210 |
-
xs_by_panel.setdefault(i, set()).update(xs)
|
| 211 |
-
# N on a log2 axis: shift by a factor; the branches (panel 7) by a step
|
| 212 |
-
moved = [x + 0.08 * step if i == 7 else x * 2 ** (0.07 * step) for x in xs]
|
| 213 |
-
ax.errorbar(moved, [p[0] for p in points],
|
| 214 |
-
yerr=[[max(0.0, p[0] - p[1]) if not math.isnan(p[1]) else 0 for p in points],
|
| 215 |
-
[max(0.0, p[2] - p[0]) if not math.isnan(p[2]) else 0 for p in points]],
|
| 216 |
-
color=colours[k], marker="o", capsize=3, label=model,
|
| 217 |
-
linestyle="-" if i != 7 else "none", **look)
|
| 218 |
-
if reference and not light:
|
| 219 |
-
ax.plot(xs, reference, color=colours[k], linewidth=1.3, linestyle="--",
|
| 220 |
-
label=f"{model}: best-of-N from N = 1")
|
| 221 |
-
ax.set_ylabel(label)
|
| 222 |
-
scales = [p[3] for p in panels(*series[0][1:])]
|
| 223 |
-
for i, ax in enumerate(axes): # after every series is in, so each scales to all of them
|
| 224 |
-
if scales[i] == "log":
|
| 225 |
-
ax.set_yscale("log")
|
| 226 |
-
ax.yaxis.set_major_formatter(FuncFormatter(tokens))
|
| 227 |
-
ax.yaxis.set_minor_formatter(NullFormatter())
|
| 228 |
-
elif scales[i]:
|
| 229 |
-
ax.set_ylim(*scales[i])
|
| 230 |
-
else:
|
| 231 |
-
ax.set_ylim(bottom=0)
|
| 232 |
-
ticks = sorted(xs_by_panel.get(i, ()))
|
| 233 |
-
if i != 7 and ticks:
|
| 234 |
-
ax.set_xlim(min(ticks) / 1.4, max(ticks) * 1.4)
|
| 235 |
-
ax.set_xscale("log", base=2)
|
| 236 |
-
ax.xaxis.set_minor_formatter(NullFormatter())
|
| 237 |
-
ax.xaxis.set_major_locator(FixedLocator(ticks))
|
| 238 |
-
ax.set_xticklabels([str(t) for t in ticks])
|
| 239 |
-
ax.set_facecolor(SURFACE)
|
| 240 |
-
ax.grid(axis="y", color=GRID, linewidth=0.8)
|
| 241 |
-
ax.set_axisbelow(True)
|
| 242 |
-
ax.spines[["top", "right"]].set_visible(False)
|
| 243 |
-
ax.set_xlabel("Door at the start room (listed order)" if i == 7 else "Swarm size N")
|
| 244 |
-
axes[0].legend(frameon=False, loc="upper left", fontsize=8)
|
| 245 |
-
fig.suptitle(title, fontsize=11, color=INK, x=0.01, ha="left")
|
| 246 |
-
gone = "".join(f"; {m} at N = {s['agents']}: {s['missing']} missing (every attempt set "
|
| 247 |
-
"aside), left out, not failures" for m, _, summary in series
|
| 248 |
-
for s in summary if s["missing"])
|
| 249 |
-
fig.text(0.01, 0.012, f"One counted team per tree (32 trees{gone}). Success: share of "
|
| 250 |
-
"teams in which any agent reached the exit, 95% Wilson intervals; dashed: best-of-N "
|
| 251 |
-
"from the model's own N = 1 rate.\nMoves (all agents') and minutes (from the "
|
| 252 |
-
"Trials' start) to the first exit: teams that got out; tokens per team (log scale): "
|
| 253 |
-
"every team; medians and interquartile ranges. Overlap and posts: means, 95% "
|
| 254 |
-
"intervals.", fontsize=8, color=INK_2, wrap=True)
|
| 255 |
-
fig.tight_layout(rect=(0, 0.06, 1, 0.95))
|
| 256 |
-
fig.savefig(path, dpi=200, facecolor=SURFACE)
|
| 257 |
-
|
| 258 |
-
|
| 259 |
-
def load(root: Path) -> tuple[list[dict], list[dict]]:
|
| 260 |
-
rows = [json.loads(line) for line in (root / "rows.jsonl").read_text().splitlines() if line]
|
| 261 |
-
teams = sorted((team_row(r) for r in rows), key=lambda t: (t["agents"], t["tree"]))
|
| 262 |
-
return teams, by_n(teams)
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
def main(argv=None) -> int:
|
| 266 |
-
parser = argparse.ArgumentParser(description="The sweep's figure, CSVs and table.")
|
| 267 |
-
parser.add_argument("--series", action="append", required=True,
|
| 268 |
-
help="NAME=ROOT, repeatable; NAME=ROOT@light draws it lighter, in the "
|
| 269 |
-
"colour of the series before it, without its best-of-N line")
|
| 270 |
-
parser.add_argument("--title", default="s3-maze with legion: success and cost against swarm "
|
| 271 |
-
"size")
|
| 272 |
-
parser.add_argument("--out", type=Path, required=True)
|
| 273 |
-
args = parser.parse_args(argv)
|
| 274 |
-
sources = []
|
| 275 |
-
for s in args.series:
|
| 276 |
-
name, root = s.split("=", 1)
|
| 277 |
-
if root.endswith("@light"):
|
| 278 |
-
root = root.removesuffix("@light")
|
| 279 |
-
LIGHT.add(name)
|
| 280 |
-
sources.append((name, Path(root)))
|
| 281 |
-
args.out.mkdir(parents=True, exist_ok=True)
|
| 282 |
-
series = [(model, *load(root)) for model, root in sources]
|
| 283 |
-
write_csv(args.out / "teams.csv", [{"model": m} | t for m, teams, _ in series for t in teams])
|
| 284 |
-
write_csv(args.out / "by_n.csv", [{"model": m} | s for m, _, summary in series
|
| 285 |
-
for s in summary])
|
| 286 |
-
(args.out / "by_n.md").write_text(table(series))
|
| 287 |
-
figure(args.out / "scaling.png", series, args.title)
|
| 288 |
-
print(table(series))
|
| 289 |
-
return 0
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
if __name__ == "__main__":
|
| 293 |
-
sys.exit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
legion/sweep/serve-vllm.sbatch
DELETED
|
@@ -1,33 +0,0 @@
|
|
| 1 |
-
#!/bin/bash
|
| 2 |
-
# The s3-maze sweep's model server: one vLLM on one GPU, in Pyxis on hopper-b200, as
|
| 3 |
-
# s3-aggregation's legion/sweep/serve-vllm.sbatch (the same image and parsers). The agents
|
| 4 |
-
# (podman on hopper-cpu) reach it by this node's address.
|
| 5 |
-
# sbatch -p hopper-b200 -J s3-maze-vllm-27b-8011 --export=ALL,MODEL=Qwen/Qwen3.5-27B,PORT=8011 -o <dir>/vllm-%j.log serve-vllm.sbatch
|
| 6 |
-
# Its log ends with: serving <model> at http://<node address>:<port>/v1
|
| 7 |
-
#
|
| 8 |
-
# Thinking is off for every model (`enable_thinking: false` as the chat template's default):
|
| 9 |
-
# the Qwen3.5 templates' defaults differ (27B thinks by default, 2B doesn't), and s3 runs compare
|
| 10 |
-
# models with thinking off. A request can still turn it on with its own chat_template_kwargs.
|
| 11 |
-
# 11 CPUs, so eight servers fit a B200 node (92 CPUs).
|
| 12 |
-
#SBATCH --job-name=s3-maze-vllm
|
| 13 |
-
#SBATCH --gpus=1
|
| 14 |
-
#SBATCH --cpus-per-task=11
|
| 15 |
-
#SBATCH --mem=96G
|
| 16 |
-
#SBATCH --time=12:00:00
|
| 17 |
-
set -uo pipefail
|
| 18 |
-
MODEL=${MODEL:-Qwen/Qwen3.5-27B}
|
| 19 |
-
PORT=${PORT:-8000}
|
| 20 |
-
IMAGE=${IMAGE:-/fsx/anton/shared/images/vllm-openai-v0.32.0.sqsh}
|
| 21 |
-
export HF_HOME=/hf
|
| 22 |
-
mkdir -p "/scratch/$USER/hf" # the weights, on the node's own disk
|
| 23 |
-
srun --overlap --container-image="$IMAGE" --no-container-mount-home \
|
| 24 |
-
--container-mounts="/scratch/$USER/hf:/hf" --container-env=HF_HOME \
|
| 25 |
-
vllm serve "$MODEL" --port "$PORT" \
|
| 26 |
-
--enable-auto-tool-choice --tool-call-parser qwen3_coder --reasoning-parser qwen3 \
|
| 27 |
-
--default-chat-template-kwargs '{"enable_thinking": false}' &
|
| 28 |
-
until curl -sf -o /dev/null "localhost:$PORT/v1/models"; do
|
| 29 |
-
sleep 10
|
| 30 |
-
kill -0 $! 2>/dev/null || { echo "vLLM exited during startup"; exit 1; }
|
| 31 |
-
done
|
| 32 |
-
echo "serving $MODEL at http://$(hostname -I | awk '{print $1}'):$PORT/v1"
|
| 33 |
-
wait
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
legion/sweep/setaside.py
DELETED
|
@@ -1,96 +0,0 @@
|
|
| 1 |
-
"""Why each set-aside attempt of a grid didn't count: `python legion/sweep/setaside.py <root>`,
|
| 2 |
-
from `<root>/rows-discarded.jsonl` and the attempt's own logs (s3-aggregation's, for the maze).
|
| 3 |
-
A restarted driver scores an attempt again from what it left, so one attempt can have several
|
| 4 |
-
entries: its reason uses them all. Writes `<root>/setaside.md`; the reasons, first that applies:
|
| 5 |
-
|
| 6 |
-
- it ran while its model server was overloaded (`--overloaded`), or an agent's server thrashed
|
| 7 |
-
for 5 minutes or more (`--health`);
|
| 8 |
-
- the worker was relaunched (more than one incarnation: legion#121's case), after running out of
|
| 9 |
-
memory or after a node failure;
|
| 10 |
-
- the launch failed (or was cancelled), so its controller never came up;
|
| 11 |
-
- the worker never started, or started more than 2 min after the launch (the loop counts from
|
| 12 |
-
the launch);
|
| 13 |
-
- the controller's node was reclaimed (spot) mid-run;
|
| 14 |
-
- the task images couldn't be pulled or built, so the Trials never started;
|
| 15 |
-
- the worker ran out of memory;
|
| 16 |
-
- the verifier timed out on a loaded worker;
|
| 17 |
-
- an agent's Trial failed before its verifier ran;
|
| 18 |
-
- the run was cancelled before its Trials were graded (e.g. the driver stopped).
|
| 19 |
-
|
| 20 |
-
What the model does (no move, no post, no exit) is never a reason: those runs count.
|
| 21 |
-
"""
|
| 22 |
-
|
| 23 |
-
import json
|
| 24 |
-
import re
|
| 25 |
-
import sys
|
| 26 |
-
from collections import Counter
|
| 27 |
-
from pathlib import Path
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
def reason(row: dict, run_dir: Path) -> str:
|
| 31 |
-
logs = {p.name: p.read_text(errors="replace") for p in (run_dir / "logs").glob("*")
|
| 32 |
-
if p.is_file()} if (run_dir / "logs").is_dir() else {}
|
| 33 |
-
workers = " ".join(v for k, v in logs.items() if "-agent-w" in k)
|
| 34 |
-
controllers = " ".join(v for k, v in logs.items() if k.startswith(("legion-ctl-",
|
| 35 |
-
"controller-")))
|
| 36 |
-
if "overloaded model server" in (row.get("set_aside") or ""):
|
| 37 |
-
return "ran on an overloaded model server (one 27B GPU, KV-cache thrash)"
|
| 38 |
-
if (row.get("thrashed_min") or 0) >= 5: # sweep.py's THRASH_LIMIT
|
| 39 |
-
return "an agent's model server thrashed (prefix-cache hits under 50%) for 5+ min"
|
| 40 |
-
if (row.get("incarnations") or 0) > 1:
|
| 41 |
-
if re.search(r"CANCELED: unresponsive", controllers):
|
| 42 |
-
return "worker stopped answering (e.g. while grading its Trials) and was relaunched"
|
| 43 |
-
if re.search(r"preempted \(memory\)|draining \(memory\)|rotation wanted", workers):
|
| 44 |
-
return "worker relaunched after running out of memory (legion#121's case)"
|
| 45 |
-
return "worker relaunched after a node failure (legion#121's case)"
|
| 46 |
-
if row.get("outcome") == "launch":
|
| 47 |
-
return "launch failed or was cancelled (the controller ended before it came up)"
|
| 48 |
-
if row.get("worker_wait_s") is None:
|
| 49 |
-
return "worker never started"
|
| 50 |
-
if row["worker_wait_s"] > 120: # sweep.py's WAIT_LIMIT
|
| 51 |
-
return "worker started more than 2 min after the launch (the loop counts from it)"
|
| 52 |
-
if "DUE TO NODE FAILURE" in controllers or row.get("outcome") == "controller lost":
|
| 53 |
-
return "controller's node reclaimed (spot)"
|
| 54 |
-
if re.search(r"toomanyrequests|Error: building at STEP|failed to build", workers):
|
| 55 |
-
return "task images not pulled or built: Trials never started"
|
| 56 |
-
if re.search(r"preempted \(memory\)|oom_kill", workers):
|
| 57 |
-
return "worker ran out of memory (preempted or killed, not relaunched)"
|
| 58 |
-
results = list(run_dir.glob("results/*/agent-*/trials/*/result.json"))
|
| 59 |
-
if any("VerifierTimeoutError" in p.read_text(errors="replace") for p in results):
|
| 60 |
-
return "verifier timed out on a loaded worker"
|
| 61 |
-
failed = [(json.loads(p.read_text()).get("exception_info") or {}).get("exception_type")
|
| 62 |
-
for p in results]
|
| 63 |
-
if kinds := sorted({k for k in failed if k and k != "CancelledError"}):
|
| 64 |
-
return f"an agent's Trial failed before its verifier ran ({', '.join(kinds)})"
|
| 65 |
-
return "cancelled before grading (e.g. the driver stopped)"
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
def main(root: Path) -> int:
|
| 69 |
-
attempts = {}
|
| 70 |
-
path = root / "rows-discarded.jsonl"
|
| 71 |
-
for line in path.read_text().splitlines() if path.exists() else []:
|
| 72 |
-
row = json.loads(line)
|
| 73 |
-
seen = attempts.setdefault(row["run"], row) # the driver that watched it knew most
|
| 74 |
-
seen["incarnations"] = max(seen.get("incarnations") or 0, row.get("incarnations") or 0)
|
| 75 |
-
seen["set_aside"] = "; ".join(filter(None, {seen.get("set_aside"), row.get("set_aside")}))
|
| 76 |
-
if row.get("outcome") == "controller lost":
|
| 77 |
-
seen["outcome"] = row["outcome"]
|
| 78 |
-
kept = [json.loads(x) for x in (root / "rows.jsonl").read_text().splitlines() if x]
|
| 79 |
-
reasons = Counter(reason(r, root / "runs" / run) for run, r in attempts.items())
|
| 80 |
-
counted = {(r["tree"], r["agents"]) for r in kept}
|
| 81 |
-
missing = sorted({(r["tree"], r["agents"]) for r in attempts.values()} - counted)
|
| 82 |
-
rerun = sum(r.get("reruns", 0) > 0 for r in kept) + len(missing)
|
| 83 |
-
lines = [(f"Attempts set aside: {len(attempts)} (rows-discarded.jsonl); teams that needed a "
|
| 84 |
-
f"rerun: {rerun} of {len(counted) + len(missing)}"), ""]
|
| 85 |
-
lines += [f"- {why}: {k}" for why, k in reasons.most_common()]
|
| 86 |
-
if missing:
|
| 87 |
-
lines += ["", f"Teams with no attempt that counted ({len(missing)}; missing from the "
|
| 88 |
-
"results, not failures): " + ", ".join(f"tree {t:02d} at N = {n}"
|
| 89 |
-
for t, n in missing)]
|
| 90 |
-
(root / "setaside.md").write_text("\n".join(lines) + "\n")
|
| 91 |
-
print("\n".join(lines))
|
| 92 |
-
return 0
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
if __name__ == "__main__":
|
| 96 |
-
raise SystemExit(main(Path(sys.argv[1])))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
legion/sweep/sweep.py
DELETED
|
@@ -1,570 +0,0 @@
|
|
| 1 |
-
"""The s3-maze scaling sweep on the HF cluster, one command per model for the whole grid, run
|
| 2 |
-
from Legion's checkout (its environment, and its `.venv` for the workers):
|
| 3 |
-
|
| 4 |
-
uv run python <this dataset>/legion/sweep/sweep.py --urls http://<vllm node>:8000/v1 \\
|
| 5 |
-
--model Qwen/Qwen3.5-27B --tag q27- --revision <sha> [--trees 1-32] \\
|
| 6 |
-
[--agents 1,2,4,8,16] [--parallel 20] [--max-agents 64] [--root .legion/s3-maze-sweep/q27]
|
| 7 |
-
|
| 8 |
-
s3-aggregation's legion/sweep/sweep.py for the maze. Each (tree, N) team is its own legion run
|
| 9 |
-
(`compute: slurm`, podman agents on hopper-cpu, a local board on its one worker), from team.py's
|
| 10 |
-
cluster spec with the sweep's model on `urls`: the same board rules, loop, limits and move
|
| 11 |
-
budget at every N, and `stop_on_success`. The worker gets a CPU per agent, a quarter of one per
|
| 12 |
-
maze service and two more (at least 4), at 1900 MB per CPU. Per team: `legion init`,
|
| 13 |
-
`legion launch`, then wait until the first agent's exit stops the run (and every Trial is
|
| 14 |
-
graded) or the loop is done and the agents are idle; `legion stop --release` (which grades the
|
| 15 |
-
Trials of a run nobody won, and ends the controller in either case); then eval/metrics.py's row
|
| 16 |
-
plus the wall time and the tree's exit branch go to `<root>/rows.jsonl`.
|
| 17 |
-
|
| 18 |
-
A run counts only when its worker started within WAIT_LIMIT of its launch (the loop's time
|
| 19 |
-
counts from the launch), on one worker incarnation (legion#121), with its controller kept and
|
| 20 |
-
nothing missing (every agent's reward and move log, the board export). Anything else is the
|
| 21 |
-
infrastructure's, so the team runs again as `<task>-rK` and the attempt goes to
|
| 22 |
-
`rows-discarded.jsonl`; what the model does (no move, no post, no exit) is a result. A team with
|
| 23 |
-
a row is skipped, so the same command resumes; a team a stopped driver launched is adopted and
|
| 24 |
-
keeps its own start time for its time cap.
|
| 25 |
-
|
| 26 |
-
At most `--parallel` teams and `--max-agents` agents run at once (the agents of the teams in
|
| 27 |
-
flight; `<root>/max_agents`, when present, overrides it while the driver runs): one GPU's KV
|
| 28 |
-
cache holds a few dozen agents' contexts of a large model, and an overloaded server would make
|
| 29 |
-
the loop's time limit, not the move budget, decide the result.
|
| 30 |
-
|
| 31 |
-
Needs HF_TOKEN (or `hf auth login`): the workers clone the private task dataset and sync the
|
| 32 |
-
private state bucket with it. The agents get no Hub token; the vLLM servers take no key.
|
| 33 |
-
"""
|
| 34 |
-
|
| 35 |
-
import argparse
|
| 36 |
-
import importlib.util
|
| 37 |
-
import json
|
| 38 |
-
import os
|
| 39 |
-
import re
|
| 40 |
-
import shutil
|
| 41 |
-
import subprocess
|
| 42 |
-
import sys
|
| 43 |
-
import threading
|
| 44 |
-
import time
|
| 45 |
-
from collections import Counter
|
| 46 |
-
from concurrent.futures import ThreadPoolExecutor
|
| 47 |
-
from datetime import UTC, datetime
|
| 48 |
-
from pathlib import Path
|
| 49 |
-
|
| 50 |
-
import httpx
|
| 51 |
-
import yaml
|
| 52 |
-
from huggingface_hub import HfApi, get_token
|
| 53 |
-
|
| 54 |
-
from legion.models import Inference
|
| 55 |
-
|
| 56 |
-
HERE = Path(__file__).resolve().parent
|
| 57 |
-
DATASET_DIR = HERE.parents[1]
|
| 58 |
-
REPO = Path.cwd() # Legion's checkout
|
| 59 |
-
SECRET = re.compile(r"hf_[A-Za-z0-9]{30,}")
|
| 60 |
-
lock, init_lock = threading.Lock(), threading.Semaphore(4)
|
| 61 |
-
LOST, GONE = "controller lost", "no controller left"
|
| 62 |
-
WAIT_LIMIT = 120 # s: a worker that started later than this after the launch doesn't count
|
| 63 |
-
MB_PER_CPU = 1900
|
| 64 |
-
# runs started in this window (`--overloaded START/END`, ISO times) ran on a model server whose
|
| 65 |
-
# KV cache was thrashing (too many agents for its GPU): the server, not the model, decided them
|
| 66 |
-
OVERLOADED: tuple[datetime, datetime] | None = None
|
| 67 |
-
# the servers' health log (`--health`: one JSON line per server and minute, with its prefix-cache
|
| 68 |
-
# hit rate): a run in which an agent's server thrashed this many minutes doesn't count
|
| 69 |
-
HEALTH: Path | None = None
|
| 70 |
-
THRASH_LIMIT = 5
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
def load(name: str, path: Path):
|
| 74 |
-
spec = importlib.util.spec_from_file_location(name, path)
|
| 75 |
-
module = importlib.util.module_from_spec(spec)
|
| 76 |
-
spec.loader.exec_module(module)
|
| 77 |
-
return module
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
team = load("team", HERE.parent / "team.py")
|
| 81 |
-
metrics = load("metrics", DATASET_DIR / "eval" / "metrics.py")
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
def say(*parts) -> None:
|
| 85 |
-
with lock:
|
| 86 |
-
print(datetime.now(UTC).strftime("%H:%M:%S"), *parts, flush=True)
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
def numbers(text: str) -> list[int]:
|
| 90 |
-
"""`1-32` or `1,3,7` -> the numbers."""
|
| 91 |
-
out = []
|
| 92 |
-
for part in text.split(","):
|
| 93 |
-
a, _, b = part.partition("-")
|
| 94 |
-
out += range(int(a), int(b or a) + 1)
|
| 95 |
-
return out
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
def legion(run_dir: Path, *args: str, timeout: float = 3600) -> subprocess.CompletedProcess:
|
| 99 |
-
env = {**os.environ, "LEGION_RUN_DIR": str(run_dir)}
|
| 100 |
-
env.pop("VIRTUAL_ENV", None)
|
| 101 |
-
return subprocess.run([str(Path(sys.executable).with_name("legion")), *args], cwd=REPO,
|
| 102 |
-
env=env, capture_output=True, text=True, timeout=timeout, check=False)
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
CPUS_PER_AGENT = 1 # --cpus-per-agent; memory follows at MB_PER_CPU
|
| 106 |
-
HINT = False # --hint: every team gets team.py's protocol hint (team.md as its team_file)
|
| 107 |
-
MEMORY_LADDER: dict | None = None # --memory-ladder: the workers' rotate/drain/preempt fractions
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
def worker_cpus(n: int) -> int:
|
| 111 |
-
"""CPUS_PER_AGENT per agent's container, a quarter of one per maze service, two for the
|
| 112 |
-
worker, podman and the image builds."""
|
| 113 |
-
return max(4, CPUS_PER_AGENT * n + 2 + (n + 3) // 4)
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
def exit_branch(tree: int) -> int:
|
| 117 |
-
"""Which of the start room's doors (1, 2 or 3, in the listed order) leads to the exit."""
|
| 118 |
-
layout = json.loads((DATASET_DIR / "tasks" / f"maze-t{tree:02d}" / "environment" / "maze"
|
| 119 |
-
/ "tree.json").read_text())
|
| 120 |
-
path = load("generate", DATASET_DIR / "generate.py").shortest_path(layout)
|
| 121 |
-
return layout["doors"][layout["start"]].index(path[0]) + 1
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
def write_experiment(src: Path, tree: int, n: int, name: str, urls: list[str], model: str,
|
| 125 |
-
revision: str) -> None:
|
| 126 |
-
"""team.py's cluster spec at the dataset `revision`, with the sweep's model on its servers
|
| 127 |
-
and a worker sized to the team, as swarm `name`; with HINT, the protocol hint as its
|
| 128 |
-
team_file."""
|
| 129 |
-
team.main(["--tree", str(tree), "--agents", str(n), "--where", "cluster",
|
| 130 |
-
"--revision", revision, "--out", str(src)] + (["--hint"] if HINT else []))
|
| 131 |
-
spec = yaml.safe_load((src / "spec.yaml").read_text())
|
| 132 |
-
spec["name"] = name
|
| 133 |
-
spec["model"] = model
|
| 134 |
-
spec["inference"] = {"urls": urls} # no key: the servers take none
|
| 135 |
-
cpus = worker_cpus(n)
|
| 136 |
-
spec["compute"] |= {"cpus": cpus, "mem": f"{cpus * MB_PER_CPU}M"}
|
| 137 |
-
if MEMORY_LADDER: # an agent's runaway process spikes the worker's memory (podman can't
|
| 138 |
-
# cap a container here): drain or rotate later, so the spike doesn't end the run
|
| 139 |
-
spec["workers"].setdefault("worker", {})["memory"] = dict(MEMORY_LADDER)
|
| 140 |
-
(src / "spec.yaml").write_text(
|
| 141 |
-
f"# {spec['task']['selector']} with N = {n} for the scaling sweep (sweep.py): team.py's "
|
| 142 |
-
f"cluster spec with {model} on the sweep's servers.\n" + yaml.safe_dump(spec,
|
| 143 |
-
sort_keys=False))
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
def profile(root: Path) -> Path:
|
| 147 |
-
"""The cluster profile: hopper-cpu, the venv, podman pulling Docker Hub images through a
|
| 148 |
-
mirror (registries.conf), and 15 minutes (not 5) for a controller to come up: with a hundred
|
| 149 |
-
teams starting at once, its imports from the shared disk can take minutes."""
|
| 150 |
-
path = root / "profiles" / "cluster.env"
|
| 151 |
-
path.parent.mkdir(parents=True, exist_ok=True)
|
| 152 |
-
path.write_text(f"SLURM_PARTITION=hopper-cpu\nSLURM_MAX_MEM_PER_CPU_MB=2000\n"
|
| 153 |
-
f"VENV={REPO / '.venv'}\n"
|
| 154 |
-
f"CONTAINERS_REGISTRIES_CONF={HERE.parent / 'registries.conf'}\n"
|
| 155 |
-
"HEALTH_WAIT_S=900\n")
|
| 156 |
-
path.chmod(0o644)
|
| 157 |
-
return path
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
def serving(url: str) -> bool:
|
| 161 |
-
"""The model server answers `GET /models`."""
|
| 162 |
-
try:
|
| 163 |
-
return httpx.get(f"{url.rstrip('/')}/models", timeout=10).status_code == 200
|
| 164 |
-
except httpx.HTTPError:
|
| 165 |
-
return False
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
def job_state(name: str) -> str:
|
| 169 |
-
"""The Slurm state of the job called `name`, '' when there is none."""
|
| 170 |
-
out = subprocess.run(["squeue", "-h", "-n", name, "-o", "%T"], capture_output=True,
|
| 171 |
-
text=True, check=False).stdout.split()
|
| 172 |
-
return out[0] if out else ""
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
def wait_done(run_dir: Path, task: str, n: int, timeout: float) -> str:
|
| 176 |
-
"""Poll `legion status` until the first exit stopped the run and its Trials are graded
|
| 177 |
-
('success'), or the loop is done and every agent is idle ('done'): or why not. A controller
|
| 178 |
-
that stops answering and isn't running (a spot reclaim requeued it, or it is gone) is LOST."""
|
| 179 |
-
deadline, unanswered, stopped = time.monotonic() + timeout, 0, None
|
| 180 |
-
while time.monotonic() < deadline:
|
| 181 |
-
# a worker that hasn't started WAIT_LIMIT after its launch can't count: stop waiting
|
| 182 |
-
# for the team now, so it runs again at once, rather than after its whole time cap
|
| 183 |
-
launches = list((run_dir / "launch").glob("*.env"))
|
| 184 |
-
if (launches and not any((run_dir / "logs").glob("*-agent-w*.out"))
|
| 185 |
-
and time.time() - min(p.stat().st_mtime for p in launches) > WAIT_LIMIT + 60):
|
| 186 |
-
return f"worker not started {WAIT_LIMIT + 60} s after its launch"
|
| 187 |
-
status = legion(run_dir, "status", task, timeout=120)
|
| 188 |
-
text = status.stdout
|
| 189 |
-
unanswered = unanswered + 1 if status.returncode != 0 else 0
|
| 190 |
-
if unanswered >= 3 and job_state(f"legion-ctl-{task}") != "RUNNING":
|
| 191 |
-
return LOST
|
| 192 |
-
if re.search(r"crashloop|launch_refused", text):
|
| 193 |
-
return "worker failed: " + " ".join(text.split())[:300]
|
| 194 |
-
if m := re.search(r"STOPPED ON SUCCESS: .*verification: (\w+)", text):
|
| 195 |
-
stopped = stopped or time.monotonic()
|
| 196 |
-
graded = m[1] != "pending" and not job_state(f"{task}-agent-w0000")
|
| 197 |
-
if graded or time.monotonic() - stopped > 600: # the cleanup budget is 5 min
|
| 198 |
-
return "success"
|
| 199 |
-
elif re.search(r"^loop agent: done", text, re.MULTILINE) and (agents := re.search(
|
| 200 |
-
r"^agent .*$", text, re.MULTILINE)) and "working:" not in agents[0]:
|
| 201 |
-
return "done" # no agent in a turn (idle, or stuck: a turn that timed out)
|
| 202 |
-
time.sleep(20)
|
| 203 |
-
return f"not done after {timeout:.0f} s"
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
def release(run_dir: Path, name: str) -> bool:
|
| 207 |
-
"""`legion stop --release`: drains (and so grades) a run nobody won and ends its
|
| 208 |
-
controller; then make sure no job of the run is left."""
|
| 209 |
-
out = legion(run_dir, "stop", name, "--release")
|
| 210 |
-
# once the worker is gone its results are on the shared disk: a controller still up a
|
| 211 |
-
# minute later (it sometimes outlives the release) only holds the team's slot, and SIGTERM
|
| 212 |
-
# makes it push its state and exit
|
| 213 |
-
for job, wait in ((f"{name}-agent-w0000", 900), (f"legion-ctl-{name}", 60)):
|
| 214 |
-
for _ in range(wait // 10): # a draining worker is still grading its Trials
|
| 215 |
-
if not job_state(job):
|
| 216 |
-
break
|
| 217 |
-
time.sleep(10)
|
| 218 |
-
else:
|
| 219 |
-
say(name, f"{job} still there after the release: cancelling it")
|
| 220 |
-
subprocess.run(["scancel", "-n", job], check=False)
|
| 221 |
-
return out.returncode == 0
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
def attempt(args, root: Path, secrets: Path, tree: int, n: int, name: str,
|
| 225 |
-
urls: list[str]) -> dict | None:
|
| 226 |
-
"""One run of a team as swarm `name` on the servers `urls`: its row, or None when it could
|
| 227 |
-
not start."""
|
| 228 |
-
run_dir, src = root / "runs" / name, root / "src" / name
|
| 229 |
-
if run_dir.exists() and (any((run_dir / "launch").glob("*.env"))
|
| 230 |
-
or (run_dir / "hosts" / "controller.host").exists()):
|
| 231 |
-
# a previous driver launched it and stopped before its row: finish it from here (its
|
| 232 |
-
# time cap counts from its own start, cluster.env's), or, with its controller gone,
|
| 233 |
-
# score what it left
|
| 234 |
-
alive = bool(job_state(f"legion-ctl-{name}"))
|
| 235 |
-
say(name, "adopting the run a previous driver launched" + ("" if alive else
|
| 236 |
-
" (no controller left)"))
|
| 237 |
-
return finish(args, run_dir, name, tree, n, (run_dir / "cluster.env").stat().st_mtime,
|
| 238 |
-
None if alive else GONE)
|
| 239 |
-
if run_dir.exists():
|
| 240 |
-
shutil.rmtree(run_dir) # init failed before: nothing ran
|
| 241 |
-
started = time.time()
|
| 242 |
-
# servers retired while the grid drained (or down) are left out, e.g. for a rerun
|
| 243 |
-
urls = [u for u in urls if serving(u)] or [u for u in args.urls if serving(u)] or urls
|
| 244 |
-
write_experiment(src, tree, n, name, urls, args.model, args.revision)
|
| 245 |
-
log = root / "logs" / f"{name}-init.log"
|
| 246 |
-
log.parent.mkdir(parents=True, exist_ok=True)
|
| 247 |
-
for tries in range(6): # its checks probe the model servers, which may be busy
|
| 248 |
-
with init_lock: # a few at a time: many at once race on the bucket's write check
|
| 249 |
-
init = legion(run_dir, "init", str(run_dir), "--from", str(src), "--profile",
|
| 250 |
-
str(profile(root)), "--secrets", str(secrets))
|
| 251 |
-
log.write_text(init.stdout + init.stderr)
|
| 252 |
-
if init.returncode == 0:
|
| 253 |
-
break
|
| 254 |
-
time.sleep(30 * (tries + 1))
|
| 255 |
-
else:
|
| 256 |
-
failed = [x for x in init.stdout.splitlines() if x.startswith("FAIL")]
|
| 257 |
-
say(name, "init failed 6 times:", failed or init.stdout[-300:], "(log:", log, ")")
|
| 258 |
-
return None
|
| 259 |
-
say(name, "launching")
|
| 260 |
-
launch = legion(run_dir, "launch", str(run_dir / "experiment"))
|
| 261 |
-
if launch.returncode != 0:
|
| 262 |
-
say(name, "launch failed:", launch.stdout[-600:], launch.stderr[-600:])
|
| 263 |
-
return finish(args, run_dir, name, tree, n, started, "launch")
|
| 264 |
-
return finish(args, run_dir, name, tree, n, started)
|
| 265 |
-
|
| 266 |
-
|
| 267 |
-
def finish(args, run_dir: Path, name: str, tree: int, n: int, started: float,
|
| 268 |
-
why: str | None = None) -> dict:
|
| 269 |
-
"""Wait for a launched team, release it (its Trials are graded, its controller ends) and
|
| 270 |
-
make its row."""
|
| 271 |
-
why = why or wait_done(run_dir, name, n, max(0.0, args.team_timeout - (time.time() - started)))
|
| 272 |
-
if why == LOST: # nothing to release: end its jobs, and the team runs again
|
| 273 |
-
say(name, "controller lost (spot reclaim?): cancelling its jobs")
|
| 274 |
-
for job in (f"legion-ctl-{name}", f"{name}-agent-w0000"):
|
| 275 |
-
subprocess.run(["scancel", "-n", job], check=False)
|
| 276 |
-
released = False
|
| 277 |
-
elif why == GONE: # its rewards and export are on disk, or it doesn't count
|
| 278 |
-
released = False
|
| 279 |
-
else:
|
| 280 |
-
say(name, "outcome:", why, "- releasing")
|
| 281 |
-
released = release(run_dir, name)
|
| 282 |
-
ended = time.time()
|
| 283 |
-
return metrics.row(run_dir) | {
|
| 284 |
-
"model": args.model, "tree": tree, "exit_branch": exit_branch(tree),
|
| 285 |
-
"wall_s": round(ended - started, 1), "outcome": why, "released": released,
|
| 286 |
-
# each launch of the worker slot writes one env file: more than one is a relaunch or a
|
| 287 |
-
# preemption, whose results a later incarnation overwrites (legion#121)
|
| 288 |
-
"incarnations": len(list((run_dir / "launch").glob("*.env"))),
|
| 289 |
-
"worker_wait_s": worker_wait(run_dir),
|
| 290 |
-
"thrashed_min": thrashed_minutes(run_dir, n, started, ended),
|
| 291 |
-
"started_at": datetime.fromtimestamp(started, UTC).isoformat()}
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
def thrashed_minutes(run_dir: Path, n: int, start: float, end: float) -> int | None:
|
| 295 |
-
"""Minutes, within the run, in which a server one of its agents calls was thrashing: a
|
| 296 |
-
prefix-cache hit rate under 50% while prefilling at least 200k prompt tokens (every call
|
| 297 |
-
recomputing an agent's long context; a cold server's first small prompts don't count), from
|
| 298 |
-
the health log (`--health`); None without one."""
|
| 299 |
-
spec = run_dir / "experiment" / "spec.yaml"
|
| 300 |
-
if HEALTH is None or not HEALTH.is_file() or not spec.is_file():
|
| 301 |
-
return None
|
| 302 |
-
urls = yaml.safe_load(spec.read_text())["inference"]["urls"]
|
| 303 |
-
servers = {u.split("//")[1].removesuffix("/v1") for u in agents_on(urls, n, run_dir.name)}
|
| 304 |
-
minutes = set()
|
| 305 |
-
for line in HEALTH.read_text().splitlines():
|
| 306 |
-
s = json.loads(line)
|
| 307 |
-
if (start <= s["t"] <= end and s["server"] in servers and s["hit_rate"] is not None
|
| 308 |
-
and s["hit_rate"] < 0.5 and s["prompt"] >= 200_000):
|
| 309 |
-
minutes.add(int(s["t"] // 60))
|
| 310 |
-
return len(minutes)
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
def worker_wait(run_dir: Path) -> float | None:
|
| 314 |
-
"""Seconds from the controller writing the worker's first launch file to the worker job's
|
| 315 |
-
first log line (None: not known)."""
|
| 316 |
-
launches = sorted((run_dir / "launch").glob("*.env"), key=lambda p: p.stat().st_mtime)
|
| 317 |
-
logs = sorted((run_dir / "logs").glob("*-agent-w*.out"))
|
| 318 |
-
if not launches or not logs:
|
| 319 |
-
return None
|
| 320 |
-
first = logs[0].read_text(errors="replace").split("\n", 1)[0]
|
| 321 |
-
try:
|
| 322 |
-
began = datetime.fromisoformat(first.split(" ", 1)[0])
|
| 323 |
-
except ValueError:
|
| 324 |
-
return None
|
| 325 |
-
return round(began.timestamp() - launches[0].stat().st_mtime, 1)
|
| 326 |
-
|
| 327 |
-
|
| 328 |
-
def why_invalid(row: dict) -> str:
|
| 329 |
-
"""Why a team's run doesn't count ('' when it does): the infrastructure's failures, never the
|
| 330 |
-
model's."""
|
| 331 |
-
wait = row.get("worker_wait_s")
|
| 332 |
-
started = datetime.fromisoformat(row["started_at"]) if row.get("started_at") else None
|
| 333 |
-
overloaded = bool(OVERLOADED and started and OVERLOADED[0] <= started < OVERLOADED[1])
|
| 334 |
-
thrashed = row.get("thrashed_min") or 0
|
| 335 |
-
return "; ".join(why for why, bad in (
|
| 336 |
-
("ran on an overloaded model server (KV-cache thrash)", overloaded),
|
| 337 |
-
(f"an agent's model server thrashed for {thrashed} min", thrashed >= THRASH_LIMIT),
|
| 338 |
-
(f"{row.get('incarnations')} worker incarnations", row.get("incarnations") != 1),
|
| 339 |
-
("worker never started", wait is None),
|
| 340 |
-
(f"worker started {wait or 0:.0f} s after the launch", (wait or 0) > WAIT_LIMIT),
|
| 341 |
-
(LOST, row.get("outcome") == LOST),
|
| 342 |
-
(f"missing {', '.join(row['missing'])}"[:160], bool(row["missing"]))) if bad)
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
def valid(row: dict) -> bool:
|
| 346 |
-
return not why_invalid(row)
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
def run_team(args, root: Path, secrets: Path, tree: int, n: int, urls: list[str],
|
| 350 |
-
slots: "Slots", held: dict) -> dict | None:
|
| 351 |
-
"""A team, run again (as `<task>-rK`) until its run counts. `held["run"]` is the run name its
|
| 352 |
-
server capacity is reserved under: each attempt moves the reservation to its own name, since
|
| 353 |
-
legion hashes agents by run and name (a rerun's agents land on other servers)."""
|
| 354 |
-
task = f"{args.tag}maze-t{tree:02d}-n{n:02d}"
|
| 355 |
-
row = None
|
| 356 |
-
for reruns in range(args.max_reruns + 1):
|
| 357 |
-
name = task if reruns == 0 else f"{task}-r{reruns}"
|
| 358 |
-
if name != held["run"] and (not (root / "runs" / name).exists()
|
| 359 |
-
or job_state(f"legion-ctl-{name}")):
|
| 360 |
-
slots.give(n, held["run"], urls) # a finished attempt is only scored again: keep
|
| 361 |
-
held["run"] = name
|
| 362 |
-
slots.take(n, name, urls if job_state(f"legion-ctl-{name}") else None)
|
| 363 |
-
row = attempt(args, root, secrets, tree, n, name, urls)
|
| 364 |
-
if row is None:
|
| 365 |
-
return None
|
| 366 |
-
row["reruns"] = reruns
|
| 367 |
-
if valid(row):
|
| 368 |
-
break
|
| 369 |
-
say(task, f"run doesn't count ({why_invalid(row)}): running it again")
|
| 370 |
-
row["set_aside"] = why_invalid(row)
|
| 371 |
-
with lock, (root / "rows-discarded.jsonl").open("a") as f:
|
| 372 |
-
f.write(json.dumps(row) + "\n")
|
| 373 |
-
else:
|
| 374 |
-
say(task, f"gave up after {args.max_reruns} reruns")
|
| 375 |
-
return row
|
| 376 |
-
with lock, (root / "rows.jsonl").open("a") as f:
|
| 377 |
-
f.write(json.dumps(row) + "\n")
|
| 378 |
-
first = row.get("first_exit") or {}
|
| 379 |
-
say(task, f"success={row['success']} exit={first.get('agent')} after "
|
| 380 |
-
f"{first.get('after_s')} s, {first.get('team_moves')} team moves; posts={row['posts']} "
|
| 381 |
-
f"overlap={row.get('room_overlap')} wall={row['wall_s']} s reruns={row['reruns']}")
|
| 382 |
-
return row
|
| 383 |
-
|
| 384 |
-
|
| 385 |
-
def agents_on(urls: list[str], n: int, run: str) -> Counter:
|
| 386 |
-
"""How many of run `run`'s agents (agent-001 .. agent-00N) call each server: legion hashes
|
| 387 |
-
each agent's run and name over the URLs (Inference.endpoint_for, legion#129), so teams on one
|
| 388 |
-
shared list spread over its servers."""
|
| 389 |
-
block = Inference(urls=urls)
|
| 390 |
-
return Counter(block.endpoint_for(run, f"agent-{k:03d}") for k in range(1, n + 1))
|
| 391 |
-
|
| 392 |
-
|
| 393 |
-
class Slots:
|
| 394 |
-
"""At most `parallel` teams, `max_agents` agents and `per_server` agents per model server
|
| 395 |
-
(`<root>/max_agents` and `<root>/per_server` override them while the driver runs) in flight,
|
| 396 |
-
granted in order. Every team gets the whole shared list; legion (#129) spreads its agents over
|
| 397 |
-
it by run and name, and a team waits until the servers its agents land on have room (one
|
| 398 |
-
server's KV cache holds about a dozen long agent contexts)."""
|
| 399 |
-
|
| 400 |
-
def __init__(self, root: Path, urls: list[str], parallel: int, max_agents: int,
|
| 401 |
-
per_server: int):
|
| 402 |
-
self.root, self.urls, self.parallel = root, urls, parallel
|
| 403 |
-
self.defaults = {"max_agents": max_agents, "per_server": per_server}
|
| 404 |
-
self.cond, self.teams, self.agents, self.load = threading.Condition(), 0, 0, Counter()
|
| 405 |
-
|
| 406 |
-
def cap(self, name: str) -> int:
|
| 407 |
-
try:
|
| 408 |
-
return int((self.root / name).read_text().strip())
|
| 409 |
-
except (OSError, ValueError):
|
| 410 |
-
return self.defaults[name]
|
| 411 |
-
|
| 412 |
-
def take(self, n: int, run: str, urls: list[str] | None = None) -> list[str]:
|
| 413 |
-
"""Wait for room for team `run` of n (its agents' servers within the cap); `urls`: an
|
| 414 |
-
adopted team's own (it already runs)."""
|
| 415 |
-
chosen = urls or list(self.urls)
|
| 416 |
-
added = agents_on(chosen, n, run)
|
| 417 |
-
with self.cond:
|
| 418 |
-
while not (self.teams < self.parallel and (
|
| 419 |
-
not self.agents or urls is not None or (
|
| 420 |
-
self.agents + n <= self.cap("max_agents")
|
| 421 |
-
and all(self.load[u] + k <= self.cap("per_server")
|
| 422 |
-
for u, k in added.items())))):
|
| 423 |
-
self.cond.wait(30)
|
| 424 |
-
self.teams, self.agents = self.teams + 1, self.agents + n
|
| 425 |
-
self.load += added
|
| 426 |
-
return chosen
|
| 427 |
-
|
| 428 |
-
def give(self, n: int, run: str, urls: list[str]) -> None:
|
| 429 |
-
with self.cond:
|
| 430 |
-
self.teams, self.agents = self.teams - 1, self.agents - n
|
| 431 |
-
self.load -= agents_on(urls, n, run)
|
| 432 |
-
self.cond.notify_all()
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
def live_run(root: Path, tag: str, tree: int, n: int) -> tuple[str, list[str] | None]:
|
| 436 |
-
"""The run of a team that a stopped driver launched and whose controller is still there,
|
| 437 |
-
with its URLs (it keeps them); else the team's first run name and None."""
|
| 438 |
-
for spec in sorted((root / "src").glob(f"{tag}maze-t{tree:02d}-n{n:02d}*/spec.yaml")):
|
| 439 |
-
if job_state(f"legion-ctl-{spec.parent.name}"):
|
| 440 |
-
return spec.parent.name, yaml.safe_load(spec.read_text())["inference"]["urls"]
|
| 441 |
-
return f"{tag}maze-t{tree:02d}-n{n:02d}", None
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
def upload(root: Path, dataset: str, prefix: str) -> None:
|
| 445 |
-
"""Each run directory's spec, results and logs, and the rows, to a private dataset; never
|
| 446 |
-
run.env, and nothing that holds a Hub token."""
|
| 447 |
-
api = HfApi()
|
| 448 |
-
api.create_repo(dataset, repo_type="dataset", private=True, exist_ok=True)
|
| 449 |
-
if not api.dataset_info(dataset).private:
|
| 450 |
-
raise SystemExit(f"{dataset} is public: refusing to upload")
|
| 451 |
-
allow = ["*.jsonl", "*.csv", "*.md", "*.png", "runs/*/experiment/**", "runs/*/results/**",
|
| 452 |
-
"runs/*/logs/**", "driver.log"]
|
| 453 |
-
leaks = [str(p) for p in root.rglob("*") if p.is_file() and not p.name.endswith(".env")
|
| 454 |
-
and SECRET.search(p.read_text(errors="ignore"))]
|
| 455 |
-
if leaks:
|
| 456 |
-
raise SystemExit(f"refusing to upload: Hub tokens in {leaks[:5]}")
|
| 457 |
-
api.upload_folder(repo_id=dataset, repo_type="dataset", folder_path=root,
|
| 458 |
-
path_in_repo=prefix, allow_patterns=allow,
|
| 459 |
-
commit_message=f"s3-maze sweep: {prefix}")
|
| 460 |
-
say("uploaded", root, "to", f"{dataset}/{prefix}")
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
def main(argv=None) -> int:
|
| 464 |
-
parser = argparse.ArgumentParser(description=__doc__.split("\n")[0])
|
| 465 |
-
parser.add_argument("--urls", required=True, help="the model servers, comma-separated")
|
| 466 |
-
parser.add_argument("--model", required=True)
|
| 467 |
-
parser.add_argument("--tag", required=True,
|
| 468 |
-
help="put before every run and swarm name (e.g. q27-): two grids at "
|
| 469 |
-
"once then never share a Slurm job name")
|
| 470 |
-
parser.add_argument("--revision", help="the dataset revision every team pins (default: its "
|
| 471 |
-
"head)")
|
| 472 |
-
parser.add_argument("--trees", default="1-32")
|
| 473 |
-
parser.add_argument("--agents", default="1,2,4,8,16")
|
| 474 |
-
parser.add_argument("--parallel", type=int, default=20, help="teams at once")
|
| 475 |
-
parser.add_argument("--max-agents", type=int, default=1000, help="agents at once")
|
| 476 |
-
parser.add_argument("--per-server", type=int, default=1000,
|
| 477 |
-
help="agents at once per model server (a team waits until the servers "
|
| 478 |
-
"its agents hash to are within it)")
|
| 479 |
-
parser.add_argument("--team-timeout", type=float, default=4800,
|
| 480 |
-
help="s from a team's start until it is released anyway")
|
| 481 |
-
parser.add_argument("--max-reruns", type=int, default=4,
|
| 482 |
-
help="runs again of a team whose run doesn't count (why_invalid)")
|
| 483 |
-
parser.add_argument("--root", type=Path, required=True)
|
| 484 |
-
parser.add_argument("--bucket", default="lewtun/s3-maze-sweep",
|
| 485 |
-
help="private bucket for the runs' state (a swarm's name is used once "
|
| 486 |
-
"in a bucket)")
|
| 487 |
-
parser.add_argument("--namespace", default="lewtun")
|
| 488 |
-
parser.add_argument("--dataset", help="private dataset for the run directories")
|
| 489 |
-
parser.add_argument("--prefix", help="folder in the dataset (default: the root's name)")
|
| 490 |
-
parser.add_argument("--overloaded", help="START/END (ISO times): runs started then ran on "
|
| 491 |
-
"an overloaded model server, and run again")
|
| 492 |
-
parser.add_argument("--health", type=Path,
|
| 493 |
-
help="the servers' health log (health-log.sh's servers.jsonl)")
|
| 494 |
-
parser.add_argument("--cpus-per-agent", type=int, default=1,
|
| 495 |
-
help="worker CPUs (and so memory, at 1900 MB each) per agent")
|
| 496 |
-
parser.add_argument("--memory-ladder", help="ROTATE,DRAIN,PREEMPT: the workers' memory "
|
| 497 |
-
"fractions (default: legion's 0.75,0.85,0.93)")
|
| 498 |
-
parser.add_argument("--hint", action="store_true",
|
| 499 |
-
help="every team gets the protocol hint (team.py --hint)")
|
| 500 |
-
args = parser.parse_args(argv)
|
| 501 |
-
global HEALTH, CPUS_PER_AGENT, MEMORY_LADDER, HINT
|
| 502 |
-
HEALTH, HINT = args.health, args.hint
|
| 503 |
-
CPUS_PER_AGENT = args.cpus_per_agent
|
| 504 |
-
if args.memory_ladder:
|
| 505 |
-
MEMORY_LADDER = dict(zip(("rotate", "drain", "preempt"),
|
| 506 |
-
map(float, args.memory_ladder.split(",")), strict=True))
|
| 507 |
-
if args.overloaded:
|
| 508 |
-
global OVERLOADED
|
| 509 |
-
start, end = (datetime.fromisoformat(t) for t in args.overloaded.split("/"))
|
| 510 |
-
OVERLOADED = (start, end)
|
| 511 |
-
args.urls = args.urls.split(",")
|
| 512 |
-
args.revision = team.pinned(args.revision)
|
| 513 |
-
root = args.root.resolve()
|
| 514 |
-
root.mkdir(parents=True, exist_ok=True)
|
| 515 |
-
api = HfApi()
|
| 516 |
-
api.create_bucket(args.bucket, private=True, exist_ok=True)
|
| 517 |
-
if not api.bucket_info(args.bucket).private:
|
| 518 |
-
raise SystemExit(f"bucket {args.bucket} is public: refusing")
|
| 519 |
-
token = os.environ.get("HF_TOKEN") or get_token()
|
| 520 |
-
secrets = root / f"secrets-{os.getpid()}.env" # per driver
|
| 521 |
-
old = os.umask(0o077)
|
| 522 |
-
secrets.write_text(f"HF_TOKEN={token}\nNAMESPACE={args.namespace}\n"
|
| 523 |
-
f"BUCKET=hf://buckets/{args.bucket}\n")
|
| 524 |
-
os.umask(old)
|
| 525 |
-
rows_file = root / "rows.jsonl"
|
| 526 |
-
rows = [json.loads(x) for x in rows_file.read_text().splitlines()] if rows_file.exists() else []
|
| 527 |
-
for r in rows: # rows from before the health check get it too
|
| 528 |
-
if r.get("thrashed_min") is None and r.get("started_at") and r.get("wall_s"):
|
| 529 |
-
start = datetime.fromisoformat(r["started_at"]).timestamp()
|
| 530 |
-
r["thrashed_min"] = thrashed_minutes(root / "runs" / r["run"], r["agents"], start,
|
| 531 |
-
start + r["wall_s"])
|
| 532 |
-
if bad := [r for r in rows if not valid(r)]: # an earlier driver kept them: run them again
|
| 533 |
-
with (root / "rows-discarded.jsonl").open("a") as f:
|
| 534 |
-
f.write("".join(json.dumps(r | {"set_aside": why_invalid(r)}) + "\n" for r in bad))
|
| 535 |
-
rows_file.write_text("".join(json.dumps(r) + "\n" for r in rows if valid(r)))
|
| 536 |
-
say(f"{len(bad)} rows that don't count moved to rows-discarded.jsonl")
|
| 537 |
-
done = {(r["tree"], r["agents"]) for r in rows if valid(r)}
|
| 538 |
-
teams = [(t, n) for t in numbers(args.trees) for n in numbers(args.agents)
|
| 539 |
-
if (t, n) not in done]
|
| 540 |
-
# teams a stopped driver launched first: they hold their own time and their workers
|
| 541 |
-
launched = {(t, n) for t, n in teams if any((root / "runs").glob(
|
| 542 |
-
f"{args.tag}maze-t{t:02d}-n{n:02d}*/launch/*.env"))}
|
| 543 |
-
teams.sort(key=lambda t: t not in launched)
|
| 544 |
-
say(f"{len(teams)} teams to run ({len(done)} done, {len(launched)} to adopt), "
|
| 545 |
-
f"{args.parallel} teams and {args.max_agents} agents at once, on {args.urls}")
|
| 546 |
-
slots = Slots(root, args.urls, args.parallel, args.max_agents, args.per_server)
|
| 547 |
-
|
| 548 |
-
def one(t: int, n: int, urls: list[str], held: dict):
|
| 549 |
-
try:
|
| 550 |
-
return run_team(args, root, secrets, t, n, urls, slots, held)
|
| 551 |
-
except Exception as e: # noqa: BLE001 - one team's failure must not stop the grid
|
| 552 |
-
say(f"{args.tag}maze-t{t:02d}-n{n:02d}", "failed:", repr(e)[:300])
|
| 553 |
-
finally:
|
| 554 |
-
slots.give(n, held["run"], urls)
|
| 555 |
-
|
| 556 |
-
try:
|
| 557 |
-
with ThreadPoolExecutor(args.parallel) as pool:
|
| 558 |
-
for t, n in teams:
|
| 559 |
-
run, live = live_run(root, args.tag, t, n)
|
| 560 |
-
urls = slots.take(n, run, live)
|
| 561 |
-
pool.submit(one, t, n, urls, {"run": run})
|
| 562 |
-
finally:
|
| 563 |
-
secrets.unlink(missing_ok=True)
|
| 564 |
-
if args.dataset:
|
| 565 |
-
upload(root, args.dataset, args.prefix or root.name)
|
| 566 |
-
return 0
|
| 567 |
-
|
| 568 |
-
|
| 569 |
-
if __name__ == "__main__":
|
| 570 |
-
sys.exit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
legion/team.md
DELETED
|
@@ -1 +0,0 @@
|
|
| 1 |
-
Before you go through a door, read the board and post which door you are taking; pick one no teammate has claimed; post when a branch is a dead end.
|
|
|
|
|
|
legion/team.py
DELETED
|
@@ -1,101 +0,0 @@
|
|
| 1 |
-
"""Write the Legion spec for one s3-maze team, from Legion's checkout (it needs Legion):
|
| 2 |
-
|
| 3 |
-
uv run python <this dataset>/legion/team.py --tree 7 --agents 4 [--where cluster|docker]
|
| 4 |
-
|
| 5 |
-
writes `out/maze-t07-n04/spec.yaml` next to this script (or `--out DIR`) from
|
| 6 |
-
spec.template.yaml: the tree `maze-t07` at `--revision` (default: the dataset's head on the
|
| 7 |
-
Hub), its 4 agents (agent-001 .. agent-004) all on that tree, on one worker with one board, and
|
| 8 |
-
`stop_on_success` with the maze service's success check. `--where` picks the template's
|
| 9 |
-
`where:` block: the HF cluster (Slurm, rootless podman, a worker of N + 2 CPUs) or local docker.
|
| 10 |
-
`--hint` adds the protocol hint (team.md, next to this script) as the team's `team_file`.
|
| 11 |
-
The dataset is private for now: HF_TOKEN must read it.
|
| 12 |
-
"""
|
| 13 |
-
|
| 14 |
-
import argparse
|
| 15 |
-
import copy
|
| 16 |
-
import shutil
|
| 17 |
-
import sys
|
| 18 |
-
from pathlib import Path
|
| 19 |
-
|
| 20 |
-
import yaml
|
| 21 |
-
from huggingface_hub import HfApi
|
| 22 |
-
|
| 23 |
-
from legion.models import load_spec_yaml
|
| 24 |
-
|
| 25 |
-
HERE = Path(__file__).resolve().parent
|
| 26 |
-
DATASET = "HuggingFaceSwarms/s3-maze"
|
| 27 |
-
TREES, SIZES = range(1, 33), (1, 2, 4, 8, 16)
|
| 28 |
-
MB_PER_CPU = 1900 # hopper-cpu's MaxMemPerCPU is 2000
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
def merge(base: dict, extra: dict) -> dict:
|
| 32 |
-
out = dict(base)
|
| 33 |
-
for key, value in extra.items():
|
| 34 |
-
both = isinstance(value, dict) and isinstance(out.get(key), dict)
|
| 35 |
-
out[key] = merge(out[key], value) if both else value
|
| 36 |
-
return out
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
def fill(value, names: dict[str, str]):
|
| 40 |
-
if isinstance(value, dict):
|
| 41 |
-
return {k: fill(v, names) for k, v in value.items()}
|
| 42 |
-
if isinstance(value, list):
|
| 43 |
-
return [fill(v, names) for v in value]
|
| 44 |
-
if isinstance(value, str):
|
| 45 |
-
for placeholder, text in names.items():
|
| 46 |
-
value = value.replace(placeholder, text)
|
| 47 |
-
return value
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
def worker_cpus(agents: int) -> int:
|
| 51 |
-
"""A CPU per agent (its container), two for the worker, the maze services and builds."""
|
| 52 |
-
return max(4, agents + 2)
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
def team_spec(template: dict, tree: int, agents: int, where: str,
|
| 56 |
-
revision: str) -> tuple[str, dict]:
|
| 57 |
-
"""(the team's name, its spec) from the template."""
|
| 58 |
-
template = copy.deepcopy(template)
|
| 59 |
-
places = template.pop("where")
|
| 60 |
-
task, team = f"maze-t{tree:02d}", f"maze-t{tree:02d}-n{agents:02d}"
|
| 61 |
-
spec = fill(merge(template, places[where]),
|
| 62 |
-
{"TEAM": team, "TREE": task, "REVISION": revision})
|
| 63 |
-
spec["agents"] = {"count": agents}
|
| 64 |
-
spec["workers"]["agents_per_worker"] = agents
|
| 65 |
-
if where == "cluster":
|
| 66 |
-
cpus = worker_cpus(agents)
|
| 67 |
-
spec["compute"] |= {"cpus": cpus, "mem": f"{cpus * MB_PER_CPU}M"}
|
| 68 |
-
return team, spec
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
def pinned(revision: str | None) -> str:
|
| 72 |
-
"""The revision (default: the dataset's head) as a commit."""
|
| 73 |
-
return HfApi().dataset_info(DATASET, revision=revision).sha
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
def main(argv=None) -> int:
|
| 77 |
-
parser = argparse.ArgumentParser(description="Write one s3-maze team's Legion spec.")
|
| 78 |
-
parser.add_argument("--tree", type=int, required=True, choices=TREES)
|
| 79 |
-
parser.add_argument("--agents", type=int, required=True, choices=SIZES)
|
| 80 |
-
parser.add_argument("--where", choices=("cluster", "docker"), default="cluster")
|
| 81 |
-
parser.add_argument("--revision", help="the dataset revision to pin (default: its head)")
|
| 82 |
-
parser.add_argument("--out", type=Path, help="default: out/<team> next to this script")
|
| 83 |
-
parser.add_argument("--hint", action="store_true",
|
| 84 |
-
help="add the protocol hint (team.md) as the team's team_file")
|
| 85 |
-
args = parser.parse_args(argv)
|
| 86 |
-
template = load_spec_yaml((HERE / "spec.template.yaml").read_text())
|
| 87 |
-
team, spec = team_spec(template, args.tree, args.agents, args.where, pinned(args.revision))
|
| 88 |
-
out = args.out or HERE / "out" / team
|
| 89 |
-
out.mkdir(parents=True, exist_ok=True)
|
| 90 |
-
if args.hint:
|
| 91 |
-
shutil.copyfile(HERE / "team.md", out / "team.md")
|
| 92 |
-
spec["team_file"] = "team.md"
|
| 93 |
-
header = (f"# {team} ({args.where}), written by {DATASET}'s legion/team.py from "
|
| 94 |
-
"spec.template.yaml: edit the template, not this file.\n")
|
| 95 |
-
(out / "spec.yaml").write_text(header + yaml.safe_dump(spec, sort_keys=False, width=100))
|
| 96 |
-
print(out / "spec.yaml")
|
| 97 |
-
return 0
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
if __name__ == "__main__":
|
| 101 |
-
sys.exit(main())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tasks/maze-t01/environment/docker-compose.yaml
CHANGED
|
@@ -9,7 +9,7 @@ services:
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
-
image: s3-maze-service:maze-t01-
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
@@ -20,6 +20,6 @@ services:
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
-
default: {} # main's
|
| 24 |
maze:
|
| 25 |
internal: true
|
|
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
+
image: s3-maze-service:maze-t01-f95fbf219418
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
+
default: {} # main's egress network
|
| 24 |
maze:
|
| 25 |
internal: true
|
tasks/maze-t01/environment/maze/service.py
CHANGED
|
@@ -6,7 +6,7 @@ tree and the exit stay in this container: an agent learns a room's doors only by
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
-
answered, and the walk's state file is replaced after it: success.py (
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
|
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
+
answered, and the walk's state file is replaced after it: success.py (the exit status check)
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
tasks/maze-t01/environment/maze/success.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
"""
|
| 2 |
-
agent's container: `python3 -I -S /app/success.py`.
|
| 3 |
|
| 4 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 5 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
|
|
|
| 1 |
+
"""Read the exit status from the maze service with `python3 -I -S /app/success.py`.
|
|
|
|
| 2 |
|
| 3 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 4 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
tasks/maze-t02/environment/docker-compose.yaml
CHANGED
|
@@ -9,7 +9,7 @@ services:
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
-
image: s3-maze-service:maze-t02-
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
@@ -20,6 +20,6 @@ services:
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
-
default: {} # main's
|
| 24 |
maze:
|
| 25 |
internal: true
|
|
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
+
image: s3-maze-service:maze-t02-446d4937ddaf
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
+
default: {} # main's egress network
|
| 24 |
maze:
|
| 25 |
internal: true
|
tasks/maze-t02/environment/maze/service.py
CHANGED
|
@@ -6,7 +6,7 @@ tree and the exit stay in this container: an agent learns a room's doors only by
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
-
answered, and the walk's state file is replaced after it: success.py (
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
|
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
+
answered, and the walk's state file is replaced after it: success.py (the exit status check)
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
tasks/maze-t02/environment/maze/success.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
"""
|
| 2 |
-
agent's container: `python3 -I -S /app/success.py`.
|
| 3 |
|
| 4 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 5 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
|
|
|
| 1 |
+
"""Read the exit status from the maze service with `python3 -I -S /app/success.py`.
|
|
|
|
| 2 |
|
| 3 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 4 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
tasks/maze-t03/environment/docker-compose.yaml
CHANGED
|
@@ -9,7 +9,7 @@ services:
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
-
image: s3-maze-service:maze-t03-
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
@@ -20,6 +20,6 @@ services:
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
-
default: {} # main's
|
| 24 |
maze:
|
| 25 |
internal: true
|
|
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
+
image: s3-maze-service:maze-t03-2f1c9db92d2d
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
+
default: {} # main's egress network
|
| 24 |
maze:
|
| 25 |
internal: true
|
tasks/maze-t03/environment/maze/service.py
CHANGED
|
@@ -6,7 +6,7 @@ tree and the exit stay in this container: an agent learns a room's doors only by
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
-
answered, and the walk's state file is replaced after it: success.py (
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
|
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
+
answered, and the walk's state file is replaced after it: success.py (the exit status check)
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
tasks/maze-t03/environment/maze/success.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
"""
|
| 2 |
-
agent's container: `python3 -I -S /app/success.py`.
|
| 3 |
|
| 4 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 5 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
|
|
|
| 1 |
+
"""Read the exit status from the maze service with `python3 -I -S /app/success.py`.
|
|
|
|
| 2 |
|
| 3 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 4 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
tasks/maze-t04/environment/docker-compose.yaml
CHANGED
|
@@ -9,7 +9,7 @@ services:
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
-
image: s3-maze-service:maze-t04-
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
@@ -20,6 +20,6 @@ services:
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
-
default: {} # main's
|
| 24 |
maze:
|
| 25 |
internal: true
|
|
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
+
image: s3-maze-service:maze-t04-ff2621b36334
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
+
default: {} # main's egress network
|
| 24 |
maze:
|
| 25 |
internal: true
|
tasks/maze-t04/environment/maze/service.py
CHANGED
|
@@ -6,7 +6,7 @@ tree and the exit stay in this container: an agent learns a room's doors only by
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
-
answered, and the walk's state file is replaced after it: success.py (
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
|
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
+
answered, and the walk's state file is replaced after it: success.py (the exit status check)
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
tasks/maze-t04/environment/maze/success.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
"""
|
| 2 |
-
agent's container: `python3 -I -S /app/success.py`.
|
| 3 |
|
| 4 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 5 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
|
|
|
| 1 |
+
"""Read the exit status from the maze service with `python3 -I -S /app/success.py`.
|
|
|
|
| 2 |
|
| 3 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 4 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
tasks/maze-t05/environment/docker-compose.yaml
CHANGED
|
@@ -9,7 +9,7 @@ services:
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
-
image: s3-maze-service:maze-t05-
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
@@ -20,6 +20,6 @@ services:
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
-
default: {} # main's
|
| 24 |
maze:
|
| 25 |
internal: true
|
|
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
+
image: s3-maze-service:maze-t05-70ed430ae624
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
+
default: {} # main's egress network
|
| 24 |
maze:
|
| 25 |
internal: true
|
tasks/maze-t05/environment/maze/service.py
CHANGED
|
@@ -6,7 +6,7 @@ tree and the exit stay in this container: an agent learns a room's doors only by
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
-
answered, and the walk's state file is replaced after it: success.py (
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
|
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
+
answered, and the walk's state file is replaced after it: success.py (the exit status check)
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
tasks/maze-t05/environment/maze/success.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
"""
|
| 2 |
-
agent's container: `python3 -I -S /app/success.py`.
|
| 3 |
|
| 4 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 5 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
|
|
|
| 1 |
+
"""Read the exit status from the maze service with `python3 -I -S /app/success.py`.
|
|
|
|
| 2 |
|
| 3 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 4 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
tasks/maze-t06/environment/docker-compose.yaml
CHANGED
|
@@ -9,7 +9,7 @@ services:
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
-
image: s3-maze-service:maze-t06-
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
@@ -20,6 +20,6 @@ services:
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
-
default: {} # main's
|
| 24 |
maze:
|
| 25 |
internal: true
|
|
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
+
image: s3-maze-service:maze-t06-b899e2c5042a
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
+
default: {} # main's egress network
|
| 24 |
maze:
|
| 25 |
internal: true
|
tasks/maze-t06/environment/maze/service.py
CHANGED
|
@@ -6,7 +6,7 @@ tree and the exit stay in this container: an agent learns a room's doors only by
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
-
answered, and the walk's state file is replaced after it: success.py (
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
|
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
+
answered, and the walk's state file is replaced after it: success.py (the exit status check)
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
tasks/maze-t06/environment/maze/success.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
"""
|
| 2 |
-
agent's container: `python3 -I -S /app/success.py`.
|
| 3 |
|
| 4 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 5 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
|
|
|
| 1 |
+
"""Read the exit status from the maze service with `python3 -I -S /app/success.py`.
|
|
|
|
| 2 |
|
| 3 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 4 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
tasks/maze-t07/environment/docker-compose.yaml
CHANGED
|
@@ -9,7 +9,7 @@ services:
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
-
image: s3-maze-service:maze-t07-
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
@@ -20,6 +20,6 @@ services:
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
-
default: {} # main's
|
| 24 |
maze:
|
| 25 |
internal: true
|
|
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
+
image: s3-maze-service:maze-t07-564a0ae975bf
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
+
default: {} # main's egress network
|
| 24 |
maze:
|
| 25 |
internal: true
|
tasks/maze-t07/environment/maze/service.py
CHANGED
|
@@ -6,7 +6,7 @@ tree and the exit stay in this container: an agent learns a room's doors only by
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
-
answered, and the walk's state file is replaced after it: success.py (
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
|
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
+
answered, and the walk's state file is replaced after it: success.py (the exit status check)
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
tasks/maze-t07/environment/maze/success.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
"""
|
| 2 |
-
agent's container: `python3 -I -S /app/success.py`.
|
| 3 |
|
| 4 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 5 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
|
|
|
| 1 |
+
"""Read the exit status from the maze service with `python3 -I -S /app/success.py`.
|
|
|
|
| 2 |
|
| 3 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 4 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
tasks/maze-t08/environment/docker-compose.yaml
CHANGED
|
@@ -9,7 +9,7 @@ services:
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
-
image: s3-maze-service:maze-t08-
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
@@ -20,6 +20,6 @@ services:
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
-
default: {} # main's
|
| 24 |
maze:
|
| 25 |
internal: true
|
|
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
+
image: s3-maze-service:maze-t08-aedfe0bcc69c
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
+
default: {} # main's egress network
|
| 24 |
maze:
|
| 25 |
internal: true
|
tasks/maze-t08/environment/maze/service.py
CHANGED
|
@@ -6,7 +6,7 @@ tree and the exit stay in this container: an agent learns a room's doors only by
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
-
answered, and the walk's state file is replaced after it: success.py (
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
|
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
+
answered, and the walk's state file is replaced after it: success.py (the exit status check)
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
tasks/maze-t08/environment/maze/success.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
"""
|
| 2 |
-
agent's container: `python3 -I -S /app/success.py`.
|
| 3 |
|
| 4 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 5 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
|
|
|
| 1 |
+
"""Read the exit status from the maze service with `python3 -I -S /app/success.py`.
|
|
|
|
| 2 |
|
| 3 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 4 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
tasks/maze-t09/environment/docker-compose.yaml
CHANGED
|
@@ -9,7 +9,7 @@ services:
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
-
image: s3-maze-service:maze-t09-
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
@@ -20,6 +20,6 @@ services:
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
-
default: {} # main's
|
| 24 |
maze:
|
| 25 |
internal: true
|
|
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
+
image: s3-maze-service:maze-t09-ba69534fb0f1
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
+
default: {} # main's egress network
|
| 24 |
maze:
|
| 25 |
internal: true
|
tasks/maze-t09/environment/maze/service.py
CHANGED
|
@@ -6,7 +6,7 @@ tree and the exit stay in this container: an agent learns a room's doors only by
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
-
answered, and the walk's state file is replaced after it: success.py (
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
|
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
+
answered, and the walk's state file is replaced after it: success.py (the exit status check)
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
tasks/maze-t09/environment/maze/success.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
"""
|
| 2 |
-
agent's container: `python3 -I -S /app/success.py`.
|
| 3 |
|
| 4 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 5 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
|
|
|
| 1 |
+
"""Read the exit status from the maze service with `python3 -I -S /app/success.py`.
|
|
|
|
| 2 |
|
| 3 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 4 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
tasks/maze-t10/environment/docker-compose.yaml
CHANGED
|
@@ -9,7 +9,7 @@ services:
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
-
image: s3-maze-service:maze-t10-
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
@@ -20,6 +20,6 @@ services:
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
-
default: {} # main's
|
| 24 |
maze:
|
| 25 |
internal: true
|
|
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
+
image: s3-maze-service:maze-t10-1ee257ade8c3
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
+
default: {} # main's egress network
|
| 24 |
maze:
|
| 25 |
internal: true
|
tasks/maze-t10/environment/maze/service.py
CHANGED
|
@@ -6,7 +6,7 @@ tree and the exit stay in this container: an agent learns a room's doors only by
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
-
answered, and the walk's state file is replaced after it: success.py (
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
|
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
+
answered, and the walk's state file is replaced after it: success.py (the exit status check)
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
tasks/maze-t10/environment/maze/success.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
"""
|
| 2 |
-
agent's container: `python3 -I -S /app/success.py`.
|
| 3 |
|
| 4 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 5 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
|
|
|
| 1 |
+
"""Read the exit status from the maze service with `python3 -I -S /app/success.py`.
|
|
|
|
| 2 |
|
| 3 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 4 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
tasks/maze-t11/environment/docker-compose.yaml
CHANGED
|
@@ -9,7 +9,7 @@ services:
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
-
image: s3-maze-service:maze-t11-
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
@@ -20,6 +20,6 @@ services:
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
-
default: {} # main's
|
| 24 |
maze:
|
| 25 |
internal: true
|
|
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
+
image: s3-maze-service:maze-t11-c21af2c3f5de
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
+
default: {} # main's egress network
|
| 24 |
maze:
|
| 25 |
internal: true
|
tasks/maze-t11/environment/maze/service.py
CHANGED
|
@@ -6,7 +6,7 @@ tree and the exit stay in this container: an agent learns a room's doors only by
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
-
answered, and the walk's state file is replaced after it: success.py (
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
|
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
+
answered, and the walk's state file is replaced after it: success.py (the exit status check)
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
tasks/maze-t11/environment/maze/success.py
CHANGED
|
@@ -1,5 +1,4 @@
|
|
| 1 |
-
"""
|
| 2 |
-
agent's container: `python3 -I -S /app/success.py`.
|
| 3 |
|
| 4 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 5 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
|
|
|
| 1 |
+
"""Read the exit status from the maze service with `python3 -I -S /app/success.py`.
|
|
|
|
| 2 |
|
| 3 |
Read-only: it prints `{"success": <the exit was reached>, "evidence": {...}}` from the walk's
|
| 4 |
state file, which only service.py writes. No state yet, or one that can't be read, is not a
|
tasks/maze-t12/environment/docker-compose.yaml
CHANGED
|
@@ -9,7 +9,7 @@ services:
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
-
image: s3-maze-service:maze-t12-
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
@@ -20,6 +20,6 @@ services:
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
-
default: {} # main's
|
| 24 |
maze:
|
| 25 |
internal: true
|
|
|
|
| 9 |
security_opt: [no-new-privileges:true]
|
| 10 |
depends_on: [maze]
|
| 11 |
maze:
|
| 12 |
+
image: s3-maze-service:maze-t12-b1d1bfd933df
|
| 13 |
build:
|
| 14 |
context: ./maze
|
| 15 |
networks: [maze]
|
|
|
|
| 20 |
pids_limit: 64
|
| 21 |
mem_limit: 256m
|
| 22 |
networks:
|
| 23 |
+
default: {} # main's egress network
|
| 24 |
maze:
|
| 25 |
internal: true
|
tasks/maze-t12/environment/maze/service.py
CHANGED
|
@@ -6,7 +6,7 @@ tree and the exit stay in this container: an agent learns a room's doors only by
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
-
answered, and the walk's state file is replaced after it: success.py (
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|
|
|
|
| 6 |
and that a room is the exit only by reaching it.
|
| 7 |
|
| 8 |
Every move, accepted or refused, is appended to the move log (agent, from, to, time) before it is
|
| 9 |
+
answered, and the walk's state file is replaced after it: success.py (the exit status check)
|
| 10 |
and export.py (Harbor's collect hook, for the grader) read those two files. A restarted
|
| 11 |
container resumes from them. Python 3.10+, standard library only.
|
| 12 |
"""
|