feat(r12): sweep wrapper for KV-cache compression PPL headroom diagnostic (A'') - #34
Merged
Merged
Conversation
…stic (A'')
Implements R12 v1.1 first-execution sweep wrapper per §8: orchestrates a
b_mse ∈ {6,5,4,3,2,1} sweep against the R7-B v1.2 autoregressive harness
with β1a (make_b_mse_hook_uniform) hook on MPS. Per-point JSONs conform
to ppl_headroom_kv_cache_point/1.0; aggregate manifest conforms to
ppl_headroom_kv_cache_sweep/1.0 (R12 v1.1 §6.1, §6.2).
Features:
- Model loaded once at sweep entry; reused across all sweep points (Q2)
- Per-point JSON written immediately for partial-progress preservation
- Termination conditions per R12 v1.1 §6.2:
* ceiling_crossed (ppl > baseline × ceiling_multiplier): halt
(continue_past_ceiling=false canonical per §8)
* hook_construction_failure: halt (environmental, not parameter-specific)
* ppl_eval_failure: continue (less-aggressive b_mse may succeed)
* grid_exhausted: clean completion
- --smoke mode for reduced verification runs (b_mse=[4,2], N=2, L=128)
- Recommended operating point: most-aggressive b_mse (lowest int) meeting
the R7-B v1.2 §1.1 N-indexed calibration gate
Q6 disposition — kv_cache_compression_ratio:
β1a is a round-trip hook (K/V shape/dtype preserved for PPL measurement
correctness), so the schema's pre/post-bytes mechanism is vacuous.
Emits theoretical 16/b_mse instead (deployment-relevant codebook ratio).
Per-point notes field documents the derivation + flags R12 v1.2
amendment carry-forward for clarifying §6.1 field semantics.
Schema version conventions:
- spec_version: kv_cache_compression_ppl_headroom_diagnostic v1.1
- methodology_consumed: wikitext2_ppl_methodology_autoregressive v1.2
- schema_version: ppl_headroom_kv_cache_{point,sweep}/1.0 (unchanged)
Dependencies: imports tern_ppl_bench functions
(build_sequences_autoregressive, evaluate_ppl_autoregressive,
build_kv_cache_hook, classify_ppl_headroom_band, utc_now_compact,
git_commit_short) via sibling sys.path. No tern_ppl_bench
modifications required — all needed functions already top-level.
Phase E smoke verification (2 runs, smoke mode):
- Smoke 1 (default ceiling=2.0): single-point ceiling-crossed at b_mse=4
(PPL=9551 expected high for N=2 L=128 aggressive compression);
termination halt + null recommended_operating_point both correctly
schema-conformant
- Smoke 2 (permissive ceiling=100000): multi-point completion;
b_mse=4 finite, b_mse=2 ppl_eval_failure (NaN); continue-on-failure
correctly populated point 1 JSON with null PPL fields + theoretical
compression ratio retained + failure rationale in notes
Full sweep at canonical R7-B parameters (N=16, L=2048,
b_mse=[6,5,4,3,2,1], MPS, β1a) launched as nohup background process
post-PR-creation. Results land in results/ppl_headroom_kv_cache_sweep/
for next-session inspection.
Cross-references:
- R12 v1.1 §6 (per-point + sweep schemas), §8 (canonical sweep params)
- R7-B v1.2 §1.1 N-indexed calibration gate (PR #33)
- β1a factory make_b_mse_hook_uniform (PR #27)
- Cache-shape DynamicCache contract (PR #32)
- MPS Codebook fix (gamma-seeds/turboquant fork; OnlyTerp PR #5)
Copyright (c) 2025-2026 Gamma Seeds Pte Ltd. All rights reserved.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Merged
6 tasks
Companion to docs(r12) PR #35 (R12 v1.2 §6.1 kv_cache_compression_ratio semantics clarification + doc-consistency sweep). The implementation already emitted theoretical compression ratios per v1.2 semantics; this bump aligns the spec_version field with the canonical doc version. Per-point JSONs and aggregate manifests from sweeps launched after this commit will emit spec_version 'kv_cache_compression_ppl_headroom_diagnostic v1.2'. The currently-running unattended sweep (PID 8767, launched 2026-05-17 under v1.1) continues emitting v1.1 — methodologically correct for sweeps started before the amendment landed. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
synapticode-ai
marked this pull request as ready for review
May 17, 2026 07:46
synapticode-ai
pushed a commit
that referenced
this pull request
May 21, 2026
Brings R12 current with main carrying: - f0b7fc4 ci: install integration3 v1.0.2 in CI; remove sys.path injection - 8547f7b ci: bump integration3 pin v1.0.2 → v1.0.3 - e53f011 test(integration3): F-1→F-12 falsifier coverage + cross-repo TW arm - 36bfd2a / 9e6f12b / 11f183d / 76550b7 Kokoro 82M adapter + Provider³ + Phase 0 docs Pre-merge assessment (read-only): - R12 working tree clean (only untracked results/ benchmark sweep outputs) - merge-tree HEAD origin/main: clean (no conflicts) - R12 tree has zero integration3 references in src/, tests/, tools/, benchmarks/ - R12 has zero tests that relied on the old hardcoded integration3 sys.path injection (that injection was introduced and removed entirely on the integration3-kokoro PR lineage; R12 never inherited it) - Inherited tests/conftest.py worktree-src precedence is benign for R12 (R12's editable install already points at this worktree's src/) - Inherited CI step needs INTEGRATION3_READONLY_TOKEN; repo-level secret is branch-agnostic Branch convention: feat/r12-* uses merge commits (PR #34, #36 precedents) — preserved here with --no-ff. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
R12 v1.1 first-execution sweep wrapper (A''): orchestrates a
b_mse ∈ {6,5,4,3,2,1}sweep against the R7-B v1.2 autoregressive harness with the β1a (make_b_mse_hook_uniform) KV-cache compression hook on MPS. Produces per-point JSONs conformant toppl_headroom_kv_cache_point/1.0and an aggregate manifest conformant toppl_headroom_kv_cache_sweep/1.0per R12 v1.1 §6.Why
All upstream dependencies landed this week (B baseline, Cache-shape contract PR #32, R7-B v1.2 calibration gate PR #33, MPS Codebook fix in
gamma-seeds/turboquantfork). The sweep wrapper is the last piece needed to characterise TurboQuant's PPL-vs-compression frontier under R7-B-conformant methodology. The 12 May TQ benchb_mse=3anchor (PPL 7.82→8.14) was non-R7-B-conformant per R7-B §1.2; this sweep re-establishes the anchor and characterises the full grid under the valid methodology.Changes
New file
tools/tern_r12_sweep.py(683 lines):SweepPointResult/SweepResultdataclassesrun_sweep_point— single-point execution with branched error capture (hook construction failure, ppl eval failure, non-finite PPL)build_point_json/build_sweep_manifest— §6.1 and §6.2 schema assemblydetect_termination— per-point termination classifierclassify_recommended_operating_point— frontier search for most-aggressive b_mse passing the R7-B v1.2 §1.1 N-indexed calibration gaterun_sweep— model-once / sequences-once orchestration loop with per-point JSON write for partial-progress preservationmain— full CLI surface including--smokemodeDispositions (ratified Phase B)
ppl_eval_failure, halt onhook_construction_failure, halt at firstceiling_crossedper §8 canonicalcontinue_past_ceiling=falsekv_cache_compression_ratio= theoretical 16/b_mse (β1a is round-trip — pre/post-bytes mechanism vacuous; theoretical ratio captures deployment-relevant compression). Per-pointnotesfield documents derivation + flags R12 v1.2 amendment carry-forwardPhase E smoke results
Smoke 1 (default ceiling=2.0×):
recommended_operating_pointcorrectly null-stubbed; both JSONs schema-conformantSmoke 2 (permissive ceiling=100000):
ppl_eval_failureat b_mse=2 (less-aggressive b_mse can still succeed per Q4 disposition)Both smokes verify the wrapper's full schema-conformance + termination-branch coverage. High PPL values are artefacts of the smoke's tiny context (N=2 L=128 with aggressive compression); not indicative of canonical-config behaviour.
Full sweep launched
After this PR opens, the canonical sweep launches as a
nohupbackground process:Expected wall-time: ~3-12 hours on M4 Pro MPS (β1a per §8.2.3 estimated ~26 hr on CPU; MPS speedup uncertain at L=2048). Results land in
results/ppl_headroom_kv_cache_sweep/for next-session inspection. PID + log path captured in landing report.Test plan
Cross-references
make_b_mse_hook_uniform(PR make_b_mse_hook_uniform: batched-uniform R12 factory (β1a) #27)gamma-seeds/turboquantfork; upstream PR OnlyTerp#5)🤖 Generated with Claude Code