Skip to content

fix(tune): give every suite arm one project path and seed each run - #162

Merged
krcm0209 merged 2 commits into
mainfrom
fix/tune-suite-confound
Oct 7, 2026
Merged

krcm0209 merged 2 commits into
mainfrom
fix/tune-suite-confound

Conversation

@krcm0209

@krcm0209 krcm0209 commented Oct 6, 2026

Copy link
Copy Markdown
Owner

Fixes #149. sous tune's suite comparisons were confounded twice:

  • Each arm saw its own prompt. The system prompt names the project root (Project root: …), and each run's root was suite/<arm label>/<task>-<i>/project. Two arms running the same task never sent the same prompt, and two runs of one arm differed only by the run index in that path.
  • A run's sampling was a fixed function of its prompt. mlx keeps its PRNG state per thread and starts every new thread on one default key, whatever any other thread seeded. Every suite run opens a fresh session thread, so every run sampled the same stream.

Change

  • One project path. Every arm and run works on its copy at one path, <run-id>/project. When the run ends, the copy moves to the same archive as before, suite/<arm>/<task>-<i>/project, beside its transcript.
    • It is run_suite's default (project beside the scratch directory), so a caller that leaves work out gets the neutral path rather than the confounded one.
  • A seed per run. ManagedEngine.session(seed=None) passes an optional seed to GenerationSession. The session applies it on its own thread, under the generation lock, right before its first generation; after that the stream advances from turn to turn as before.
    • The suite seeds run i with i. A task's runs therefore differ on purpose and reproducibly, and run i of every arm starts from the same stream.
  • The daemon is unchanged. The endpoint passes no seed.
  • Greedy arms. A greedy arm (temperature = 0) draws nothing, so its runs of a task now repeat one trajectory. docs/tuning.md says so. Before this change those runs varied only through the path.

Testing

  • New tests:
    • With real mlx on the CPU, on the session thread: the same seed gives the same draws, different seeds give different draws, and no seed replays the default stream. The stream also advances between generations.
    • run_loop opens its session with the run's seed.
    • Two arms × two runs send one identical system prompt, naming <run>/project. The seeds go 0, 1, 0, 1, every run grades 1.0 on a written solution, a stale project left at the work path is replaced, and each run is archived where it was before.
    • A run that raises midway still archives what it wrote.
  • Mutations:
    • Each new test failed before the fix.
    • Moving the grade after the archive move fails two runner tests.
  • CI set: uv run pytest -m "not model" 2268 passed. ty, ruff check, ruff format --check and uv lock --check are clean.
  • By hand, with the 0.6B model scripts/api_smoke.py uses, sampled at 0.7:
    • two unseeded sessions gave byte-identical replies (the bug);
    • seed 1 reproduced its replies;
    • seed 2 gave different ones.
  • Review: a three-lens review (correctness, confound, tests) found no correctness issues. Its four findings are fixed in the second commit.

Follow-up

#123's int8 ruling came from a suite run whose two arms had different paths. Re-measuring it under this fix needs the M5 Pro and is a separate step.

🤖 Generated with Claude Code

krcm0209 and others added 2 commits October 6, 2026 16:52
Suite comparisons were confounded twice (#149). The system prompt names
the project root, and each run's root was built from the arm's label and
the run index, so two arms never saw the same prompt. And mlx keeps its
PRNG per thread, starting every new thread on one default key, so each
run's fresh session thread sampled the same stream: a run was a fixed
function of its prompt, and repeated runs varied only through the path.

Every run's project now works at one path, <run-id>/project, and is
archived under suite/ beside its transcript afterwards. GenerationSession
takes an optional seed, applied on its own thread before the first
generation, and the suite seeds run i with i, so a task's runs differ on
purpose and run i of every arm draws from the same stream. The endpoint
passes no seed; the daemon is unchanged.

Co-Authored-By: Claude <noreply@anthropic.com>
run_suite's work path defaulted to the run's own archive directory, which
put the arm's label and the run index back into the prompt for any caller
that left it out. It now defaults to `project` beside the scratch
directory, so leaving it out can no longer bring the confound back, and
sous tune relies on that default.

The shared-root test now writes a solution and checks every run's grade,
so grading the project after it moved away fails it; a run that raises
midway is checked to archive what it wrote. The docs say that a greedy
arm's runs repeat one trajectory: it draws nothing for a seed to change.

Co-Authored-By: Claude <noreply@anthropic.com>
@krcm0209
krcm0209 merged commit c2ace92 into main Oct 7, 2026
9 checks passed
@krcm0209
krcm0209 deleted the fix/tune-suite-confound branch October 7, 2026 00:38
This was referenced Oct 7, 2026
krcm0209 added a commit that referenced this pull request Oct 7, 2026
Closes #123. #123 had kept int8 prefill off because the tool-loop
suite's grade fell from 1.000 to 0.883 with it. That comparison gave its
two arms different prompts (#149). Re-measured with the fixed suite
(#162), int8's grade stays within the tune's 0.05 margin of stock's, and
the maintainer chose to ship it on
([results](#123 (comment))).

## The re-measure

- **Setup:** M5 Pro, main at c2ace92, sous's defaults against the same
with `int8_prefill = true`.
- **Runs:** 8 tasks × seeds 0–7, so 64 runs per arm. The runs are
paired, so both arms of a pair get one prompt and one seed.
- **Result:** mean grade 0.943 for stock and 0.955 for int8. The
difference is **+0.013, 95% CI −0.020 to +0.054**.
  - Both arms completed 64 of 64 runs, with no repetitions.
  - Of the 64 pairs, 3 are lower with int8, 3 are higher and 58 tie.
- **The rule:** pre-registered, and it said recommend default-on.
- **Limit:** the suite's prompts are short, and long subagent turns were
not graded.
- **The gain:** about 7–8% of a lone subagent's wall clock on the M5
Pro. That is #77's per-prefill measurement priced over #130's workload
model.

## Change

- **`[model].int8_prefill` defaults to `true`.** A non-boolean value
still means `false`, the stock path, and warns.
- **Refusals split the way the attention tile's do**
(`int8prefill._refuse(expected=...)`):
- **INFO line** where int8 does not apply to the load. That covers the
platform rule (no tensor units, macOS < 26.2), a model type other than
dense `qwen3_5` (the MoE variant and mlx-lm models included) and a
checkpoint with no routable affine Q4 gs64 projection. This is how most
loads of a default-on setting go.
- **Warning** only where int8 should have run and did not: the GEMM
probe or the warm-up failing.
- Everything that says int8 doesn't apply runs **before** the probe, so
a model int8 could never route neither compiles the kernel nor warns
when a new macOS rejects it.
- **Docs:** `docs/configuration.md` (the sample config and the int8
paragraph, now citing the re-measure and its limit), `docs/tuning.md`
(the winner stage measures int8 only for a winner that has it off),
`CLAUDE.md`, and the README, whose prefill figures now say they predate
this change.
- **Tune tests:** the fixtures pin `int8_prefill=False`, so the winner
stage's int8 arm, which is built only for a winner that has it off,
stays tested.

**Side effects:**
- The fork key records int8 (`int8=active:N`), so stored forks miss once
after upgrading.
- A config that sets `int8_prefill = false` explicitly, such as one
copied from the old sample, stays off.

## Testing

- `uv run pytest -m "not model"`: 2271 passed. `ty`, `ruff check`, `ruff
format --check` and `uv lock --check` are clean.
- **New tests:**
  - the default and an explicit `false`;
  - a Mac without tensor units logs INFO and warns nothing;
  - a GEMM probe failure on an M5 still warns;
  - MoE and no-eligible-projection refusals log INFO;
  - a model int8 can't route is refused before the probe runs.
- **`scripts/api_smoke.py` on an M2 (macOS 15.5):** passes. The load
logs `INFO sous.engine.int8prefill: int8 prefill unavailable: macOS 15.5
< 26.2` and no warning.
- **A default-config load on the M5 Pro (macOS 27.0) at this branch:**
`int8: active, routed 336`, attention tile and projection kernel active,
no warnings.
- **Review:** a two-lens review (behaviour, docs and tests) found six
minor issues, all real. The second commit fixes them: the probe
ordering, two stale "one warning" comments, the README figures and one
CLAUDE.md sentence.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
krcm0209 added a commit that referenced this pull request Oct 7, 2026
Closes #87.

`sous tune`'s full run no longer adds a greedy winner-stage arm or
proposes `temperature = 0`. Greedy now runs only when the user sets
`temperature = 0` themselves.

**Why**
- **Greedy has no way out of a repetition loop.** In #145's merge gate,
greedy looped to the token cap on one real subagent turn in all 3 of its
runs on the attention tile. No sampled run looped.
- **The suite cannot see that risk.** On the fixed suite (#162) a greedy
arm draws nothing, so its runs of a task repeat one trajectory. That
leaves one sample per task.
- **The gain is small.** On real subagent turns greedy decoded at most
about 5% faster than sampled (#143, #145).

**What changes**
- `arms.winner_stage_arms` builds only the INT8 prefill arm. `decide`
never writes `temperature`.
- Every arm still inherits the user's temperature, and `Arm.greedy`
still keys suite rows. A user who set `temperature = 0` has every arm
run greedy, and the proposal leaves the setting alone.
- `docs/tuning.md` now describes one winner-stage arm, and both docs say
the tune never proposes greedy.

**Tests**
- The arms tests assert that no winner gets a greedy arm, and that a
winner the user set greedy keeps greedy on its int8 arm.
- A full-run test, parametrized over 0.7 and 0, asserts that no graded
arm changes the sampler and that the diff never mentions `temperature`.
- `uv run pytest -m "not model"`: 2274 passed. ty, ruff and `uv lock
--check` are clean.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude <noreply@anthropic.com>
krcm0209 added a commit that referenced this pull request Oct 15, 2026
## What

`SPECULATIVE_BLOCK_KERNEL` and `SPECULATIVE_BLOCK_MAX` move from 5 to 8
(`src/sous/config.py`): an unset `[model].speculative_block_size`
resolves to 8 where the projection kernel serves the load (the M5 Pro),
and an explicit block up to 8 loads unclamped. The tile-only block stays
4 and the default 3. Tests and docs follow (the projection kernel's
model test asserts the resolved block; the curated-set test uses 0, the
one configurable block outside the set; `docs/configuration.md`,
`docs/tuning.md`, `docs/observability.md`, CLAUDE.md, README figures).
Nothing here changes what a token id produces: the tile, the kernel and
the int8 K/V mirror already compile and prove T = 1..8.

## Why

A deeper verify block costs its attention, which steps with the
attention tile's 16-row groups: six rows × GQA 6 fill three groups and
waste twelve, so block 6 measured 1.019x block 5 with the kernel and the
mirror on and closed (#184). Eight rows fill the groups, the DFlash2
drafter is trained at block 8 (its config's `block_size`) and accepts
0.85–0.88 of positions 5–7 against 0.80 of positions 1–4, and the
projection kernel's 8-row tile costs the same at 8 rows as at 5.

Measured on the M5 Pro (main 8cb274b, block 8 explicit through an
out-of-tree shim — the same engine this branch resolves to from an unset
block, which its load line confirms), pre-registered before any run and
reviewed by three independent reviewers first:

| | 8 / 5 |
|---|---|
| **Decision: pure-arm ABBA, whole-turn decode tok/s** (runs 8, 5, 5, 8
over 145 real subagent turns at 44–88K, 290 turn pairs, turn bootstrap)
| **1.087 [1.053, 1.126]** |
| halves | 1.078 [1.031, 1.132] / 1.097 [1.054, 1.148] |
| 32–64K / 64–128K | 1.107 [1.063, 1.156] / 1.056 [1.018, 1.112] |
| prefill / time to first token (tripwires ≤ 1.03) | 1.001 / 1.000 |
| screen: arms 5k/8k drawn per round, two seeds, 127 distinct turns |
1.171 [1.129, 1.228] (crossover-adjusted 1.124 [1.074, 1.186]) |
| tokens/round, ms/round (per round) | 3.29 → 4.27, 107.8 → 119.5 ms |

The screen's per-round design flatters the deeper arm (a deep round's
deferred work lands in the rounds after it, and it consumes the next
round's easy acceptance: −0.18 tokens), which is why the pure-arm ABBA
decides at #157's bar (≥ 1.02 with the lower bound above 1.00) and the
screen only closes. Peak memory 40.5 GB against 40.2 at block 5.

## Gate (pre-registered; harness out of tree)

Draft until every step passes; the maintainer merges.

1. **CI's four jobs**: done locally at 7ba4930 (2487 passed, 95 skipped;
ty, ruff check, ruff format, `uv lock --check` clean).
2. **Decision**: the pure-arm ABBA above (PASS).
3. **Greedy parity at block 8**: 68 turns (131K–229K included),
max_tokens 256, drafter on (block unset → 8) against drafter off: every
token stream identical, a difference exempt only as the documented
argmax residual (equal top-2 logprobs in the drafter-off trace at the
first differing token); the same rule for block 8 against the kv8 gate's
block-5 drafter-on traces, since exact verification makes greedy output
independent of the block.
4. **Suite** (#123's paired design, as the kv8 gate ran it): eight tasks
× seeds 0..7, arms b5/b8 explicit, each arm proving its block by its
verify-row counters; ELIGIBLE iff the paired bootstrap's 2.5th
percentile ≥ −0.05, completed(b8) ≥ completed(b5) − 8 and
repetitions(b8) ≤ repetitions(b5).
5. **Model tests on the M5 Pro** at the branch head:
`tests/test_projkernel_model.py` (asserts the unset block resolves to 8
and greedy parity at 8, 12 and 0).

README figures: the 57K decode figure moves by the 32–64K pair ratio
(26.5 × 1.107 → about 29.5 tok/s); the Splash comparison keeps its
measured 1.54x at block 5 and says what block 8 narrows it to, pending a
side-by-side re-measure. `sous tune` gains block 6, 7 and 8 arms per
drafted pair (`BLOCK_SIZES` runs to the clamp), so the quick run grows
by three drafter arms per pair; on an M2 those are the slowest of the
run. The fork store cold-starts once on deploy (the engine epoch hashes
`vlm.py`, whose comment changed).

## Gate results (2026-10-14, M5 Pro, branch tree at 7ba4930; every GPU
job "daemon stayed idle")

| step | result |
|---|---|
| 3. greedy parity at block 8, drafter on vs off (68 turns, 131K–229K
included) | **PASS**: 68/68 identical token streams, cache histories
equal 68/68, no tie exemptions needed |
| 3. cross-block: block 8 drafter-on vs the kv8 gate's block-5
drafter-on traces | **PASS**: identical on every turn (exact
verification is block-independent, as it must be) |
| 5. `tests/test_projkernel_model.py` on the branch (resolves to 8;
parity at 8, 12, 0) | **PASS** (1 passed, 262 s) |
| 4. suite, b8 − b5 over 64 pairs (#123's rule) | **TO THE MAINTAINER**:
−0.019, 95 % CI [−0.053, +0.000]; the lower bound misses the −0.05 bar
by 0.003 |

The suite in detail: 62 of 64 pairs scored equal; two scored lower at
b8, one `dataclass_from_schema` run at 0.0 against 1.0 (the task known
to flip between whole and zero on its self-fix, #123/#162) and one
`tests_for_slugify` at 0.8 against 1.0; none scored higher; completion
64/64 on both arms, repetitions 0 on both; b8 finished the suite in
1,034 s against 1,271 s for b5 (1.23x, on conversations below the kv8
floor). Exact speculative sampling preserves the target's token
distribution whatever the block, and the parity runs above show the
greedy path bit-identical, so the two differing pairs are different
sampling paths of a bimodal task rather than a block effect; the
pre-registered rule still sends this to the maintainer, and the PR stays
a draft until the maintainer rules. **Information cell, 64 more pairs
(seeds 8–15, same design, run after the verdict and reported beside it,
not pooled into it):** b8 − b5 = +0.034, 95 % CI [−0.012, +0.089]
(ELIGIBLE on its own); 54 pairs equal, 6 higher at b8, 4 lower;
`dataclass_from_schema` flipped the other way this time (0.469 → 0.750,
three runs whole at b8 that were zero at b5); completion 64/64 both,
repetitions 0; wall 1,117 s against 1,251 s. All 128 pairs together:
+0.008 [−0.022, +0.038]. The gate's verdict is still the pre-registered
64's: the maintainer rules.

**Ruling (maintainer, 2026-10-14): suite accepted.** Every gate step is
therefore met; marked ready for merge.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tune: suite arm comparisons are confounded by per-arm prompt paths and per-thread deterministic sampling

1 participant