auto-optimize 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- auto_optimize/__init__.py +3 -0
- auto_optimize/__main__.py +5 -0
- auto_optimize/cli.py +651 -0
- auto_optimize/skills/auto-optimize-code/LICENSE +21 -0
- auto_optimize/skills/auto-optimize-code/SKILL.md +251 -0
- auto_optimize/skills/auto-optimize-code/VERSION +1 -0
- auto_optimize/skills/auto-optimize-code/references/algorithm.md +182 -0
- auto_optimize/skills/auto-optimize-code/references/changes.md +146 -0
- auto_optimize/skills/auto-optimize-code/references/cli.md +206 -0
- auto_optimize/skills/auto-optimize-code/references/dashboard.md +203 -0
- auto_optimize/skills/auto-optimize-code/references/documents.md +55 -0
- auto_optimize/skills/auto-optimize-code/references/extending.md +87 -0
- auto_optimize/skills/auto-optimize-code/references/external-validation.md +98 -0
- auto_optimize/skills/auto-optimize-code/references/glossary.md +134 -0
- auto_optimize/skills/auto-optimize-code/references/idea-miner.md +108 -0
- auto_optimize/skills/auto-optimize-code/references/issue-bugs.md +182 -0
- auto_optimize/skills/auto-optimize-code/references/layout.md +300 -0
- auto_optimize/skills/auto-optimize-code/references/main-session.md +45 -0
- auto_optimize/skills/auto-optimize-code/references/measuring.md +208 -0
- auto_optimize/skills/auto-optimize-code/references/pr-optimization.md +127 -0
- auto_optimize/skills/auto-optimize-code/references/pr-tests.md +254 -0
- auto_optimize/skills/auto-optimize-code/references/promotion.md +133 -0
- auto_optimize/skills/auto-optimize-code/references/reading-a-search.md +65 -0
- auto_optimize/skills/auto-optimize-code/references/repo-mode.md +224 -0
- auto_optimize/skills/auto-optimize-code/references/resume.md +81 -0
- auto_optimize/skills/auto-optimize-code/references/shared-knowledge.md +114 -0
- auto_optimize/skills/auto-optimize-code/references/step0-interview.md +298 -0
- auto_optimize/skills/auto-optimize-code/references/step1-unit-tests.md +136 -0
- auto_optimize/skills/auto-optimize-code/references/step2-baseline.md +708 -0
- auto_optimize/skills/auto-optimize-code/references/step3-rounds.md +350 -0
- auto_optimize/skills/auto-optimize-code/references/step4-final.md +121 -0
- auto_optimize/skills/auto-optimize-code/references/step5-ship.md +220 -0
- auto_optimize/skills/auto-optimize-code/references/step6-finish.md +67 -0
- auto_optimize/skills/auto-optimize-code/references/subagent.md +467 -0
- auto_optimize/skills/auto-optimize-code/references/symptoms.md +67 -0
- auto_optimize/skills/auto-optimize-code/references/writing-briefs.md +117 -0
- auto_optimize/skills/auto-optimize-code/scripts/attribution.py +156 -0
- auto_optimize/skills/auto-optimize-code/scripts/autoopt.py +12863 -0
- auto_optimize/skills/auto-optimize-code/scripts/check_seeding.py +334 -0
- auto_optimize/skills/auto-optimize-code/scripts/cold.py +90 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/README.md +165 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/autoopt_monitor.py +850 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/gpu_scan.py +954 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/monitor_writer.py +684 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/scan.py +1030 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/dashboard.css +775 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/dashboard.js +3652 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/index.html +191 -0
- auto_optimize/skills/auto-optimize-code/scripts/issue_body.py +2118 -0
- auto_optimize/skills/auto-optimize-code/scripts/lint_text.py +448 -0
- auto_optimize/skills/auto-optimize-code/scripts/opt_pr_body.py +894 -0
- auto_optimize/skills/auto-optimize-code/scripts/opt_pr_tables.py +367 -0
- auto_optimize/skills/auto-optimize-code/scripts/paired.py +188 -0
- auto_optimize/skills/auto-optimize-code/scripts/preflight.py +280 -0
- auto_optimize/skills/auto-optimize-code/scripts/probe_run.py +72 -0
- auto_optimize/skills/auto-optimize-code/scripts/publish.py +385 -0
- auto_optimize/skills/auto-optimize-code/scripts/run_iteration.py +1382 -0
- auto_optimize/skills/auto-optimize-code/scripts/ship.py +1193 -0
- auto_optimize/skills/auto-optimize-code/scripts/stages.py +651 -0
- auto_optimize/skills/auto-optimize-code/scripts/tests_pr_body.py +1267 -0
- auto_optimize/skills/auto-optimize-code/scripts/tests_pr_push.py +426 -0
- auto_optimize/skills/auto-optimize-code/scripts/tests_pr_tables.py +779 -0
- auto_optimize-1.0.0.dist-info/METADATA +610 -0
- auto_optimize-1.0.0.dist-info/RECORD +67 -0
- auto_optimize-1.0.0.dist-info/WHEEL +4 -0
- auto_optimize-1.0.0.dist-info/entry_points.txt +2 -0
- auto_optimize-1.0.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,708 @@
|
|
|
1
|
+
# Step 2 — the setup subagent: the benchmark and the baseline
|
|
2
|
+
|
|
3
|
+
You are the setup subagent. You do step 2; the idea miner starts when you are
|
|
4
|
+
done, because it prices ideas against the profile you write after the baseline,
|
|
5
|
+
and the orchestrator briefs the first iteration once it has reported.
|
|
6
|
+
Your prompt lists A0's code and the harness, file by file, and the usage line
|
|
7
|
+
of each subcommand this file has you run: read a `--help` only for a flag its
|
|
8
|
+
line does not explain.
|
|
9
|
+
Your prompt (`autoopt.py setup`) gives `AO`, `WORK`, the mode, the command
|
|
10
|
+
`init` recorded and the rules from `spec.md`, which bind you as much as this
|
|
11
|
+
file does. A term you do not know is in `references/glossary.md`; read it for
|
|
12
|
+
that only.
|
|
13
|
+
|
|
14
|
+
**Scratch goes in a new directory under `setup/`**, `mktemp -d
|
|
15
|
+
$WORK/autooptimize/setup/scratch.XXXX`, never in a folder of a fixed name
|
|
16
|
+
elsewhere, such as a scratchpad: another search or test may already hold one
|
|
17
|
+
of that name, and its files get overwritten.
|
|
18
|
+
|
|
19
|
+
**Keep notes as you go** in `$WORK/autooptimize/setup/notes.md`: each item
|
|
20
|
+
below as it is done, and each proof's numbers. A subagent that continues
|
|
21
|
+
after you, once you stop on a question or die, starts from them. Append each
|
|
22
|
+
note in the same call as the work it records (`<command> && cat >> $N
|
|
23
|
+
<<'EOF' … EOF`), or beside the next command, never in a call of its own: a
|
|
24
|
+
call re-reads your whole context.
|
|
25
|
+
|
|
26
|
+
**Use `wait` for anything over four minutes** (`SKILL.md`).
|
|
27
|
+
`run_iteration.py`, `width` and `prove` take `--background`, which detaches
|
|
28
|
+
them and prints the log to wait on (`width` under a `gpu_command` goes through
|
|
29
|
+
`bg` instead: *GPU leases*); anything else:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
(<command>; echo "exit $?") > $WORK/autooptimize/setup/<name>.log 2>&1 &
|
|
33
|
+
python3 $AO/autoopt.py wait $WORK/autooptimize/setup/<name>.log
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
`check_seeding.py` on A0, `prove` and `width` write their own logs in
|
|
37
|
+
`setup/` (`seeding.log`, `prove-gates.log`, `prove-compare.log`,
|
|
38
|
+
`width.log`), each ending `exit <code>`: your notes cite them, and need no
|
|
39
|
+
redirection of your own.
|
|
40
|
+
|
|
41
|
+
## In this order
|
|
42
|
+
|
|
43
|
+
1. Write the benchmark (*What the script must do*), and put what one run
|
|
44
|
+
does on `spec.md`'s *Benchmark* line, which every brief quotes so no
|
|
45
|
+
iteration reads the harness for it: the entry point, the call into the
|
|
46
|
+
code under test with its arguments, the inputs and their sizes, and what
|
|
47
|
+
is timed and what is not (`autoopt.py spec $WORK --set Benchmark
|
|
48
|
+
'<text>'`).
|
|
49
|
+
2. When a gate compares against the baseline's output, wire up its reference
|
|
50
|
+
(*A gate that compares against the baseline's output*).
|
|
51
|
+
3. When parsing the inputs takes longer than the timed work, parse them once
|
|
52
|
+
(*Parse the inputs once*).
|
|
53
|
+
4. Check the seeding with `check_seeding.py` (*Seeding*), then, for a speed
|
|
54
|
+
search, time the code's documented speed options against its defaults
|
|
55
|
+
(*Documented speed options*).
|
|
56
|
+
5. Prove each gate on three kinds of change, and compute any tolerance from
|
|
57
|
+
data (*Prove the gate*, *Compute a numeric tolerance against real data*).
|
|
58
|
+
Write the values on `spec.md`'s *Gate proof* line (`autoopt.py spec`).
|
|
59
|
+
6. For a speed or memory search, write the task's checks and prove them
|
|
60
|
+
(*Write the checks*).
|
|
61
|
+
7. For a CPU benchmark, measure how many concurrent runs the benchmark
|
|
62
|
+
tolerates and write the verdict on *Width measured* (`autoopt.py width
|
|
63
|
+
--write`, *Measure what concurrency does to the objective*); for a GPU
|
|
64
|
+
benchmark, write "one run per GPU".
|
|
65
|
+
8. Check that the machine is quiet with `autoopt.py busy` (*Check the
|
|
66
|
+
machine is quiet*).
|
|
67
|
+
9. Run the baseline on its own GPUs and check its report (*GPU leases*,
|
|
68
|
+
*Running the baseline*).
|
|
69
|
+
10. Seed the knowledge ledger and write A0's README (*After the baseline*).
|
|
70
|
+
11. Close step 2 and report (*Closing step 2*).
|
|
71
|
+
|
|
72
|
+
`run_iteration.py` refuses the baseline until items 1, 5 and 7 (*Benchmark*,
|
|
73
|
+
*Gate proof*, *Width measured*) are on `spec.md`.
|
|
74
|
+
|
|
75
|
+
## Decisions that are the user's
|
|
76
|
+
|
|
77
|
+
You cannot ask the user. When step 2 reaches one of these, run `python3
|
|
78
|
+
$AO/autoopt.py setup $WORK --ask "<the question and the options>" --recommend
|
|
79
|
+
"<the answer you recommend>"` and write it in your notes. Under
|
|
80
|
+
`after.setup_questions=recommended` (the user's word at step 0) it prints
|
|
81
|
+
`taken without asking`: go on with that answer; `setup --done` lists it for
|
|
82
|
+
the user. Otherwise it waits: **first do every step that does not depend on
|
|
83
|
+
the answer**, `--ask` what else those steps reach (each joins the one stop),
|
|
84
|
+
then put all of them in your report and stop once:
|
|
85
|
+
|
|
86
|
+
- a numeric tolerance: both error distributions, and where the threshold
|
|
87
|
+
would sit (*Compute a numeric tolerance against real data*);
|
|
88
|
+
- a width narrower than the runs at once in the plan (`gpus_per_agent`; *Measure what
|
|
89
|
+
concurrency does to the objective*);
|
|
90
|
+
- a busy machine before the baseline (*Check the machine is quiet*);
|
|
91
|
+
- a documented option that beats the defaults by more than 10% (*Documented
|
|
92
|
+
speed options*).
|
|
93
|
+
|
|
94
|
+
Any other choice this skill gives the user before the baseline goes the same
|
|
95
|
+
way: unit tests that fail on unmodified code, a baseline that sits on its own
|
|
96
|
+
gate, a seed spread as large as the hoped-for gain, a plan whose cost runs to
|
|
97
|
+
a week. The answer is recorded in `spec.md` and comes back as a message, or as
|
|
98
|
+
the prompt of a subagent that continues from your notes.
|
|
99
|
+
|
|
100
|
+
## What the script must do
|
|
101
|
+
|
|
102
|
+
1. Take `--seed` and `--out`, and use the seed for every source of
|
|
103
|
+
randomness it has.
|
|
104
|
+
2. Run from inside its own iteration directory, writing only into `--out`.
|
|
105
|
+
3. Write `<out>/metrics.json` meeting the contract in `references/layout.md`,
|
|
106
|
+
*metrics.json — the contract every benchmark meets*:
|
|
107
|
+
`objective`, every configured gate and every observer.
|
|
108
|
+
4. Exit non-zero if it could not produce a number. A bad objective is data; a
|
|
109
|
+
crash is a failure, and the runner has to tell them apart.
|
|
110
|
+
|
|
111
|
+
It goes in the baseline worktree, where `init --copy` may already have put
|
|
112
|
+
it; in repository mode, in `harness/` (`references/repo-mode.md`, *Setting it
|
|
113
|
+
up*). It may be
|
|
114
|
+
several files; the whole directory is what gets forked.
|
|
115
|
+
|
|
116
|
+
**Relative paths to data break it quietly.** The script runs with its
|
|
117
|
+
iteration directory as the working directory, so `../data/input.h5` resolves
|
|
118
|
+
somewhere different in every iteration. Use absolute paths for anything
|
|
119
|
+
outside the iteration.
|
|
120
|
+
|
|
121
|
+
**So does writing outside `--out`.** A script that writes `./cache.bin`
|
|
122
|
+
or appends to a shared log collides with the iterations running beside it,
|
|
123
|
+
and the collision shows up as a failure in an unrelated iteration.
|
|
124
|
+
|
|
125
|
+
**So does a seed that changes nothing** (*Seeding*, below).
|
|
126
|
+
|
|
127
|
+
## Timing, when the objective or a gate is speed
|
|
128
|
+
|
|
129
|
+
- Warm up before timing, on the benchmark's full input. The first call
|
|
130
|
+
compiles kernels and allocates; a small warmup leaves the timed call as the
|
|
131
|
+
first large one (`references/measuring.md`, *A cached compile can outlive
|
|
132
|
+
the edit*).
|
|
133
|
+
- `torch.cuda.synchronize()` before reading the clock at each end, or the
|
|
134
|
+
timing measures the launch of the work rather than the work.
|
|
135
|
+
- Say which device and which batch shape in the README.
|
|
136
|
+
- Choosing between variants, profiling the root and reading generated code:
|
|
137
|
+
`references/measuring.md`.
|
|
138
|
+
|
|
139
|
+
### One run is a warmup and one timed call
|
|
140
|
+
|
|
141
|
+
**The run does not take a median; the runner does.** A run warms up, times
|
|
142
|
+
the thing once, and writes that number as `objective`; the iteration's
|
|
143
|
+
`runs_per_iteration` runs give it its median. A `for _ in range(N)` around
|
|
144
|
+
the timed call is a second median over the same machine noise, and its cost
|
|
145
|
+
multiplies:
|
|
146
|
+
|
|
147
|
+
| Inner calls | 5 runs | 10 runs |
|
|
148
|
+
|---|---|---|
|
|
149
|
+
| 1 | 10 calls | 20 |
|
|
150
|
+
| 5 | 30 calls | 60 |
|
|
151
|
+
| 200 | 1005 calls | 2010 |
|
|
152
|
+
|
|
153
|
+
The warmup is one of those calls, which is why the first row is not 5 and 10.
|
|
154
|
+
|
|
155
|
+
**The exception is a call too short to time alone.** Under about 10 ms, clock
|
|
156
|
+
resolution and one scheduling hiccup are a large share of the measurement, and
|
|
157
|
+
an inner repeat is part of making it. Then:
|
|
158
|
+
|
|
159
|
+
- Say the repeat count in the metric's name or the README, so nobody reads a
|
|
160
|
+
per-call number as a per-batch one.
|
|
161
|
+
- Keep `inner x runs_per_iteration` in mind: 200 inner calls of a 10 ms
|
|
162
|
+
forward pass is 2 s, and 200 calls of anything that takes a second is not.
|
|
163
|
+
- Put the within-run spread in an observer, so a machine that got busy
|
|
164
|
+
mid-run is visible rather than averaged away.
|
|
165
|
+
|
|
166
|
+
A latency **gate** on one short call beside an objective timed over the
|
|
167
|
+
whole input is the usual case for an inner loop, as in the skeleton
|
|
168
|
+
at the end.
|
|
169
|
+
|
|
170
|
+
## A gate that compares against the baseline's output
|
|
171
|
+
|
|
172
|
+
The snippet compares arrays. For a dict, a list or a string, store the
|
|
173
|
+
reference as canonical JSON, count the entries that differ, and use the
|
|
174
|
+
order rule the user chose at step 0.
|
|
175
|
+
|
|
176
|
+
The reference is written once, during the baseline, to `autooptimize/reference/`,
|
|
177
|
+
outside every iteration: a forked copy would let each iteration compare
|
|
178
|
+
against itself. **Only A0 writes it**, and any other iteration that finds it
|
|
179
|
+
missing fails. Otherwise a lost reference, or an iteration run before the
|
|
180
|
+
baseline, writes its own output as the reference and passes against itself.
|
|
181
|
+
|
|
182
|
+
```python
|
|
183
|
+
parser.add_argument('--iteration', required=True) # {iteration} in the command
|
|
184
|
+
...
|
|
185
|
+
# One file per seed: run i is compared with the baseline's run i, since a
|
|
186
|
+
# seed that changes the input or the initialization changes the output.
|
|
187
|
+
reference = os.path.join(os.environ['AUTOOPT_REF'],
|
|
188
|
+
'baseline_predictions.seed-{}.npy'.format(args.seed))
|
|
189
|
+
|
|
190
|
+
if os.path.basename(os.path.normpath(args.iteration)) == '0':
|
|
191
|
+
numpy.save(reference, predictions)
|
|
192
|
+
elif not os.path.exists(reference):
|
|
193
|
+
sys.exit('no reference for seed {} at {}: run the baseline on this '
|
|
194
|
+
'seed'.format(args.seed, reference))
|
|
195
|
+
|
|
196
|
+
expected = numpy.load(reference)
|
|
197
|
+
metrics['gates']['max_abs_diff_vs_base'] = float(
|
|
198
|
+
numpy.abs(predictions - expected).max())
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
Pass the directory in through the command as an absolute path, for the same
|
|
202
|
+
reason the data paths are absolute:
|
|
203
|
+
|
|
204
|
+
```bash
|
|
205
|
+
python3 $AO/autoopt.py init $WORK … \
|
|
206
|
+
--command "AUTOOPT_REF=$WORK/autooptimize/reference python3 bench.py --iteration {iteration} --seed {seed} --out {out}"
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
`init` ran at step 0: when the benchmark needs the reference path or another
|
|
210
|
+
flag the recorded command lacks, set it with `autoopt.py config $WORK --set
|
|
211
|
+
command="…" --reason "…"`, which is accepted until A0 has run.
|
|
212
|
+
A `$WORK` holding a space needs single quotes of its own inside the double
|
|
213
|
+
quotes (`AUTOOPT_REF='…/autooptimize/reference'`). `{iteration}` is the
|
|
214
|
+
iteration's absolute directory in both modes. Placeholder rules:
|
|
215
|
+
`references/layout.md`, *config.json*.
|
|
216
|
+
|
|
217
|
+
A raised `runs_per_iteration` hits the missing-reference exit: seeds past
|
|
218
|
+
A0's runs have no reference until A0 runs them. `run_iteration.py` on
|
|
219
|
+
`iterations/0`, without `--rerun`, runs only the seeds it lacks.
|
|
220
|
+
|
|
221
|
+
## Parse the inputs once
|
|
222
|
+
|
|
223
|
+
Every run, and every process a paired or cold-compile check starts, pays the
|
|
224
|
+
benchmark's setup. A paired check starts dozens of processes, so a parse
|
|
225
|
+
slower than the timed work dominates its cost. Parse once into
|
|
226
|
+
`autooptimize/reference/`, in a binary form that loads in milliseconds, and
|
|
227
|
+
have the benchmark and every probe load that:
|
|
228
|
+
|
|
229
|
+
```python
|
|
230
|
+
# once, before the baseline: AUTOOPT_REF=$WORK/autooptimize/reference python3 parse_once.py
|
|
231
|
+
import os, numpy
|
|
232
|
+
arrays = parse_input_file('inputs.txt') # the slow parser
|
|
233
|
+
numpy.savez(os.path.join(os.environ['AUTOOPT_REF'], 'inputs.npz'), *arrays)
|
|
234
|
+
|
|
235
|
+
# in bench.py and in every probe
|
|
236
|
+
with numpy.load(os.path.join(os.environ['AUTOOPT_REF'], 'inputs.npz')) as data:
|
|
237
|
+
arrays = [data['arr_{}'.format(i)] for i in range(len(data.files))]
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Check the loaded arrays are byte-identical to what the parser returns
|
|
241
|
+
(`tobytes()` on each, and the dtype and memory layout), since a layout change
|
|
242
|
+
can change which compiled code runs. The runner and `autoopt.py final` pass
|
|
243
|
+
a registered check no environment, so a check that loads them carries
|
|
244
|
+
`AUTOOPT_REF=$WORK/autooptimize/reference` at the front of its command (*Write
|
|
245
|
+
the checks*); a probe run by hand with `paired.py` takes `--env
|
|
246
|
+
AUTOOPT_REF=…`.
|
|
247
|
+
|
|
248
|
+
## Seeding
|
|
249
|
+
|
|
250
|
+
Two properties have to hold:
|
|
251
|
+
|
|
252
|
+
1. **Within an iteration, the runs differ.** That is what the median averages
|
|
253
|
+
and what the noise band measures.
|
|
254
|
+
2. **Across iterations, the seeds are the same.** The runner guarantees it: run
|
|
255
|
+
*i* uses `seed_base + i`, so every iteration runs seeds 0 to 4 at the
|
|
256
|
+
default count, and a difference between two iterations is the idea
|
|
257
|
+
rather than the draw.
|
|
258
|
+
|
|
259
|
+
Take every seed from `--seed`, and **give the input its own stream, separate
|
|
260
|
+
from any randomness the code under test draws**:
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
seed = args.seed
|
|
264
|
+
|
|
265
|
+
random.seed(seed)
|
|
266
|
+
numpy.random.seed(seed)
|
|
267
|
+
input_rng = numpy.random.default_rng(seed) # the input: sizes, order, sampling
|
|
268
|
+
code_rng = numpy.random.default_rng(seed + 1_000_000) # handed to the code under test
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
The separate stream keeps property 2 through a change to the code. Drawn from
|
|
272
|
+
one stream, an implementation that takes one more value (a random pivot, a
|
|
273
|
+
sampled subset) shifts every later draw, and the run does not see the input
|
|
274
|
+
the baseline saw at that seed: the seeds match and the input does not, which
|
|
275
|
+
looks like a real effect.
|
|
276
|
+
|
|
277
|
+
Worker processes or threads that draw random numbers each need a seed derived
|
|
278
|
+
from `seed`, or they draw from entropy. Anything with a `random_state=`
|
|
279
|
+
argument takes `seed`, never a literal.
|
|
280
|
+
|
|
281
|
+
Do **not** reach for `torch.use_deterministic_algorithms(True)`. It changes
|
|
282
|
+
which kernels run, so a latency measures something other than the code in
|
|
283
|
+
production, and a gate on numeric output becomes a gate on the deterministic
|
|
284
|
+
kernels.
|
|
285
|
+
|
|
286
|
+
### Check it before spending the baseline
|
|
287
|
+
|
|
288
|
+
```bash
|
|
289
|
+
python3 $AO/check_seeding.py $WORK/autooptimize/iterations/0
|
|
290
|
+
# a GPU search with no gpu_command: prefix CUDA_VISIBLE_DEVICES=<indices> (*GPU leases*)
|
|
291
|
+
```
|
|
292
|
+
|
|
293
|
+
It reads the benchmark for unseeded randomness and seeding calls handed a
|
|
294
|
+
literal, then runs it twice on one seed and twice more on others, and reports
|
|
295
|
+
the **same-seed spread** and the **between-seed spread**. It runs A0's own
|
|
296
|
+
code, so a gate against the baseline's output has its reference written
|
|
297
|
+
early; the baseline rewrites it.
|
|
298
|
+
|
|
299
|
+
| Exit | Verdict | Do |
|
|
300
|
+
|---|---|---|
|
|
301
|
+
| 0 | OK: the same seed reproduces, or its spread is small next to the between-seed spread (also every `--scan-only`) | go on |
|
|
302
|
+
| 1 | WARNING: repeating a seed moves the objective by half or more of what changing it does | something unseedable runs: GPU nondeterminism, `SystemRandom`, a worker seeded from entropy. Fix it, or record it in `spec.md`; it widens the noise band |
|
|
303
|
+
| 2 | FAIL: different seeds gave identical answers | the seed never reaches the randomness, so the runs are one number repeated. Fix it before anything runs |
|
|
304
|
+
| 3 | refused or could not run: bad arguments, no GPU lease, a run failed | read the message |
|
|
305
|
+
|
|
306
|
+
Both spreads come from a handful of runs; re-run with `--repeats 5 --others 5`
|
|
307
|
+
before believing a borderline answer. `--scan-only` reads the source and runs
|
|
308
|
+
nothing.
|
|
309
|
+
|
|
310
|
+
**On a deterministic benchmark the verdict is about machine noise.** A timing
|
|
311
|
+
harness with a fixed input has a seed that varies nothing, so both spreads are
|
|
312
|
+
noise and which is larger is chance. That is harmless, since the noise band
|
|
313
|
+
comes from the runs' own spread, but say so in the README. Better, make the
|
|
314
|
+
seed do real work: having it choose the subset or the order turns the runs
|
|
315
|
+
into independent repeats and makes a bitwise gate cover several inputs.
|
|
316
|
+
|
|
317
|
+
## Documented speed options
|
|
318
|
+
|
|
319
|
+
For a speed search, before the gates are proven. The benchmark times the call
|
|
320
|
+
at its defaults, and a documented option may already give most of what the search
|
|
321
|
+
will find (a parallel flag, `n_jobs`, a cache, a batch size, a faster
|
|
322
|
+
variant). List the options of the entry point the benchmark calls from its
|
|
323
|
+
docstrings, README and `--help` (`grep -n -i 'parallel\|n_jobs\|thread\|cache\|fast\|batch'`).
|
|
324
|
+
Time each one on A0 with the harness's own call sequence, one option at a
|
|
325
|
+
time, the thread count fixed, three runs in separate processes, and compare
|
|
326
|
+
its outputs with the defaults' under the gate's rule. Write one table in
|
|
327
|
+
`setup/notes.md`: option, seconds, ratio to the defaults, outputs equal to
|
|
328
|
+
the defaults' (yes or no).
|
|
329
|
+
|
|
330
|
+
- **No option moves the objective by more than 10%** (the noise band is not
|
|
331
|
+
measured yet): write that sentence in the notes and go on.
|
|
332
|
+
- **One does:** add a `[harness]` ledger entry for it (option, ratio, outputs
|
|
333
|
+
equal or not) so the miner and the iterations do not rediscover it, then
|
|
334
|
+
`setup --ask`: "option X takes N s against M s at the defaults, outputs equal
|
|
335
|
+
(or not); keep the objective at the defaults, or time with X on?" A search at
|
|
336
|
+
the defaults whose best idea reproduces the option reports a gain users can
|
|
337
|
+
already have; with X on, it starts from what users get with it. `setup
|
|
338
|
+
--answer` records the answer in `spec.md`.
|
|
339
|
+
|
|
340
|
+
## Prove the gate
|
|
341
|
+
|
|
342
|
+
Before the baseline, write a change of each kind and check that every gate
|
|
343
|
+
calls it right.
|
|
344
|
+
|
|
345
|
+
| Kind | Should |
|
|
346
|
+
|---|---|
|
|
347
|
+
| unchanged code | pass, at exactly zero |
|
|
348
|
+
| a change the user considers acceptable: under a tolerance, a pure reordering of floating-point work; under a bitwise gate, a change that reorders work without changing any result bit, such as swapping two independent statements | pass |
|
|
349
|
+
| a genuinely lossy change | **fail** |
|
|
350
|
+
|
|
351
|
+
The third case passes by accident when the patch matches nothing, such as a
|
|
352
|
+
`str.replace` against lines that are not there, with a `print` claiming
|
|
353
|
+
success. **Assert that each edit landed**, then run.
|
|
354
|
+
|
|
355
|
+
`prove` runs the search's `command` as the runner fills it, against a
|
|
356
|
+
scratch reference: A0's code writes it (its `--iteration` ends in `0`), and
|
|
357
|
+
each copy compares against it. `AUTOOPT_REF` points at the scratch directory,
|
|
358
|
+
in the environment and in the command, so the real `reference/` is never
|
|
359
|
+
touched:
|
|
360
|
+
|
|
361
|
+
```bash
|
|
362
|
+
python3 $AO/autoopt.py prove $WORK --make same,reorder,lossy # copies of A0's code under $WORK/setup/gateproof/
|
|
363
|
+
# edit each copy but same
|
|
364
|
+
python3 $AO/autoopt.py prove $WORK # every gate on A0 and on each copy
|
|
365
|
+
python3 $AO/autoopt.py spec $WORK --set 'Gate proof' '<the three values per gate>'
|
|
366
|
+
```
|
|
367
|
+
|
|
368
|
+
It runs `same` first and stops there when the unchanged copy does not pass:
|
|
369
|
+
the base differs from itself run to run (unseeded sampling, ids drawn from
|
|
370
|
+
the clock, thread order), and no fault copy is run until the gate ignores or
|
|
371
|
+
fixes what varies. It names a copy in which no file changed (`NO FILE
|
|
372
|
+
CHANGED`); check that the change in each other copy is the intended one.
|
|
373
|
+
|
|
374
|
+
## Compute a numeric tolerance against real data
|
|
375
|
+
|
|
376
|
+
A tolerance that sounds precise is often unreachable or meaningless, and only
|
|
377
|
+
data tells which. "p-values within 1e-12 relative" fails every reordering when
|
|
378
|
+
the p-value is `1 - CDF`: cancellation dominates the tail and many reference
|
|
379
|
+
values are exactly 0, so a pure `fastmath` reordering reaches a **relative**
|
|
380
|
+
difference of 0.286 at a worst **absolute** difference of 2.13e-14. That gate
|
|
381
|
+
has to be absolute, on a quantity bounded by 1.
|
|
382
|
+
|
|
383
|
+
**Generate the error distribution of a change the user considers acceptable
|
|
384
|
+
and of one they do not, and put the threshold between them.** Write both on
|
|
385
|
+
*Gate proof* and put the threshold to the user (*Decisions that are the
|
|
386
|
+
user's*) rather than choosing silently. The gap is often orders of magnitude.
|
|
387
|
+
|
|
388
|
+
- **An absolute tolerance on a bounded quantity is usually the honest one.**
|
|
389
|
+
Relative error means nothing wherever the quantity is near zero.
|
|
390
|
+
- **Pair a numeric gate with an observer for the decision it feeds**, such as
|
|
391
|
+
how many elements cross the significance threshold anybody applies. A
|
|
392
|
+
change that moves that observer while passing the gate goes to the user.
|
|
393
|
+
|
|
394
|
+
**A tolerance is a budget that iterations spend.** Each iteration's README
|
|
395
|
+
says how much of it the iteration used. An idea that spends most of it in one
|
|
396
|
+
step forces every later idea that needs room to fork from the baseline. Keep
|
|
397
|
+
two numbers apart: the headroom over the *current* error, and the room an idea
|
|
398
|
+
needs. "99.9% of the budget is unspent" is the first; narrowing float64 to
|
|
399
|
+
float32 can need orders of magnitude more than that.
|
|
400
|
+
|
|
401
|
+
## Write the checks
|
|
402
|
+
|
|
403
|
+
Once, written by you, into `autooptimize/checks/`, outside every worktree like
|
|
404
|
+
the harness, and off limits to every iteration. The runner runs them on each
|
|
405
|
+
iteration (`references/subagent.md`, *Checks beyond the runner*); a subagent
|
|
406
|
+
writes checks only for paths they cannot reach:
|
|
407
|
+
|
|
408
|
+
| Script | Takes | Does | Exits |
|
|
409
|
+
|---|---|---|---|
|
|
410
|
+
| `compare.py` | `{src}`: one version's tree, as `git archive` writes it; `{reference}`: the directory of A0's cached outputs | imports the version from its tree and runs two groups of inputs: the timed call on the benchmark's inputs and the edge cases (empty, one element, the largest size, degenerate shapes, other dtypes, every class the unit tests name), and every public function the package exports on small and odd inputs. Compares each output with A0's under the gate's rule: hashes for a bitwise gate, the gate's quantity for a tolerance. A version that raises where A0 returned differs. With `AUTOOPT_WRITE_REFERENCE=1` it writes its outputs into `{reference}` instead. One line per input; the last line a summary such as `46 inputs identical` | 0 alike, 1 different, 2 with no outputs in `{reference}` |
|
|
411
|
+
| `time_one.py` | `{src}` | imports from the tree, warms up at full size, times one benchmark call, prints the seconds last; what `autoopt.py final` pairs, A0 against the winner (`references/measuring.md`, *Paired separate processes: `paired.py`*) | 0, or non-zero on a wrong output |
|
|
412
|
+
| `first_call.py` | `{src}` | compiled code only: one small call, which the runner times with `cold.py` on empty caches before each iteration's runs | 0 |
|
|
413
|
+
| `checks.build` | `{src}` | compiled code only: a command (not a file under `checks/`) that builds that exported tree in place exactly as the harness builds a worktree, the same compiler, flags and toolchain; what `variant` builds a subagent's copies with and what a checker's `{parent}` and `{child}` are built with | 0 |
|
|
414
|
+
| `profile_call.py` (never `profile.py`, which shadows the standard library's `profile` that `cProfile` imports, since a script's own directory comes first on the import path) | `{src}`, `{out}` (a scratch directory) | prints where one benchmark call spends its time on that tree: one line per function or stage, `<share of the call> <file>:<function>`, largest first, at most 60 lines. Python: cProfile's cumulative time over the call's total; compiled code: a sampling profiler (`perf`, or one that needs no privileges where `perf` is blocked); numba: wrap a dispatcher to time it only after the warm-up call, since a jitted caller compiled later sees the wrapper, a Python object, and fails to type, which breaks the profile on every new jitted helper. What `promote` runs on each new root, so the miner's *Gain* and each brief's premise come from the root being changed, not from A0 | 0 |
|
|
415
|
+
|
|
416
|
+
The public functions are the second group because the benchmark calls one
|
|
417
|
+
entry point: a change to a shared helper can keep its output identical and
|
|
418
|
+
break every other caller (`references/subagent.md`, *Off-benchmark callers of the code you are
|
|
419
|
+
changing*).
|
|
420
|
+
|
|
421
|
+
Register them, absolute paths in double quotes, and `checks.threads`, the
|
|
422
|
+
second thread count `final` pairs at, when `spec.md` names one. A check that
|
|
423
|
+
loads the parsed inputs starts its command with
|
|
424
|
+
`AUTOOPT_REF=$WORK/autooptimize/reference`:
|
|
425
|
+
|
|
426
|
+
```bash
|
|
427
|
+
python3 $AO/autoopt.py config $WORK --reason "step 2: the task's checks" \
|
|
428
|
+
--set checks.compare="python3 $WORK/autooptimize/checks/compare.py {src} {reference}" \
|
|
429
|
+
--set checks.time="python3 $WORK/autooptimize/checks/time_one.py --src {src}" \
|
|
430
|
+
--set checks.first_call="python3 $WORK/autooptimize/checks/first_call.py --src {src}" \
|
|
431
|
+
--set checks.threads=8
|
|
432
|
+
python3 $AO/autoopt.py config $WORK --reason "step 2: how a copy is built" \
|
|
433
|
+
--set checks.build="make -C {src} -j 8" # compiled code: as the harness builds
|
|
434
|
+
python3 $AO/autoopt.py config $WORK --reason "step 2: the root's profile" \
|
|
435
|
+
--set checks.profile="python3 $WORK/autooptimize/checks/profile_call.py {src} {out}"
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
**Only A0's outputs are cached**, in `autooptimize/reference/checks/outputs/`,
|
|
439
|
+
as only A0 writes the gate's reference. The runner caches them itself before
|
|
440
|
+
the first compare, and again from A0 whenever the gates, the compare command
|
|
441
|
+
or any file under `checks/` changes, so an edited check is in force before
|
|
442
|
+
the next iteration's compare; `autoopt.py check $WORK --reference` does the
|
|
443
|
+
same by hand. Each cache is proven as it is written: A0 compared against its
|
|
444
|
+
own outputs must pass, or the runner refuses to start.
|
|
445
|
+
|
|
446
|
+
A package with compiled extensions is built inside each tree first, as the
|
|
447
|
+
harness builds the worktree (`references/repo-mode.md`, *Setting it up*).
|
|
448
|
+
|
|
449
|
+
**How the scripts call what you write**, so nothing here needs their source:
|
|
450
|
+
|
|
451
|
+
| What | Run by | How |
|
|
452
|
+
|---|---|---|
|
|
453
|
+
| `command`, the benchmark | `run_iteration.py`, once per run; `prove` and `width` the same way | in the iteration directory, with `{seed}`, `{out}` (the run's directory, relative to it; `{out_abs}` absolute), `{iteration}` (the iteration's absolute directory), `{src}` (its worktree) and `{cache}` (`iterations/<id>/cache/<commit>`, the commit's first 12 characters, as in `check/` and `profile/`) filled shell-quoted; `CUDA_VISIBLE_DEVICES` set to one leased GPU; killed with its process group after `timeout_seconds`. A non-zero exit, or a `metrics.json` without the objective or a gate, fails the run |
|
|
454
|
+
| `checks.compare` | the runner, after an iteration's first run; `check --reference`; `prove --compare` | `{src}`: the iteration's commit as `git archive` writes it (tracked files, no `.git`) in `iterations/<id>/check/<commit>/`; `{reference}`: `reference/checks/outputs/`; in the iteration directory, with the same timeout. Exit 0 is `pass`, 1 `differ`, anything else or a timeout `error`; its last non-empty line is the `check:` line's summary |
|
|
455
|
+
| caching A0's outputs | the runner, before the first compare and after any change to the compare command, the gates or a file under `checks/` | A0's commit exported to `reference/checks/trees/`; the compare run with `AUTOOPT_WRITE_REFERENCE=1` into a new directory, which must not stay empty; then A0 compared against it, which must pass. Earlier outputs stay beside the new ones |
|
|
456
|
+
| `checks.time` | `final`, through `paired.py` | `{src}`, a tree; the seconds are the last number on its last line; a non-zero exit stops the pairing as a wrong output. Run again at `checks.threads` with `OMP_NUM_THREADS`, `NUMBA_NUM_THREADS`, `MKL_NUM_THREADS` and `OPENBLAS_NUM_THREADS` all set to it |
|
|
457
|
+
| `checks.first_call` | the runner, before an iteration's runs, through `cold.py` | `{src}`, the exported tree; two repetitions, each with `NUMBA_CACHE_DIR`, `TRITON_CACHE_DIR` and `TORCHINDUCTOR_CACHE_DIR` on an empty directory of its own; the seconds are the last number on its last line |
|
|
458
|
+
| `checks.build` | `variant`, `prove --id`, `finish` and `checkers` | `{src}`: an exported tree under the iteration's `probe/`; run in that tree with the runner's timeout, once per tree, its log beside it as `<tree>.build.log` ending `exit <code>` |
|
|
459
|
+
| `checks.profile` | `promote`, on each new root; `autoopt.py profile --id <id>` by hand | `{src}`: the measured commit exported to `iterations/<id>/profile/<commit>/` and built with `checks.build`; `{out}`: `iterations/<id>/profile/`; in the iteration directory with the runner's timeout. Its standard output becomes `iterations/<id>/profile.txt`; a failure is reported on `promote`'s `profile:` line and never stops a promotion |
|
|
460
|
+
|
|
461
|
+
**Prove them as you prove a gate**, before the baseline, against a scratch
|
|
462
|
+
reference. Plant two faults, each in a copy of its own: one output value
|
|
463
|
+
changed, and one public function the benchmark never calls raising. `prove
|
|
464
|
+
--compare` caches A0's outputs there (`AUTOOPT_WRITE_REFERENCE=1`) and runs
|
|
465
|
+
the compare on every copy: `same` passes, each fault differs. With
|
|
466
|
+
`checks.time` registered it runs that on each copy too, its exit in the row
|
|
467
|
+
(`time exit`): 0 on `same`, non-zero on a fault, or `final` would pair a
|
|
468
|
+
wrong output. It runs only the copies `--make` made, never another folder in
|
|
469
|
+
the scratch directory.
|
|
470
|
+
|
|
471
|
+
```bash
|
|
472
|
+
python3 $AO/autoopt.py prove $WORK --make fault_value,fault_raise
|
|
473
|
+
# plant the two faults
|
|
474
|
+
python3 $AO/autoopt.py prove $WORK --compare "python3 $WORK/autooptimize/checks/compare.py {src} {reference}"
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
It takes the registered `checks.compare` when `--compare` is not given. `time_one.py`'s seconds should agree with the runner's
|
|
478
|
+
timing within its noise.
|
|
479
|
+
|
|
480
|
+
## Measure what concurrency does to the objective
|
|
481
|
+
|
|
482
|
+
One iteration runs at a time, so the runs at once are one iteration's:
|
|
483
|
+
`gpus_per_agent` (without a GPU, `gpus_per_agent` is the runs the iteration
|
|
484
|
+
starts at once). They decide how many benchmarks run at the same moment, and
|
|
485
|
+
for anything bound by memory bandwidth that number **changes the objective**.
|
|
486
|
+
Measure it on the real benchmark:
|
|
487
|
+
|
|
488
|
+
```bash
|
|
489
|
+
python3 $AO/autoopt.py width $WORK --write --background # writes autooptimize/setup/width.log; runs in $WORK/setup/width/
|
|
490
|
+
python3 $AO/autoopt.py wait $WORK/autooptimize/setup/width.log # repeat until `wait: finished`
|
|
491
|
+
```
|
|
492
|
+
|
|
493
|
+
It runs A0's code N at once, each run with its own scratch reference, for N
|
|
494
|
+
in 1, the powers of two up to twice the plan's runs at once, and the plan
|
|
495
|
+
(`--counts` overrides), twice each (`--reps`). It prints the table and the
|
|
496
|
+
largest count the rule below allows, says when that is narrower than the
|
|
497
|
+
plan (a question for the user), and with `--write` puts the verdict on
|
|
498
|
+
*Width measured*.
|
|
499
|
+
|
|
500
|
+
**Take the largest count at which neither the median nor the slowest run is
|
|
501
|
+
slower than the slowest run made alone by more than the runs made alone
|
|
502
|
+
spread** (their range, from the N = 1 rows: the baseline's noise band does
|
|
503
|
+
not exist yet). The slowest of several runs is slower than one by chance,
|
|
504
|
+
so the spread is the tolerance; past it, an iteration measured alone scores
|
|
505
|
+
better than an identical one inside a full set of concurrent runs, and the search ranks
|
|
506
|
+
scheduling luck. A 5-run median absorbs two slow runs and not three, so the
|
|
507
|
+
slowest run sets the limit before the median moves. One single-threaded CPU
|
|
508
|
+
benchmark, two repetitions per width:
|
|
509
|
+
|
|
510
|
+
| concurrent runs | median | slowest run |
|
|
511
|
+
|---|---|---|
|
|
512
|
+
| 1 | 0.917–0.926 s | 0.917–0.926 s |
|
|
513
|
+
| 4 | 0.901–0.907 s | 0.916–0.918 s |
|
|
514
|
+
| 8 | 0.899–0.908 s | 0.931–0.935 s |
|
|
515
|
+
| 12 | 0.899–0.902 s | 0.914–1.012 s |
|
|
516
|
+
| 16 | 0.904–0.923 s | 1.078–1.182 s |
|
|
517
|
+
|
|
518
|
+
The runs made alone spread 0.009 s, so the limit is 0.926 + 0.009 = 0.935 s.
|
|
519
|
+
The median never slows; at 8 the slowest run (0.935 s) stays within the
|
|
520
|
+
limit, and at 12 it passes it (1.012 s), so this benchmark supports eight
|
|
521
|
+
concurrent runs: `gpus_per_agent` can go to eight.
|
|
522
|
+
`width` says when other processes were busy while it measured: a width
|
|
523
|
+
measured under load is measured again once the machine is quiet. The answer
|
|
524
|
+
moves as the code changes: re-measure on the current root before raising
|
|
525
|
+
`gpus_per_agent`. Two searches running side by side share the budget, so
|
|
526
|
+
halve each one's `gpus_per_agent`.
|
|
527
|
+
|
|
528
|
+
## Check the machine is quiet
|
|
529
|
+
|
|
530
|
+
Size every thread and worker count inside what `spec.md`'s *Machine and
|
|
531
|
+
environment* line allows. On a CPU benchmark, before A0 runs: `python3 $AO/autoopt.py busy $WORK`
|
|
532
|
+
samples every process for two seconds and names each one outside this search
|
|
533
|
+
above about 110% of one core (`busy_percent` in `config.json`, or
|
|
534
|
+
`AUTOOPT_BUSY_PERCENT`), with its user, its share and its command (exit 1
|
|
535
|
+
when there is one). It reads `/proc`: on a machine without it, the check stops
|
|
536
|
+
with `needs /proc (Linux)`, and `AUTOOPT_SKIP_QUIET_CHECK=1` skips it.
|
|
537
|
+
The runner reports each run's CPU idle share (`idle 82%` in its report,
|
|
538
|
+
`runs[].idle` in `result.json`), and `width` prints it per concurrency. A busy machine is the user's decision (*Decisions that are the
|
|
539
|
+
user's*): ask with `setup --ask`, giving those processes and these options,
|
|
540
|
+
and on their answer run A0 as usual. The runner names what was busy at A0's
|
|
541
|
+
start in its report (`busy at start:`) and `result.json`, and never
|
|
542
|
+
refuses: when A0 ran under load, say so in its README and the ledger.
|
|
543
|
+
|
|
544
|
+
| Option | What it means |
|
|
545
|
+
|---|---|
|
|
546
|
+
| Hold off (Recommended) | run nothing until the machine is quiet; say what you will watch |
|
|
547
|
+
| Run the baseline now | its median and its spread are measured under load |
|
|
548
|
+
|
|
549
|
+
Recommend waiting: the baseline sets the frontier and the noise band, so
|
|
550
|
+
measured under load it makes every later iteration look like a win once the
|
|
551
|
+
other jobs finish.
|
|
552
|
+
|
|
553
|
+
**A library that threads by default turns one run into the whole machine.**
|
|
554
|
+
BLAS calls, a `prange`, a torch op and anything OpenMP take every core unless
|
|
555
|
+
told otherwise. Set the count in the benchmark (`OMP_NUM_THREADS`,
|
|
556
|
+
`numba.set_num_threads`, `torch.set_num_threads`) and check what ran:
|
|
557
|
+
|
|
558
|
+
```bash
|
|
559
|
+
python3 bench.py & echo $! > bench.pid # the launcher records the pid
|
|
560
|
+
ps -o nlwp,pcpu -p $(cat bench.pid)
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
Find a process by its pid file or its exit file, never with `pgrep -f` in a wait
|
|
564
|
+
loop: the loop's own command line holds the pattern, so it matches itself and
|
|
565
|
+
never ends.
|
|
566
|
+
|
|
567
|
+
`nlwp` counts threads that exist, not threads that run: numba allocates its
|
|
568
|
+
pool at import, so many threads at 100% CPU is one busy thread and a sleeping
|
|
569
|
+
pool. `pcpu` well above 100 is a run using more of the machine than planned.
|
|
570
|
+
|
|
571
|
+
## GPU leases
|
|
572
|
+
|
|
573
|
+
Two iterations never hold the same GPU, and no subagent picks a device from
|
|
574
|
+
`nvidia-smi` for itself. Which of two rules applies is read from `config.json`:
|
|
575
|
+
|
|
576
|
+
| `gpu_command` | The scripts | Everything else that runs the code |
|
|
577
|
+
|---|---|---|
|
|
578
|
+
| recorded (`init --gpu-command`, `config --set gpu_command=...`): the machine's allocator, as the words before a command (`srun --gres=gpu:1`) | run them bare. `run_iteration.py`, `check_seeding.py`, `prove`, `end` and `final` start themselves again under it when `CUDA_VISIBLE_DEVICES` is unset, and wait while no GPU is free (a try a minute, a day at most) | put the allocator's words before it: `paired.py`, `cold.py`, `width`, `check`, `validate`, a probe |
|
|
579
|
+
| none: a search made before `setup --done` required one | `setup --done` refuses a GPU search without it: record `env CUDA_VISIBLE_DEVICES=<index>` on a machine with no allocator. A search that already ran without one prefixes each with `CUDA_VISIBLE_DEVICES=<indices>`, the orchestrator giving each brief its own indices (`brief --gpus`) | the same prefix |
|
|
580
|
+
|
|
581
|
+
Allocator words before `width --background` or `validate --background` hold
|
|
582
|
+
the lease only until the command detaches, which is at once: the detached job
|
|
583
|
+
then runs with no lease. Detach the whole command, allocator included:
|
|
584
|
+
`python3 $AO/autoopt.py bg $WORK <log> '<allocator words> python3
|
|
585
|
+
$AO/autoopt.py validate …'`.
|
|
586
|
+
|
|
587
|
+
`gpus_per_agent` = 1 is one card, seeds one after another; with 4, the lease
|
|
588
|
+
is four cards (`CUDA_VISIBLE_DEVICES=2,3,4,5`, or four in `gpu_command`) and
|
|
589
|
+
four seeds run at once. The runner pins each run to one index and says so
|
|
590
|
+
when fewer were given than `gpus_per_agent`.
|
|
591
|
+
|
|
592
|
+
`setup --done` refuses a GPU search with no `gpu_command`:
|
|
593
|
+
`end` takes its lease through it, and so does anything run on the search
|
|
594
|
+
afterwards. On a machine with no allocator that the user has to themselves,
|
|
595
|
+
record `env CUDA_VISIBLE_DEVICES=<index>` with the index they named: it sets
|
|
596
|
+
the variable for the command after it, which is all the scripts ask of an
|
|
597
|
+
allocator. `error: CUDA_VISIBLE_DEVICES is unset, so this run holds no
|
|
598
|
+
GPU lease` means neither rule was met; an allocator that does not set
|
|
599
|
+
`CUDA_VISIBLE_DEVICES` for the command after it is refused. A benchmark that
|
|
600
|
+
needs no GPU is initialized with `init --no-gpu`, which lifts the check.
|
|
601
|
+
|
|
602
|
+
## Running the baseline
|
|
603
|
+
|
|
604
|
+
```bash
|
|
605
|
+
python3 $AO/run_iteration.py $WORK/autooptimize/iterations/0
|
|
606
|
+
# a GPU search with no gpu_command: the CUDA_VISIBLE_DEVICES prefix (*GPU leases*); add --background when it may pass
|
|
607
|
+
# four minutes, then wait on iterations/0/probe/runner.log
|
|
608
|
+
```
|
|
609
|
+
|
|
610
|
+
A0 runs `runs_per_iteration` runs, like every iteration: its median is the first frontier, and its spread across runs sets the noise band. Check
|
|
611
|
+
three things in its report; one that fails is a question for the user
|
|
612
|
+
(*Decisions that are the user's*):
|
|
613
|
+
|
|
614
|
+
1. **The objective moves across seeds, but not wildly.** A standard deviation
|
|
615
|
+
of zero means the seed reaches nothing that varies. One as large as the
|
|
616
|
+
hoped-for improvement means more runs per iteration, and that is cheapest
|
|
617
|
+
to decide at this step.
|
|
618
|
+
2. **Every gate passes, with margin.** A baseline sitting on its own gate
|
|
619
|
+
leaves no room: is the threshold right?
|
|
620
|
+
3. **One run's wall clock.** Multiply by the runs per iteration, the round
|
|
621
|
+
size and the number of rounds. If the product is a week, the plan changes
|
|
622
|
+
at this step: a smaller input, fewer runs per iteration, fewer thread counts.
|
|
623
|
+
|
|
624
|
+
In repository mode the unit tests MUST pass on A0 (`references/repo-mode.md`,
|
|
625
|
+
*Setting it up*, step 5).
|
|
626
|
+
|
|
627
|
+
## The price of the base
|
|
628
|
+
|
|
629
|
+
When A0 finishes, the runner prints what each later step that runs the base
|
|
630
|
+
costs, from A0's own seconds a run (`autoopt.py price $WORK` prints it again):
|
|
631
|
+
an iteration, the base's side of the paired timing at `end` and, in
|
|
632
|
+
repository mode, a re-measurement of the base outside the search. A line of an hour or more is marked `!`, and the paired
|
|
633
|
+
timing is marked when `end` would refuse it under `after.pair_cap_hours` (4).
|
|
634
|
+
|
|
635
|
+
With `floor` set (step 0), the table also says how many times A0 is above
|
|
636
|
+
it, marked under 20: a search can gain more than tenfold, and one that reaches
|
|
637
|
+
the floor stops there with nothing left to resolve.
|
|
638
|
+
|
|
639
|
+
With a marked line, ask the user before step 2 closes (`setup --ask`), with
|
|
640
|
+
the table: a smaller input for the timing probe (`checks.time`), the cap
|
|
641
|
+
raised, or the prices as they are; for the floor, a larger input. The objective's own input stays the user's.
|
|
642
|
+
|
|
643
|
+
With `workers` set, `setup --done` refuses while A0's runs never had that many
|
|
644
|
+
threads running at once (`result.json` `workers`): the count the task names
|
|
645
|
+
is not in effect, such as a launcher that failed to start and left one rank.
|
|
646
|
+
|
|
647
|
+
## After the baseline
|
|
648
|
+
|
|
649
|
+
Write A0's profile with `python3 $AO/autoopt.py profile $WORK --id A0`
|
|
650
|
+
(`iterations/0/profile.txt`; every later root gets one from `promote`). Then
|
|
651
|
+
write the first ledger entries in its format
|
|
652
|
+
(`references/shared-knowledge.md`) to `$WORK/autooptimize/setup/ledger.txt`:
|
|
653
|
+
the machine and toolchain (`[machine]`), what the harness measures and how
|
|
654
|
+
(`[harness]`), and the baseline's largest shares from that profile
|
|
655
|
+
(`[code:<subsystem>]`).
|
|
656
|
+
|
|
657
|
+
Write A0's notes the way every iteration does, in `iterations/0/notes.md`,
|
|
658
|
+
as `## ` sections in this order, each non-empty, with nothing before the
|
|
659
|
+
first: `## The idea`, what the baseline is; `## What happened`, its numbers in
|
|
660
|
+
words; `## Notes and failures`, anything surprising in the setup; `## What to
|
|
661
|
+
try next`, "the idea miner's stages in `ideas.md`". Then one call writes the
|
|
662
|
+
README and appends the entries:
|
|
663
|
+
|
|
664
|
+
```bash
|
|
665
|
+
python3 $AO/autoopt.py finish $WORK --id A0 --ledger $WORK/autooptimize/setup/ledger.txt
|
|
666
|
+
```
|
|
667
|
+
|
|
668
|
+
## Closing step 2
|
|
669
|
+
|
|
670
|
+
```bash
|
|
671
|
+
python3 $AO/autoopt.py setup $WORK --done
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
It refuses with `step 2 is not finished`, one line per item missing: a TODO
|
|
675
|
+
left in `spec.md`, A0 not `ok` with its full count of runs, A0 without a
|
|
676
|
+
README, no entry in `knowledge.md`, a question still waiting for the user,
|
|
677
|
+
in a GPU search no `gpu_command`, with `workers` set an A0 that never ran that many threads at once, and, in an algorithm search, `checks.compare` or
|
|
678
|
+
`checks.time` not registered or A0's compare outputs not cached. Then report back exactly this, and
|
|
679
|
+
nothing more:
|
|
680
|
+
|
|
681
|
+
1. The *Gate proof* and *Width measured* lines you wrote in `spec.md`.
|
|
682
|
+
2. The block `run_iteration.py` printed for A0.
|
|
683
|
+
3. Each check's proof, one line each: it passes on unchanged code and fails
|
|
684
|
+
on its planted faults.
|
|
685
|
+
4. The documented speed options' verdict: the table's rows that moved the objective, or "no documented option moves it".
|
|
686
|
+
5. At most two sentences of anything else the main session must know.
|
|
687
|
+
|
|
688
|
+
## A benchmark skeleton
|
|
689
|
+
|
|
690
|
+
The reference gate and the parse-once load are the snippets above.
|
|
691
|
+
|
|
692
|
+
```python
|
|
693
|
+
count_words(lines) # warmup on the full input
|
|
694
|
+
start = time.perf_counter()
|
|
695
|
+
counts = count_words(lines) # the one timed call
|
|
696
|
+
seconds = time.perf_counter() - start
|
|
697
|
+
|
|
698
|
+
times = [] # latency gate: one line is too short to time alone
|
|
699
|
+
for i in range(200):
|
|
700
|
+
start = time.perf_counter()
|
|
701
|
+
count_words(lines[i:i + 1])
|
|
702
|
+
times.append((time.perf_counter() - start) * 1000)
|
|
703
|
+
|
|
704
|
+
json.dump({'objective': seconds,
|
|
705
|
+
'gates': {'single_line_ms': float(numpy.median(times)), 'n_mismatch_vs_base': n_mismatch},
|
|
706
|
+
'observers': {'peak_rss_mb': resource.getrusage(resource.RUSAGE_SELF).ru_maxrss / 1024}},
|
|
707
|
+
open(os.path.join(args.out, 'metrics.json'), 'w'))
|
|
708
|
+
```
|