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,224 @@
|
|
|
1
|
+
# Repository mode: optimizing code in a git repository
|
|
2
|
+
|
|
3
|
+
Use it when the code lives in a git repository. Plain mode (`init --copy`) is for a benchmark with no
|
|
4
|
+
git repository as its base.
|
|
5
|
+
|
|
6
|
+
## What it guarantees
|
|
7
|
+
|
|
8
|
+
- **The original is never written to.** `init --repo` makes a bare clone at
|
|
9
|
+
`autooptimize/repo.git`, its objects hardlinked when on the same filesystem
|
|
10
|
+
(almost no disk), and removes its `origin` remote, which is the original's
|
|
11
|
+
own directory. No command before step 5 writes outside the search; step 5
|
|
12
|
+
writes to the original only on the user's yes (`references/step5-ship.md`).
|
|
13
|
+
- **Each branch is the path.** `autoopt/<id>` is the original's history up to
|
|
14
|
+
the copied commit, followed by one commit per iteration on the path to
|
|
15
|
+
`<id>` (*path* in `references/glossary.md`).
|
|
16
|
+
|
|
17
|
+
## Layout
|
|
18
|
+
|
|
19
|
+
```
|
|
20
|
+
autooptimize/
|
|
21
|
+
repo.git/ bare clone of the original; no remotes
|
|
22
|
+
harness/ the benchmark: --copy lands here; fixed for the search
|
|
23
|
+
iterations/
|
|
24
|
+
0/
|
|
25
|
+
src/ worktree on autoopt/0: the original at the copied commit
|
|
26
|
+
meta.json result.json notes.md README.md runs/ unit-tests/
|
|
27
|
+
7/
|
|
28
|
+
src/ worktree on autoopt/7
|
|
29
|
+
… records beside src/, never inside it
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Records sit beside `src/` so the iteration's `README.md` cannot overwrite the
|
|
33
|
+
repository's own. `repo.git/info/exclude` hides only `__pycache__/`, `*.pyc`,
|
|
34
|
+
`.pytest_cache/` and `*.egg-info/`, so a new `README.md` or `.npz` inside the
|
|
35
|
+
package is committed like any other file.
|
|
36
|
+
|
|
37
|
+
## Setting it up
|
|
38
|
+
|
|
39
|
+
**1. Check the original.** Its checked-out branch is where the copy starts and
|
|
40
|
+
what the winner is later compared with and merged onto; `config.json["repo"]` records it, with the
|
|
41
|
+
commit and the remote. When step 0 settled on a new unit-test suite, the
|
|
42
|
+
original here is the suite's clone, and `init` runs at the end of step 1
|
|
43
|
+
(`references/step1-unit-tests.md`).
|
|
44
|
+
|
|
45
|
+
| Found | What `init` does | Do |
|
|
46
|
+
|---|---|---|
|
|
47
|
+
| uncommitted changes to tracked files | refuses, and lists them | ask the user: commit them in their repository, or re-run with `--allow-dirty` to start from the last commit without them |
|
|
48
|
+
| untracked files | copies nothing untracked, and says nothing | check `git -C <original> --no-optional-locks status` (a plain `status` rewrites the original's index) for data the benchmark needs; pass it with `--copy` (into `harness/`) or put it in `autooptimize/reference/`, never into `src/` |
|
|
49
|
+
| detached HEAD | refuses | check out the branch the search should start from |
|
|
50
|
+
|
|
51
|
+
**2. Write the harness.** It takes `--src`, imports the package from that
|
|
52
|
+
directory, and meets the `metrics.json` contract in `references/layout.md`.
|
|
53
|
+
It lives in `harness/`, outside every worktree, so no iteration can change
|
|
54
|
+
what is measured; a change to the harness is a new search. Pass it to `init`
|
|
55
|
+
with `--copy` from outside `autooptimize/`, or the setup subagent writes it
|
|
56
|
+
into `harness/` at step 2.
|
|
57
|
+
|
|
58
|
+
```python
|
|
59
|
+
"""One run, importing the package from the worktree it is pointed at."""
|
|
60
|
+
|
|
61
|
+
import os, sys, json, argparse
|
|
62
|
+
|
|
63
|
+
parser = argparse.ArgumentParser()
|
|
64
|
+
parser.add_argument('--src', required=True)
|
|
65
|
+
parser.add_argument('--iteration', required=True) # for a reference gate: references/step2-baseline.md
|
|
66
|
+
parser.add_argument('--seed', type=int, required=True)
|
|
67
|
+
parser.add_argument('--out', required=True)
|
|
68
|
+
args = parser.parse_args()
|
|
69
|
+
|
|
70
|
+
src = os.path.realpath(args.src)
|
|
71
|
+
sys.path.insert(0, src)
|
|
72
|
+
|
|
73
|
+
import mypackage # the package the search optimizes
|
|
74
|
+
|
|
75
|
+
# Without this, an installed copy can win and every iteration measures it.
|
|
76
|
+
assert os.path.realpath(mypackage.__file__).startswith(src + os.sep), \
|
|
77
|
+
mypackage.__file__
|
|
78
|
+
|
|
79
|
+
os.makedirs(args.out, exist_ok=True)
|
|
80
|
+
# ... measure, then write metrics.json with 'note': mypackage.__file__
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
**3. Init.** `{src}` expands to the iteration's worktree. Write the harness
|
|
84
|
+
path absolute, in double quotes so the shell expands `$WORK` (placeholder
|
|
85
|
+
rules: `references/layout.md`, *config.json*). `AUTOOPT_REF` and
|
|
86
|
+
`--iteration {iteration}` serve a gate against the baseline's output
|
|
87
|
+
(`references/step2-baseline.md`, *A gate that compares against the baseline's
|
|
88
|
+
output*); drop both when there is none.
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
python3 $AO/autoopt.py init $WORK \
|
|
92
|
+
--repo /path/to/<repository> \
|
|
93
|
+
--copy /path/to/bench.py \
|
|
94
|
+
--command "AUTOOPT_REF=$WORK/autooptimize/reference PYTHONPATH={src} python3 $WORK/autooptimize/harness/bench.py --src {src} --iteration {iteration} --seed {seed} --out {out}" \
|
|
95
|
+
--tests 'PYTHONPATH={src} OMP_NUM_THREADS=4 python3 -m pytest -q tests' \
|
|
96
|
+
--tests-timeout 1800 \
|
|
97
|
+
--objective seconds --direction min --unit s --observers peak_mb …
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Code compiled by numba, Triton or `torch.compile` also sets
|
|
101
|
+
`NUMBA_CACHE_DIR={cache}/numba TRITON_CACHE_DIR={cache}/triton
|
|
102
|
+
TORCHINDUCTOR_CACHE_DIR={cache}/inductor` in both strings
|
|
103
|
+
(`references/measuring.md`, *A cached compile can outlive the edit*). The rest
|
|
104
|
+
of `init` is as in `references/step0-interview.md`. Add `autooptimize/` to the
|
|
105
|
+
ignore list of the project that holds the search, not of the copied
|
|
106
|
+
repository.
|
|
107
|
+
|
|
108
|
+
**4. Find the oldest toolchain the repository supports** (its pinned Cython or
|
|
109
|
+
compiler) and record the command that builds and tests a tree with it:
|
|
110
|
+
`autoopt.py config $WORK --set 'after.oldest_toolchain_command=<command with {src}>'
|
|
111
|
+
--reason "..."`. `promote` then runs it on every iteration it promotes
|
|
112
|
+
(`references/promotion.md`, *The preflight*). The search's environment usually
|
|
113
|
+
has the newest compiler, and newer syntax compiles in every iteration and
|
|
114
|
+
fails in the repository's CI: `requirements.txt` may pin `Cython<3.1` while
|
|
115
|
+
`pyproject.toml` asks for `Cython>=3.0`, and Cython 3.0 lacks
|
|
116
|
+
`cython.pointer[T]` (write `cython.pointer(T)`) and `cython.p_const_char`.
|
|
117
|
+
|
|
118
|
+
**5. Run the baseline** (the setup subagent, `references/step2-baseline.md`).
|
|
119
|
+
**The unit tests MUST pass on it.** If some fail on unmodified code, the
|
|
120
|
+
failing test ids go to the user (`setup --ask`). With their agreement, the
|
|
121
|
+
`--tests` command deselects them (`--deselect tests/test_x.py::test_y`, set
|
|
122
|
+
with `config --set tests.command=…`) and `spec.md` lists them. Never deselect
|
|
123
|
+
a test that an iteration broke.
|
|
124
|
+
|
|
125
|
+
## Import from the worktree, never the installed package
|
|
126
|
+
|
|
127
|
+
A package under development is usually an editable install of the original.
|
|
128
|
+
Without `PYTHONPATH`, `import <package>` resolves there from any directory,
|
|
129
|
+
and the runner starts each run in `iterations/<id>/`, not in `src/`, so the
|
|
130
|
+
working directory does not rescue it. **The symptom is every iteration
|
|
131
|
+
matching the baseline to the last digit.** A non-editable installed copy
|
|
132
|
+
fails the same way.
|
|
133
|
+
|
|
134
|
+
- The harness's `sys.path.insert` covers its own import. Set
|
|
135
|
+
`PYTHONPATH={src}` as well, in the command and in `--tests`: it comes before
|
|
136
|
+
site-packages and a subprocess inherits it, so the package's command-line
|
|
137
|
+
entry points and the test suite also import the worktree.
|
|
138
|
+
- Keep the `__file__` assertion in the harness and record `__file__` in
|
|
139
|
+
`note`.
|
|
140
|
+
- **Never run `pip install` or `uv pip install -e` on a worktree.** That
|
|
141
|
+
points the shared environment at one iteration, for every iteration and every
|
|
142
|
+
other search that uses it.
|
|
143
|
+
- **A package with compiled extensions is built in place inside each
|
|
144
|
+
worktree**, as a prefix to both `--command` and `--tests`. For setuptools:
|
|
145
|
+
`(cd {src} && python3 setup.py build_ext --inplace -q) && …`, which skips
|
|
146
|
+
up-to-date extensions, so after a commit's first run it costs seconds. With
|
|
147
|
+
`gpus_per_agent` above 1 several runs start at once and race on the build;
|
|
148
|
+
put `flock {cache}/build.lock` (Linux) in front of it.
|
|
149
|
+
- **A project that is built, not installed** (C, C++, Rust; no `pyproject.toml`
|
|
150
|
+
or `setup.py`) is the same with its own build: `(cd {src} && make -j8 -s) && …`
|
|
151
|
+
in `--command`, and `make -C {src} test` (or the repository's test target) as
|
|
152
|
+
`--tests`. The build alone is also `checks.build`
|
|
153
|
+
(`references/step2-baseline.md`, *Write the checks*).
|
|
154
|
+
|
|
155
|
+
## The unit-test gate
|
|
156
|
+
|
|
157
|
+
`--tests` gives a command that runs **once per iteration**, in `src/`, after
|
|
158
|
+
the first run passes its gates and before the other runs (and a second time,
|
|
159
|
+
whole, when it uses `{selected}` and the median passes the keep rule). It also works in plain mode, where it
|
|
160
|
+
runs in the iteration directory.
|
|
161
|
+
|
|
162
|
+
| | |
|
|
163
|
+
|---|---|
|
|
164
|
+
| Pass | exit code 0. Anything else fails, including pytest's 5, "no tests collected", which almost always means the wrong directory |
|
|
165
|
+
| Failure | `status: gate-failed`, off the frontier. The table's `tests` column reads `FAIL` |
|
|
166
|
+
| Record | `result.json["tests"]` (fields: `references/layout.md`); output in `unit-tests/log.txt` |
|
|
167
|
+
| Not run | when the first run crashed or broke a gate. The column reads `-` |
|
|
168
|
+
| Resume | a result for the same commit is reused; `--rerun` runs the suite again |
|
|
169
|
+
| Placeholders | `{src}`, `{iteration}`, `{out}` (the `unit-tests/` directory), `{cache}` (shared with the runs of the same commit), `{selected}` (below) |
|
|
170
|
+
| GPU | inherits the iteration's GPUs |
|
|
171
|
+
| Artifacts | untracked files the run writes into the worktree (an index such as `data.csv.idx`) are removed after it, listed in the log's last line and `result.json["tests"]["removed"]`, and recorded in `autooptimize/test-artifacts.txt`. The runner's commit leaves a recorded artifact out, a recorded artifact is no unmeasured change, and `promote` refuses a commit that adds one: `git rm --cached` it and measure again. The runner's own `.autoopt-build.lock` and `.autoopt-build.log` (`autoopt.RUNNER_FILES`) are never committed or counted as unmeasured; any other untracked file outside `after.build_outputs` (`references/step0-interview.md`, *The questions*) is an unmeasured change |
|
|
172
|
+
|
|
173
|
+
**Run only the tests for the changed code, and the whole suite only on a
|
|
174
|
+
possible winner.** Put `{selected}` where the test paths go:
|
|
175
|
+
|
|
176
|
+
```
|
|
177
|
+
--tests 'PYTHONPATH={src} NUMBA_CACHE_DIR={cache}/numba python3 -m pytest -x -q {selected}' --tests-path tests
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
| Changed against the parent's commit | `{selected}` becomes |
|
|
181
|
+
|---|---|
|
|
182
|
+
| `pkg/foo.py` | every `test_foo.py` under `--tests-path` |
|
|
183
|
+
| `tests/test_foo.py` | itself |
|
|
184
|
+
| `__init__.py`, `conftest.py`, any other file under the tests path, a non-Python file, a module with no `test_<name>.py`, nothing at all, or an iteration with no parent | the whole tests path |
|
|
185
|
+
|
|
186
|
+
The runner runs the whole suite on an iteration whose median passes the
|
|
187
|
+
default keep rule, since only such an iteration can be promoted.
|
|
188
|
+
`promote` refuses one whose last pass was a subset and prints the command
|
|
189
|
+
that fixes it, `run_iteration.py <dir> --full-tests`: with `promote:
|
|
190
|
+
orchestrator`, an iteration promoted on the user's own rule may need it. The
|
|
191
|
+
table's `tests` column reads `pass sub` for a subset pass.
|
|
192
|
+
|
|
193
|
+
**In a timing search, the suite runs on a machine other jobs time on.** Pin
|
|
194
|
+
every thread pool the package uses (`OMP_NUM_THREADS` above; also
|
|
195
|
+
`NUMBA_NUM_THREADS`, `MKL_NUM_THREADS` or a torch setting where they apply):
|
|
196
|
+
an unpinned suite spreads over every core and inflates the objective of
|
|
197
|
+
whatever else is timing there. **Pin to the smallest count the suite needs, not to 1**,
|
|
198
|
+
after grepping the tests for skips on thread count: a suite that skips every
|
|
199
|
+
test with `n_jobs > numba.config.NUMBA_NUM_THREADS` under
|
|
200
|
+
`NUMBA_NUM_THREADS=1` silently drops the tests of the parallel path a speed
|
|
201
|
+
search is most likely to break.
|
|
202
|
+
|
|
203
|
+
## What this mode adds to the interview
|
|
204
|
+
|
|
205
|
+
Rows for group 4 of `references/step0-interview.md`, *The questions*. The
|
|
206
|
+
first is asked in these words, and never assumed.
|
|
207
|
+
|
|
208
|
+
| Group | Question | Options to offer | Default | Recorded in `spec.md` |
|
|
209
|
+
|---|---|---|---|---|
|
|
210
|
+
| 4 | "Do you want to add new unit tests?" | no; yes, which needs the original's branch committed and pushed to its remote (`references/step1-unit-tests.md`) | none: always asked | New unit tests |
|
|
211
|
+
| 4 | On a yes: for the functions being optimized, or the whole repository? | the functions being optimized (Recommended); the whole repository | none: always asked, though one option is recommended (step 0's one exception) | New unit tests |
|
|
212
|
+
| 4 | Which command runs the repository's tests, and with how many threads? | the command its CI runs, with thread pools pinned | from CI | the `--tests` flag |
|
|
213
|
+
|
|
214
|
+
## Common errors
|
|
215
|
+
|
|
216
|
+
| Message or symptom | Cause | Do |
|
|
217
|
+
|---|---|---|
|
|
218
|
+
| `has uncommitted changes to tracked files` | the original is dirty | ask the user; commit there, or `--allow-dirty` |
|
|
219
|
+
| `unit tests: FAIL` on A0 | tests that already failed | ask the user; deselect those tests and record them in `spec.md` |
|
|
220
|
+
| `fatal: '…/src' is a missing but already registered worktree` | a `src/` was deleted by hand | `git -C repo.git worktree prune`, then re-run `new` or `restore` |
|
|
221
|
+
| `a branch named autoopt/7 already exists` | `new --new-id 7` named an id whose iteration was moved aside but whose branch remains | brief the next free id; `reset` removes both |
|
|
222
|
+
| `fatal: invalid reference: autoopt/9` | the parent's branch does not exist | check `--parent` against `autoopt.py status` |
|
|
223
|
+
| `has no git checkout: it was pruned` | `prune --worktrees` removed `src/` | `autoopt.py restore $WORK --id N` |
|
|
224
|
+
| a new file in the package is missing from the branch | it matches the repository's own `.gitignore` | say so in the README; `git add -f` inside `src/` if it belongs in the change |
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# Picking up a search already in progress
|
|
2
|
+
|
|
3
|
+
The session that started a search is rarely the one that finishes it. None of
|
|
4
|
+
its context survives; everything needed is on disk.
|
|
5
|
+
|
|
6
|
+
This file is for continuing the search. To answer a question about the
|
|
7
|
+
search without continuing it, read `references/reading-a-search.md` instead.
|
|
8
|
+
|
|
9
|
+
## First: has the search ended?
|
|
10
|
+
|
|
11
|
+
`autooptimize/ended.json` means it has (`references/step4-final.md`). Read
|
|
12
|
+
`ended.md`, put the publisher back up if it died (`end` leaves it running
|
|
13
|
+
and writes `final/dashboard.html`; step 6 stops it), and go on with step 5
|
|
14
|
+
(`references/step5-ship.md`): `stages.py next $WORK` says whether the user has
|
|
15
|
+
been asked how to ship and what is left, then step 6
|
|
16
|
+
(`references/step6-finish.md`).
|
|
17
|
+
`end --reopen` is only for a user who wants the search itself to go on, and
|
|
18
|
+
is refused once step 5 has shipped the winner (applied it, made a branch or
|
|
19
|
+
posted a document). Otherwise:
|
|
20
|
+
|
|
21
|
+
## The main session
|
|
22
|
+
|
|
23
|
+
**Put the dashboard publisher back up.** It may have died with the old
|
|
24
|
+
session. Start it before reading anything, so it scans while you read; it
|
|
25
|
+
prints `already running` if the old one is still up.
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
python3 $AO/dashboard/autoopt_monitor.py $WORK/autooptimize --start
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
**Read where it got to** with `python3 $AO/autoopt.py status $WORK --brief`,
|
|
32
|
+
then act on what it names:
|
|
33
|
+
|
|
34
|
+
- **a `setup (step 2):` line**: the setup subagent died with the old session.
|
|
35
|
+
A question waiting for the user goes to them, and `setup --answer` prints
|
|
36
|
+
the prompt for a new subagent; otherwise `setup --force` prints one that
|
|
37
|
+
continues from the notes (`references/step0-interview.md`, *Handing off
|
|
38
|
+
step 2*). Step 3 starts once `status` stops printing `first iteration:
|
|
39
|
+
waiting for …`;
|
|
40
|
+
- **a phase still open**: its orchestrator subagent died with the old
|
|
41
|
+
session. `loop $WORK --force` replaces it; the new phase acts on the
|
|
42
|
+
unfinished iterations (below).
|
|
43
|
+
|
|
44
|
+
Tell the user what changed since they last looked and the plan before the
|
|
45
|
+
next phase starts; the search may have reached *When to stop*
|
|
46
|
+
(`references/step3-rounds.md`). Then go on with `references/main-session.md`.
|
|
47
|
+
|
|
48
|
+
## The orchestrator subagent
|
|
49
|
+
|
|
50
|
+
Your first call, `python3 $AO/autoopt.py status $WORK --resume`, says where the
|
|
51
|
+
search got to. `spec.md` holds what `config.json` has no field for: the keep
|
|
52
|
+
rule, the rules added during the search, what is off limits.
|
|
53
|
+
`autooptimize/briefs/<id>.md` holds what each subagent was told.
|
|
54
|
+
|
|
55
|
+
## Then act on each unfinished iteration
|
|
56
|
+
|
|
57
|
+
**Iterations**, by the verdict `--resume` gives each:
|
|
58
|
+
|
|
59
|
+
| Verdict | Do |
|
|
60
|
+
|---|---|
|
|
61
|
+
| its runner is alive | leave it: resuming it runs the same seeds twice |
|
|
62
|
+
| its subagent wrote recently | it may still be working (a resume after a compaction keeps its subagent): look again before handing it on |
|
|
63
|
+
| an empty fork, never edited | set it aside with the two commands it names; its branch `autoopt/<id>` stays and keeps the id taken, and `new` without `--id` skips it |
|
|
64
|
+
| edited, not measured; measured, no README; partial | hand it to a new subagent with the prompt `autoopt.py brief $WORK --prompt <id>` prints, which carries the line for where the last one stopped. Seeds already measured on its current commit are not run again |
|
|
65
|
+
|
|
66
|
+
A `partial` row is already excluded from the frontier, and may instead be set
|
|
67
|
+
aside.
|
|
68
|
+
|
|
69
|
+
**GPUs still held.** A live runner holds its GPUs. Check what is free before
|
|
70
|
+
briefing the next iteration.
|
|
71
|
+
|
|
72
|
+
## Rebuild the idea list if it needs it
|
|
73
|
+
|
|
74
|
+
`autooptimize/ideas.md` is the queue the idea miner fills, with tried ideas
|
|
75
|
+
struck through and the decisions taken while the user was away. Do not
|
|
76
|
+
rebuild it yourself: when `status` says fewer than two untried ideas are left, or the
|
|
77
|
+
file is missing, run `autoopt.py mine $WORK` and spawn the miner, which reads
|
|
78
|
+
the READMEs and the ledger in its own context. A stage `status` shows as
|
|
79
|
+
running whose miner died with the old session needs `mine --force`.
|
|
80
|
+
|
|
81
|
+
Then go on with *The loop* (`references/step3-rounds.md`).
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# What one subagent learns, the next one reads
|
|
2
|
+
|
|
3
|
+
Subagents start cold: unless the search keeps what each learned, every
|
|
4
|
+
iteration re-reads the same code, re-measures the same premises and rewrites
|
|
5
|
+
the same helpers: the same alternate build, the same side-by-side checker.
|
|
6
|
+
|
|
7
|
+
`init` starts three shared files under `autooptimize/`, outside every
|
|
8
|
+
worktree. None of them is the harness, and none changes a measurement.
|
|
9
|
+
|
|
10
|
+
| What | Path | Who writes it |
|
|
11
|
+
|---|---|---|
|
|
12
|
+
| knowledge ledger | `knowledge.md` | every subagent, the setup subagent and the idea miner included (*The knowledge ledger*) |
|
|
13
|
+
| shared tools | `tools/`, listed in `tools/README.md` | a subagent (*Shared tools*) |
|
|
14
|
+
| checker library | `tools/checkers/<subsystem>-<label>/`, listed in `tools/checkers/README.md` | the subagent that wrote the checker, every time (sources and scripts, not build trees) |
|
|
15
|
+
|
|
16
|
+
These are the only places a subagent writes outside its iteration directory.
|
|
17
|
+
|
|
18
|
+
## The knowledge ledger
|
|
19
|
+
|
|
20
|
+
Append only, so the miner and the iteration subagents cannot clobber each other: each writes
|
|
21
|
+
its entries to `$DIR/probe/ledger.txt` and appends them under the ledger's
|
|
22
|
+
lock with `python3 $AO/autoopt.py ledger $WORK --by <label> --add
|
|
23
|
+
$DIR/probe/ledger.txt` (Linux `flock`). An entry is one to three lines:
|
|
24
|
+
|
|
25
|
+
```markdown
|
|
26
|
+
- [machine] AVX-512 VNNI present; 32 MB L3 per 8-core group (A0, root A0).
|
|
27
|
+
- [code:scoring] the inner loop is 71% of the timed call (A0, root A0).
|
|
28
|
+
- [closed] Score-only pre-pass refuted: 77% of cases still need the full pass (A1, root A0).
|
|
29
|
+
- [code:scoring] the inner loop is 38% of the timed call after A6's hoist (A8, root A7) (corrects: inner loop is 71%)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
The last entry is a correction: `ledger --add` strikes the one older entry
|
|
33
|
+
holding the words after `corrects:` ("- ~~… 71% of the timed call (A0, root
|
|
34
|
+
A0)~~ corrected by A8") and appends it. When the words match no entry or
|
|
35
|
+
several, it writes nothing and says so.
|
|
36
|
+
|
|
37
|
+
| Tag | For |
|
|
38
|
+
|---|---|
|
|
39
|
+
| `machine` | hardware, toolchain, versions |
|
|
40
|
+
| `harness` | what the benchmark measures, and how |
|
|
41
|
+
| `code:<subsystem>` | facts about one part of the code: costs, shapes, invariants |
|
|
42
|
+
| `closed` | ideas refuted or closed, with the number that closed them |
|
|
43
|
+
| `bug` | bugs found in the code or the base, not fixed by the search |
|
|
44
|
+
|
|
45
|
+
Every entry names the label that established it, its number, and the root it
|
|
46
|
+
was measured on.
|
|
47
|
+
|
|
48
|
+
| Who | Does |
|
|
49
|
+
|---|---|
|
|
50
|
+
| setup subagent, after the baseline | appends the machine, the toolchain, what the harness measures, and a profile of the baseline, with `ledger --by A0` |
|
|
51
|
+
| `autoopt.py brief` | points every brief at the ledger; `--sections` names the tags that matter for the idea |
|
|
52
|
+
| subagent, first | reads it before reading code or planning; a premise it settles is not measured again |
|
|
53
|
+
| subagent, last | appends what it established and a correction for what it disproved, with `finish --ledger`; if writing a `.md` file is refused, returns the entries in its reply |
|
|
54
|
+
| orchestrator | checks nothing in it; it saves only the entries a reply returned because writing was refused |
|
|
55
|
+
|
|
56
|
+
A fact without its root goes stale silently: costs and shares move as the
|
|
57
|
+
code changes. A brief that quotes a number from an older root names that
|
|
58
|
+
root, so the subagent measures it again (`references/measuring.md`,
|
|
59
|
+
*Profile the root you are actually on*).
|
|
60
|
+
|
|
61
|
+
## Shared tools
|
|
62
|
+
|
|
63
|
+
A helper goes in `tools/` the second time anyone writes it, or the first time
|
|
64
|
+
when the brief or the ledger says later iterations will need it. Usual
|
|
65
|
+
candidates:
|
|
66
|
+
|
|
67
|
+
- the alternate builds the checks need (debug, sanitized, another ISA level,
|
|
68
|
+
CI's variants) and the test run against them;
|
|
69
|
+
- a profiler wrapper that knows the platform's pitfalls;
|
|
70
|
+
- a cached scratch build (below).
|
|
71
|
+
|
|
72
|
+
Each tool gets a row in `tools/README.md`, appended under a lock
|
|
73
|
+
(`T=$WORK/autooptimize/tools/README.md; flock "$T" -c "cat >> '$T'" <
|
|
74
|
+
$DIR/probe/row.md`, Linux): what it does, typical use, and its measured
|
|
75
|
+
cost. A tool's interface is documented
|
|
76
|
+
there, not only in a docstring.
|
|
77
|
+
|
|
78
|
+
## The checker library
|
|
79
|
+
|
|
80
|
+
A checker for a change that must keep outputs identical runs the parent's and
|
|
81
|
+
the new code side by side on every call and compares the full result. It is
|
|
82
|
+
specific to a subsystem and costly to write, and the next change there needs
|
|
83
|
+
it again. `autoopt.py finish --checker` runs it on the parent and the new
|
|
84
|
+
code, then copies it into `tools/checkers/<subsystem>-<label>/` with its
|
|
85
|
+
full row in `ROW.md` there (the files it guards, what it compares, how it is
|
|
86
|
+
built, the `run` line, its planted-fault controls, its inputs and its measured
|
|
87
|
+
run time) and one line in `tools/checkers/README.md`, the index every
|
|
88
|
+
iteration reads (`references/subagent.md`, *Before you stop*). `autoopt.py
|
|
89
|
+
checkers --touched` runs every checker guarding a file an edit changes, so
|
|
90
|
+
nobody reads a checker's code to learn how to run it.
|
|
91
|
+
|
|
92
|
+
## A cached scratch build
|
|
93
|
+
|
|
94
|
+
When the build compiles every source of a binary in one compiler command
|
|
95
|
+
(common in Makefiles), every variant or checker build pays the whole
|
|
96
|
+
compile. A tool can take the build's exact commands (`make -n -B <goal>`),
|
|
97
|
+
compile each source separately under ccache with the same flags, and link
|
|
98
|
+
with the same command, so a one-file change rebuilds in seconds. Pitfalls:
|
|
99
|
+
|
|
100
|
+
- Point `CCACHE_DIR` at one cache for the whole search (`tools/ccache/`), the
|
|
101
|
+
one scratch area outside `$DIR/probe`; a cache per iteration reuses nothing.
|
|
102
|
+
- Set `CCACHE_BASEDIR` to the copied tree and `CCACHE_NOHASHDIR=1`, or `-g`
|
|
103
|
+
makes every directory a cache miss.
|
|
104
|
+
- The link command takes the objects before the libraries (`--as-needed` drops
|
|
105
|
+
a library named first) and none of the preprocessor options; a separated
|
|
106
|
+
`-I <dir>` is two tokens and is dropped as a pair.
|
|
107
|
+
- `make -n` still runs recipe lines that use `$(MAKE)` or start with `+`.
|
|
108
|
+
- Re-read the commands (`make -n -B`) from each tree, so a changed Makefile or
|
|
109
|
+
flag is picked up.
|
|
110
|
+
|
|
111
|
+
Check that its binaries' outputs are byte-identical to the real build's on a
|
|
112
|
+
few cases before anyone uses it, and again after any change to the build
|
|
113
|
+
files. It is for subagents' scratch builds only: the runner and the unit-test
|
|
114
|
+
gate keep the repository's own build, which is what its users run.
|