Files
OBLITERATUS/docs/ADAPTIVE_CAPTURE.md
Joseph MaglyandClaude Opus 5.5 780c450e0b feat(analysis): adaptive coarse-to-fine capture study
Add optimization study O03: can a coarse layer pass followed by
targeted fine captures find the same targets as the full sweep at lower
end-to-end cost?

- Three arms over the same rows and target rule: the reference sweep
  (every candidate layer), a fixed layer grid, and adaptive capture
  (coarse grid plus random exploration, then fine captures ranked by
  neighbouring AUC, uncertainty, direction disagreement and gap
  position, plus coverage probes).
- Forwards are counted by a hook; inference savings are claimed only
  when every seed needs fewer complete forwards. Bytes and
  extraction/CV work are counted; host timings stay outside the report
  digest.
- Unobserved regions are listed with "no evidence either way", and each
  missed target names its region.
- The recommendation is "no improvement" unless the missed-target rate
  stays within the pre-declared tolerance over at least 3 seeds with
  lower counted cost, and adoption also needs measured end-to-end time
  below the reference in every seed. Confirmation-exposed rows are
  refused.
- `obliteratus experiments adaptive-capture` and a Python API.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-16 09:21:55 -05:00

104 lines
5.2 KiB
Markdown

# Adaptive capture study (O03)
The adaptive capture study asks whether a coarse-to-fine layer search finds the
same target layers as the exhaustive candidate-layer sweep at lower end-to-end
cost. Its default answer is "no improvement".
```bash
# next to an observation run: pack and model come from <run>/spec.json
obliteratus experiments adaptive-capture --run ./observations/<digest>
# or explicitly, with a candidate layer subset and a study config
obliteratus experiments adaptive-capture --pack ./my-pack --model org/model \
--layer 4 --layer 5 --layer 6 --layer 7 --config ./adaptive.json --out ./adaptive
```
```python
from obliteratus.analysis.adaptive_capture_study import run_adaptive_study
report = run_adaptive_study(model, {"layer.0": layer0, "layer.1": layer1, ...}, rows,
config={"seeds": 5, "max_missed_target_rate": 0.0})
```
`rows` are `{"batch", "positive", "group"}` with one unpadded row per batch. The
command uses the positive and control rows of the `fit` role (`--role` to
change; locked `test` rows are refused). It writes
`<run>/adaptive-capture/adaptive-capture.json` or `<out>/adaptive-capture.json`.
Row text is never written. `--no-timings` gives a byte-identical file for a
fixed configuration.
## Arms
All arms capture the same rows of the same model and apply one target rule:
a layer is a target when its out-of-fold AUC is at least `min_auc` (0.7) and
within `target_margin` (0.05) of the best observed layer. AUC comes from a
difference-of-means direction fitted inside group-disjoint, label-stratified
folds (`folds`, default 3).
| Arm | What it captures |
| --- | --- |
| `reference_sweep` | Every candidate layer on every row in one pass: the current exhaustive workflow. Its targets define recall. |
| `fixed_grid` | Every `grid_stride`-th layer (default 3) plus the last, on every row in one pass. |
| `adaptive` | Coarse stage: a group-disjoint, class-stratified sample (`coarse_fraction`, 0.3) at a coarse grid plus `explore_layers` random layers. Fine stage: the `fine_layers` unobserved layers ranked highest by neighbour upper bound (AUC + fold SD), neighbour direction misalignment and gap position; the best coarse layers and any coarse layer whose upper bound reaches the target floor; and `coverage_probes` random still-unobserved layers. |
By default (`fine_rows: "remaining"`) the fine stage runs only on rows the
coarse stage did not use, so no row is forwarded twice. `fine_rows: "all"`
runs the fine stage on every row: this is an extra pass.
Every seed (`seeds`, default 5) uses new folds, and the adaptive arm draws a new
coarse sample, exploration and probes. Selected-target stability is the mean
pairwise Jaccard index of an arm's targets across seeds.
## Accounting
Deterministic counters per arm and seed:
- complete forwards, counted by a hook on the model rather than inferred;
- captured bytes moved to the host;
- extraction/CV work as `fit_rows` (rows per fit summed over every fit), plus
`layer_fits` and captured row-layers.
Capturing fewer layers does not skip the model's forward computation. The
study claims inference savings only when an arm needs fewer complete forwards
than the reference sweep. With equal forwards the report says the savings are
not claimed; with more (the extra coarse pass) it says that pass costs more.
Measured forward, transfer (device to host) and extraction/CV seconds, and
their end-to-end sum, go to `host_measurements`. They are excluded from
`report_sha256`. The reference and grid captures do not depend on the seed;
they are captured once and their timing is reused for every seed.
## Coverage
Each arm and seed lists its unobserved regions: contiguous layers it never
captured. They mean no evidence either way, not an empty or irrelevant region.
Layers captured on only a subset of rows are listed separately. Every missed
reference target is reported with its region: unobserved, observed on a subset
of rows, or observed but not selected. `coverage_flag` is set when an arm missed
a target or left any layer unobserved.
## Adoption rule
The tolerance `max_missed_target_rate` (default 0.0) is declared in the config
before the run. `recommendation` is deterministic and sealed. It reads
`counted savings; pending end-to-end runtime` only if all of these hold:
1. The study used at least `min_seeds_for_recommendation` seeds (default 3).
2. The reference sweep selected a target in every seed.
3. The adaptive arm's worst-seed missed-target rate is within the tolerance.
4. In every seed, the adaptive arm needs no more complete forwards than the
reference sweep, and captures fewer bytes and does less `fit_rows` work.
5. The fixed grid does not meet the tolerance at no more forwards, bytes and
`fit_rows` than the adaptive arm.
Otherwise it reads `no improvement`, with reasons.
`adoption` holds the final verdict. It is `improvement` only if the
recommendation holds and the measured end-to-end time of the adaptive arm is
below the reference sweep's in every seed. It is `no improvement` in every
other case, including runs without timings. Because it reads host timings,
`adoption` is excluded from `report_sha256`. The reference sweep remains
available for audit and fallback.
Results on synthetic fixtures, including this project's tests, are not
evidence for real models.