interplane.Get Omega
Read in your language

aien-architecture-mv

Canonical architecture for the AIEN ecosystem: flows, boundaries, ADRs, and the map from design to implementation repositories.

Brought by drakestapleton

branch main Branches Tags History

aien-architecture-mv / docs / ops / MEASUREMENT_WINDOWS.md

185 lines · 11629 bytes Raw Blame History Rendered
1# Measurement windows and the shared base
2
3Several agents measure on the one Spark at the same time. When three of them timed things in parallel
4on 2026-10-19, two of the three verdicts came back INCONCLUSIVE only because the box was loaded by the
5others. Drake's rule: build once, measure the shared parts once per window, and then each agent measures
6only its own difference, one after another.
7
8The shared base is four small shell tools in `~/.local/bin` (copies in [`tools/ops/`](../../tools/ops/README.md)):
9
10| Tool | What it does |
11|---|---|
12| `spark-build-once` | Builds a source tree once. A second caller with the same source gets the stored result in seconds. |
13| `spark-window` | Opens one measurement window at a time, keeps the box quiet while it is open, records the box state at open and close. |
14| `spark-calibrate` | The one calibration of a window: CPU memory bandwidth and idle power at the wall. |
15| `spark-baseline 27b` | The one 27B baseline of a window: a fixed 64-token reply, tokens per second and joules per token. |
16
17`spark-receipt` (the energy receipt every measurement already uses) now stamps the window id and the
18window's calibration file into each receipt. It is shell and awk now; the keys, file name and output
19are the same as before, plus the two new keys.
20
21## The run order
22
231. One window at a time. `spark-window open` refuses when a window is already open or waiting, and
24 shows whose it is.
252. To wait your turn, add `--wait`: you get a place in line and your window opens when everyone
26 ahead of you is done, first come, first served. While anyone is in line, an `open` without
27 `--wait` is refused, so nobody jumps ahead. Say so on the ledger:
28 `ledger note <your id> "measure: in line for a window"`. `spark-window status` shows the line.
29 (Retrying a refused `open` every 15 s lost the turn for four hours on 2026-10-20; that is why the
30 line exists.)
313. Inside your window: calibrate once, take the 27B baseline once (if your work involves the 27B),
32 then run only your own measurements. Every receipt carries the window id, so a reader can match it
33 to the calibration and the baseline taken under the same conditions.
344. Close the window as soon as your timings are done. A window that holds anything exclusive (the
35 default) lasts at most 20 minutes and `open` refuses a longer `--lease`; other windows default to
36 90 minutes. A window that runs past its lease lets its locks go, writes NO VERDICT in its folder
37 and posts on the board: its timings are not valid (L405, Drake 2026-10-22). Split long measurements.
385. A timing window opens only when the machine is quiet anyway: at most 3 jobs on the quiet lock and
39 a 1-minute load of at most 10. It waits for that holding nothing (L405).
40
41Builds are not measurements: do them before you open the window, through `spark-build-once` or
42`quiet-build`. While a window is open, builds wait, but at most 25 minutes; then they run anyway and
43the window is marked "shared machine" (L405).
44
45## Exact commands
46
47Open a window that will run the commands below, including `spark-baseline` (waits its turn; prints the
48window id when it holds the box). `spark-baseline` refuses a window that holds the GPU lock, so this
49open passes `--gb10 none`:
50
51```sh
52id=$(spark-window open my-measurement --ledger L109 --lease 20 --gb10 none --wait)
53```
54
55By default `open` holds the GPU lock (`--gb10 exclusive`, added by L154), so GPU-only jobs cannot run
56inside it. The 27B server takes that lock itself for every reply, so a window that measures the 27B
57server, including `spark-baseline`, must be opened with `--gb10 none`; `spark-baseline` refuses
58otherwise. A window that does not measure the 27B can leave that default and skip `spark-baseline`.
59To hold the GPU lock for other work and still take a 27B baseline, use two windows: the default for
60the GPU-holding work, and `--gb10 none` for `spark-baseline`. `spark-calibrate` works in both: it
61uses the window's GPU lock when the window holds it and takes the lock itself when it does not.
62
63Calibrate and take the baseline inside it:
64
65```sh
66spark-window run spark-calibrate
67spark-window run spark-baseline 27b
68```
69
70Run your own measurement inside it (any command; `spark-receipt` inside picks up the window id):
71
72```sh
73spark-window run spark-receipt my-run --idle 30 -- ./my-benchmark args
74```
75
76Close it:
77
78```sh
79spark-window close "$id"
80```
81
82A bare `spark-window close` closes the open window only if you own it: the shell that ran `open` is
83in your process tree, or `$SPARK_WINDOW` (set by `run`) is its id. Otherwise it refuses with exit 3
84and names the holder (L162, 2026-10-20: one lane's finishing script closed another lane's window).
85`spark-window close <ID>` closes exactly that window.
86
87See what is open and who holds or waits on the locks:
88
89```sh
90spark-window status
91spark-window locks
92```
93
94Build once (from inside a git worktree; name every result you need with `--out`):
95
96```sh
97spark-build-once --out build/dagsim -- make build/dagsim
98```
99
100## What lands on disk
101
102Everything for one window sits in `~/yardsticks/windows/<window id>/`:
103
104| File | Contents |
105|---|---|
106| `open.json`, `close.json` | Box state at open and close: load, free memory, GPU use and power, who holds the GPU and quiet locks, who waits, the latest sensor row |
107| `calibration.json` | Memory bandwidth (median, lowest and highest of 10 copies, with 1 and 8 threads) and idle power at the wall over 30 s |
108| `calibration/` | The raw probe output and the idle receipt |
109| `baseline-27b.json` | Decode tokens per second, joules per token over the decode at the wall and above idle, the reply's fingerprint, the server build |
110| `baseline-27b/` | The exact request, the reply, the arrival time of every streamed piece, the receipt, the GPU lock samples |
111
112Receipts still go to `~/yardsticks/receipts/<date>-<name>.json` and now carry `window_id` and
113`calibration` (both `null` outside a window). The build cache lives in `~/.cache/spark-build-once/`
114and its log in `~/yardsticks/build-once.log`.
115
116## How it works, in plain words
117
118- **The quiet lock.** The hive already had one rule for keeping the box quiet: builds share
119 `/tmp/aien-quiet.lock` through `quiet-build`, a measurement takes it alone through `quiet-measure`.
120 L217: `quiet-measure flock LOCKFILE ...` takes LOCKFILE first and the quiet lock second. The old order
121 held the quiet lock exclusive while queued for the GPU, so every build waited behind a measurement
122 that was not measuring (2026-10-20: more than an hour, dozens of builds). The want flag is raised
123 only once LOCKFILE is held. With LOCKFILE held it waits at the gate for at most `SPARK_DRAIN_MAX`
124 seconds (default 300) and then passes it. If the quiet lock does not drain within another
125 `SPARK_DRAIN_MAX` seconds, or a process queued on LOCKFILE has the quiet lock open, the measurement
126 lets LOCKFILE go and queues again. A measurement killed while it queues for LOCKFILE exits without
127 running its command. A command that does not start with `flock` still takes the quiet lock first.
128 `tools/ops/test-quiet-lock-order.sh` replays the starvation on scratch locks. A window is a
129 long-running `quiet-measure`: a small holder process takes the lock alone
130 and keeps it until you close the window or the lease runs out. Inside the window `quiet-measure`
131 sees its own window and runs your command straight away instead of waiting on its own lock.
132- **Getting both locks without starving (L154, L189, L322, L217).** The window waits for the GPU lock
133 holding nothing, so it never blocks CPU timings while it queues. Once it has the GPU lock it keeps it
134 and raises a gate (`/tmp/aien-quiet.gate`): new `quiet-build` and `quiet-measure` callers wait outside
135 while the ones already holding the quiet lock finish (L322: without the gate, shared takers kept
136 arriving and the window waited 40+ minutes). It drains the quiet lock for at most 5 minutes, then
137 lets everything go and waits for a quiet machine again (L405). If a process waiting for the GPU lock
138 holds the quiet lock, the window lets the GPU lock go (gate stays up), waits for the quiet lock, then
139 tries the GPU lock without blocking while keeping the quiet lock it won (L189: letting a won quiet
140 lock go starved the window for hours). A flock-form measurement now uses the same order as the window
141 (chip, then quiet). The window's guard stays, for an old-order caller or a build whose command takes
142 the chip. `--quiet none` takes the GPU lock only, for checks that compare values, never speeds.
143- **The GPU lock.** `/tmp/aien-gb10.lock` is separate. The calibration holds it for its minute of
144 probing and idling so the GPU stays idle. The baseline does not hold it, because the 27B server takes
145 that lock itself for every reply; holding it would make the server wait on the baseline forever. Programs that
146 use only the GPU lock keep it busy almost all the time (the first window ran out its hour waiting for
147 it to go quiet), so the baseline asks for the reply word by word and stamps each word as it arrives.
148 From the first word to the last the server is holding the GPU lock for the baseline's reply, so the decode rate
149 and its energy are clean however long the reply waited in the GPU queue. The baseline samples the
150 lock table throughout and is marked not ok if anyone else held the GPU lock during the decode, or if
151 the whole reply arrived in one burst (then nothing was timed).
152- **The build cache key** is the source tree as it is on disk (the committed tree, plus uncommitted
153 changes, plus new files that git does not ignore), the folder you run from, the exact command, the
154 `--out` list and the `PHYSICS_DIR` / `AIENOS_LOCK_REPO` settings. Any change gives a new key, so a
155 stored build is only reused for identical sources. Two callers with the same key at the same moment:
156 one builds, the other waits on a per-key lock and then takes the stored result. Results are stored
157 by an atomic rename, so a half-written entry is never visible.
158
159## Limits, said plainly
160
161- Wall power is the whole UPS output in 10 W steps about every 2 s, not the Spark alone. A 64-token
162 reply lasts a few seconds, so its joules per token rest on a few samples: read it as coarse.
163- The headline speed is the decode rate: words after the first, divided by the time from the first word
164 to the last. The whole-request rate is recorded too, but it includes the wait in the GPU queue and the
165 short prompt's prefill.
166- Programs that take only the GPU lock and not the quiet lock can still run during a window. The
167 window records them (lock holders at open and close; the baseline samples the lock during its
168 decode), it does not stop them.
169- The memory probe is the one research/583 used (omega `research/cost-sim-583@3bd56731`,
170 `tools/dagsim/memcpy_probe.c`), built with `cc -O2 -pthread`; 583 did not record its compiler
171 flags, so its numbers and mine are comparable in method, not guaranteed bit for bit.
172
173## Receipt format: what changed
174
175Same keys, same order, same file name, same output as before; two keys added at the end. Run side by
176side on the same 8-second command, the old and new receipts differed only in timing jitter
177(`start`, `seconds`, `wall_J` within 0.02 %) and these lines:
178
179```diff
180 "note": "wall W = UPS ups.load x 10 (CP1500PFCLCD, 1 percent steps, ~2 s); whole UPS output, not the Spark alone",
181+ "window_id": "20261019T232138Z-103d00",
182+ "calibration": "/home/drakestapleton/yardsticks/windows/20261019T232138Z-103d00/calibration.json"
183```
184
185Outside a window both are `null`. Numbers still print with a decimal point (`180.0`), as before.