tomography / seq /protocol_seq.py
davidafrica's picture
add seq/ config: directions found by a diversity-maximising search above the census floor
9cb1c66 verified
Raw History Blame Contribute Delete
8.24 kB
"""Frozen constants for the diversity-maximising sequential search — see
../PROTOCOL-SEQ.md. Pinned before any GPU job ran.
Everything the frozen census pinned (slices, SEQ, flow constants, colored
floor, lift measurement, clustering/identity threshold) is imported unchanged
from `protocol.py` / `sprotocol.py`. This module adds only:
1. the grid (2 models x 3 representative blocks x 4 measures, + floors),
2. the sequential orthogonalised search's own knobs (restarts, K rule,
per-slot seeds, selection rule),
3. the end-to-end impact measurement (Q3),
4. the labelling cap (Q2),
5. the pre-registered verdict thresholds (Q1).
Nothing here is chosen at runtime.
"""
import protocol as P
import sprotocol as S
# ==========================================================================
# provenance
CENSUS_RAW_EID = S.CENSUS_RAW_EID # exp-1: raw GPT-2 census
CENSUS_WGPT2_EID = S.CENSUS_WGPT2_EID # exp-6: whitened GPT-2 census
CENSUS_WNEW_EID = S.CENSUS_WNEW_EID # exp-7: qwen adapters + packs
SPARSE_EID = "exp_01m14v596yfz9vwrrevxgexsme" # exp-9: corpus conditions
INTERP_EID = S.INTERP_EID # exp-8: label/validate pipeline
IMPACT_EID = "exp_01m0rjj4e8fdraqcf9vtcs2hnv" # exp-2: off-context KL precedent
# ==========================================================================
# 1. the grid
MODELS = ("gpt2", "qwen3-0.6b")
CONDITIONS = ("pile", "code", "math", "chat")
# The census's own representative blocks (round L/6, L/2, round 5L/6) —
# a subset of every completed census's blocks and of exp-9's condition blocks.
BLOCKS = {"gpt2": (2, 6, 10), "qwen3-0.6b": (5, 14, 23)}
FLOOR_OF = dict(S.FLOOR_OF)
TAGS = ("gpt2", "gpt2-randinit", "qwen3-0.6b", "qwen3-0.6b-randinit")
BASE_OF = dict(S.BASE_OF)
FRAMES = ("raw", "whit")
# ==========================================================================
# 2. the search
#
# Per slot: R_RESTARTS natural-token inits (census convention v0 = h - mu),
# projected off the accepted set in the working frame, each ascending the
# FROZEN amp objective (fastflow.lift_flow_batched mechanics: 200 steps,
# batch 1024, per-batch top-10% on-set, Adam lr 0.05, clamp 6, batch-stream
# seed 3) with a hard orthogonality constraint re-applied after every
# optimizer step. Best-of-restarts by FIT-slice gate lift at the frozen
# quantile; the winner occupies the slot and every later slot is searched in
# its orthogonal complement.
#
# Frames: raw — conditioning bra = the direction itself, orthogonality in
# raw coordinates; whit — conditioning bra = Sigma_s^{-1} v (the census's
# whitened-bra sensitivity arm), orthogonality in whitened coordinates
# (u = Sigma_s^{-1/2} v). Measurement is arm-matched, frozen: held-out gate
# lift at LIFT_Q vs the block's own colored floor (mean + 3 SD, N=50,
# seed 0) measured in the same arm.
R_RESTARTS = 8
K_MULT = 8 # K_max = 8x the censused count per (cell, frame)
K_CAP = 64 # capped at 64 directions
K_MIN = 8 # floor so zero-count cells still get a curve
SEQ_STEPS = P.FLOW_STEPS # 200, frozen
SEQ_BATCH = P.FLOW_BATCH # 1024, frozen
SEQ_Q = P.FLOW_Q # 0.1, frozen
SEQ_LR = P.FLOW_LR # 0.05, frozen
SEQ_CLAMP = P.FLOW_CLAMP # 6.0, frozen
SEQ_FLOW_SEED = P.FLOW_SEED # 3: every slot sees the census flow's batch stream
SELECT_Q = P.LIFT_Q # best-of-restarts on FIT gate lift, frozen quantile
ORTHO_TOL = 1e-3 # acceptance guard: max |cos| to the accepted set
def k_max(n_census):
"""The pre-registered K rule. Floor tags use the TRAINED model's count."""
return min(K_CAP, max(K_MIN, K_MULT * int(n_census)))
def slot_seed(slot, frame):
"""Deterministic per-slot init seed (recorded in every record)."""
return P.INIT_SEED * 100_000 + slot * 100 + (0 if frame == "raw" else 1)
# ==========================================================================
# 3. end-to-end impact per unit norm (Q3)
#
# Injection at the census steering site (resid_mid: qwen — attention output;
# gpt2 — attn output, so resid_mid = x + attn + delta feeds both the MLP
# branch and the ongoing residual). Every direction and every control is
# injected at the SAME norm alpha_cell = IMPACT_ALPHA_MULT x the median over
# the cell's sequential candidates of the top-q fit projection mean
# (q = LIFT_Q) — a per-cell constant, so "impact per unit norm" comparisons
# are rank-identical to impact at alpha_cell. Measured on a fixed batch of
# held-out sequences against the un-injected baseline:
# * next-token KL(base || injected), mean over positions >= 1;
# * downstream activation change at the LAST block's MLP-input site:
# rms ||delta h|| / rms ||h_base||.
# Both signs of every direction are measured. Controls: the block's 50
# frozen colored directions and IMPACT_N_RANDOM random unit directions.
IMPACT_N_SEQS = 64
IMPACT_SEQ_SEED = 0
IMPACT_N_RANDOM = 16
IMPACT_RANDOM_SEED = 123
IMPACT_ALPHA_MULT = P.STEER_ALPHA_MULT # 2.0, the census steering scale
IMPACT_SUBBATCH = 16
# The cached baseline log-probs are the KL's reference distribution, so the
# cache dtype sets the instrument's numerical noise floor: an fp16 cache put
# it at 2.3e-6 nats (measured, smoke job 306006891842). fp32 costs ~5 GB on
# the largest cell (64 seqs x 127 positions x 151936 vocab) and removes the
# rounding term.
IMPACT_CACHE_DTYPE = "float32"
TOPK_OVERLAP = 10 # fixed-k overlap; also reported at k = n_census
# ==========================================================================
# 4. novelty and labelling (Q2)
#
# A recovered above-floor direction is NEW iff its best |cos| against the
# model's entire known set — the Pile library (raw + whitened censuses, all
# blocks) UNION exp-9's novel domain/tail axes — is below the line's identity
# threshold. Orthogonal above-floor directions cannot double-count one known
# axis at this bar (two orthogonal unit vectors cannot both have |cos| >= 0.9
# with the same axis).
NOVEL_COS = S.NOVEL_COS # 0.9
LABEL_CAP_AXES = 400 # Stage A/B cap; stratified by (model, condition,
# frame) proportionally, top held lift first
LABEL_CATEGORIES = S.LABEL_CATEGORIES
CATEGORY_DESC = S.CATEGORY_DESC
# ==========================================================================
# 5. pre-registered verdict thresholds (Q1) — rules in ../PROTOCOL-SEQ.md
UNDERCOUNT_MULT = 2.0 # N_seq > 2 x N_census (pooled, trained cells)
SMALL_MULT = 1.25 # N_seq <= 1.25 x N_census -> confirmed small ...
SATURATION_FRAC = 0.10 # ... AND last-quarter slots contribute <= 10%
FLOOR_EXCESS_FRAC = 0.5 # floor excess >= 50% of trained excess -> the
# search manufactures counts; undercount verdict
# unavailable (uninterpretable)
ALPHA = 0.05
WILCOXON_ALT = "greater"
BOOT_N = 10_000
BOOT_SEED = 42
# ==========================================================================
# 6. smoke gates (gpt2, Pile, block 6) — thresholds; rules in PROTOCOL-SEQ.md
SMOKE_MODEL = "gpt2"
SMOKE_COND = "pile"
SMOKE_BLOCK = 6
SMOKE_K_WHIT = 24 # truncated whit search in the smoke (budget)
S1_COS = 0.9 # raw census axis re-found ...
S1_WITHIN_SLOTS = 2 # ... within the first 2 accepted raw slots
S1_LIFT_LO, S1_LIFT_HI = 0.5, 2.0 # matched slot's held lift vs stored median
S2_FLOOR_RTOL = 0.15 # recomputed raw colored floor vs exp-1's stored
# S4's null is judged against the instrument's own recomputation noise (an
# unhooked forward re-scored against the cache) and against the weakest
# control signal it must resolve, not against an absolute nats bar chosen
# before that noise floor was known.
S4_NULL_MULT = 3.0 # zero-injection KL <= 3x the recompute noise ...
S4_NULL_ABS = 1e-7 # ... or below this, if recompute noise is ~0
S4_NULL_FRAC = 0.01 # ... and <= 1% of the colored-control median KL
# Per-cell floor drift (PROTOCOL-SEQ.md section 5): a cell whose recomputed
# colored floor differs from the stored census floor by more than this is
# flagged and excluded from the pooled verdicts.
FLOOR_DRIFT_RTOL = 0.15