tomography / interp /protocol.py
davidafrica's picture
tomography catalog v1
5d7c20f verified
Raw History Blame Contribute Delete
10.2 kB
"""Frozen interpretation protocol for the whitened + scale-up attractor
libraries — pinned before the smoke test.
This experiment runs the raw library's proven exemplar->label->validate
pipeline (exp_01m0spvn1eew0sje5yh97cjpxe, its src/protocol.py constants are
reproduced verbatim below) over every still-uninterpreted attractor pole:
- the whitened GPT-2 library (exp_01m0tedzxhejkrq70x0pvcsay1, 895 axes)
- the whitened Pythia/Qwen library (exp_01m0xrq2h1fdertpjmkd9x80cs, 2,168 axes)
- the raw-metric Pythia/Qwen attractors (exp_01m0sy4fjhefv9tv0nwz9cx1nd,
466 axes, never labeled)
3,529 axes / 7,058 poles over 12 trained models. Random-init floors are not
interpreted. Nothing downstream chooses a threshold at runtime.
"""
# ---- provenance -----------------------------------------------------------
CENSUS_EID = "exp_01m0rjapkveyqr5fytnhtwdzg8" # raw GPT-2 census (frame ref)
RAW_INTERP_EID = "exp_01m0spvn1eew0sje5yh97cjpxe" # raw interpretation (pipeline)
WGPT2_EID = "exp_01m0tedzxhejkrq70x0pvcsay1" # whitened GPT-2 census
WNEW_EID = "exp_01m0xrq2h1fdertpjmkd9x80cs" # whitened Pythia/Qwen census
RAWNEW_EID = "exp_01m0sy4fjhefv9tv0nwz9cx1nd" # raw scaling census
# ---- models (registry copied from the whitened scaling census) -------------
# family: "gpt2" (HF GPT2, ln_2-input hook == census hook_resid_mid),
# "neox" (parallel residual, block-input hook), "qwen3"/"qwen3_5" (SwiGLU,
# post_attention_layernorm-input hook). bos = prepended sink token.
ALL_MODELS = {
"gpt2": dict(hf="openai-community/gpt2", family="gpt2",
n_layers=12, d_model=768, d_mlp=3072, vocab=50257, bos=50256),
"gpt2-medium": dict(hf="openai-community/gpt2-medium", family="gpt2",
n_layers=24, d_model=1024, d_mlp=4096,
vocab=50257, bos=50256),
"gpt2-large": dict(hf="openai-community/gpt2-large", family="gpt2",
n_layers=36, d_model=1280, d_mlp=5120,
vocab=50257, bos=50256),
"gpt2-xl": dict(hf="openai-community/gpt2-xl", family="gpt2",
n_layers=48, d_model=1600, d_mlp=6400,
vocab=50257, bos=50256),
"pythia-160m": dict(hf="EleutherAI/pythia-160m", family="neox",
n_layers=12, d_model=768, d_mlp=3072,
vocab=50304, bos=0),
"pythia-410m": dict(hf="EleutherAI/pythia-410m", family="neox",
n_layers=24, d_model=1024, d_mlp=4096,
vocab=50304, bos=0),
"pythia-1.4b": dict(hf="EleutherAI/pythia-1.4b", family="neox",
n_layers=24, d_model=2048, d_mlp=8192,
vocab=50304, bos=0),
"pythia-2.8b": dict(hf="EleutherAI/pythia-2.8b", family="neox",
n_layers=32, d_model=2560, d_mlp=10240,
vocab=50304, bos=0),
"pythia-6.9b": dict(hf="EleutherAI/pythia-6.9b", family="neox",
n_layers=32, d_model=4096, d_mlp=16384,
vocab=50432, bos=0),
"qwen3-0.6b": dict(hf="Qwen/Qwen3-0.6B", family="qwen3",
n_layers=28, d_model=1024, d_mlp=3072,
vocab=151936, bos=151643),
"qwen3-8b": dict(hf="Qwen/Qwen3-8B", family="qwen3",
n_layers=36, d_model=4096, d_mlp=12288,
vocab=151936, bos=151643),
"qwen3.6-27b": dict(hf="Qwen/Qwen3.6-27B", family="qwen3_5",
n_layers=64, d_model=5120, d_mlp=17408,
vocab=248320, bos=248044, dtype="bfloat16"),
}
DEFAULT_DTYPE = "float32" # 27B loads bf16 (spec dtype); rest fp32
# Pinned tag order — axis_gid / pole_id assignment depends on it.
TAGS = ("gpt2", "gpt2-medium", "gpt2-large", "gpt2-xl",
"pythia-160m", "pythia-410m", "pythia-1.4b", "pythia-2.8b",
"pythia-6.9b", "qwen3-0.6b", "qwen3-8b", "qwen3.6-27b")
# Axis sources per tag: GPT-2 tags carry only whitened axes (their raw axes
# are the already-interpreted exp-4 library); new families carry whitened +
# raw. Within a tag axes are ordered (layer, metric_order, cluster_id) with
# metric_order whitened=0, raw=1. pole_id = 2*axis_gid + (0 pos | 1 neg).
METRICS_BY_FAMILY = {"gpt2": ("whitened",),
"neox": ("whitened", "raw"),
"qwen3": ("whitened", "raw"),
"qwen3_5": ("whitened", "raw")}
# ---- corpus (census conventions, unchanged) --------------------------------
SEQ = 127 # tokens per sequence, BOS prepended at capture
DATASET = "NeelNanda/pile-10k"
NEW_SLICE_START_ROW = 363 # first pile row untouched by fit/held slices
NEW_SLICE_TOKENS = 4_000_000 # per family, truncated to a multiple of SEQ
# gpt2-family regression: the exemplar slice must reproduce the raw
# interpretation run's slice exactly (its slice_meta sha).
GPT2_SLICE_SHA = "bcf5eee2" # prefix pin; full sha asserted from staged meta
CAPTURE_BATCH = {768: 64, 1024: 64, 1280: 32, 1600: 32, 2048: 32,
2560: 32, 4096: 16, 5120: 16} # harvest batch by width
# ---- exemplar extraction (raw interpretation protocol, verbatim) ------------
TOP_ANCHORS = 128 # anchors retained per pole (cap-respecting walk)
PER_SEQ_CAP = 2 # max anchors per 127-token sequence per pole
PER_DOC_CAP = 4 # max anchors per pile-10k document per pole
OUTLIER_SD = 4.0 # ||h|| > mean + 4 SD (new slice, per block) excluded
WINDOW_RADIUS = 10 # +-10 tokens, clamped to the sequence
N_LABEL_POOL = 60 # label-side anchors kept per pole (even rows only)
N_LABEL_PROMPT = 20 # exemplars per label prompt, pool-sampled (seeded)
N_DETECT = 10 # detection-true exemplars (odd rows only)
N_NEG = 12 # non-activating negatives extracted per pole
NEG_SEED = 43 # rejection-sampling seed (NEG_SEED + pole_id)
NEG_MAX_QUANTILE = 0.5 # negatives drawn where signed proj < slice median
NEG_PER_SEQ_CAP = 2
NEG_PER_DOC_CAP = 2
EXCL_TOP = 100 # pole positions a negative must stay away from
EXCL_RADIUS = 10
MIN_LABEL = 8 # below these the pole is flagged insufficient
MIN_DETECT = 6
# ---- per-model token profiles (native vocab; report display + sensitivity) --
PROFILE_MIN_OCC = 50 # ids with >= 50 occurrences on the new slice
# ---- family clustering: HELD-slice word profiles (cross-tokenizer) ----------
# Profiles are the stored word-type profiles of the scale-up protocol
# (rows 102-362 shared raw text, WordMap aggregation): exp-7 wpacks (whitened
# new families), exp-7 wwordprof packs (whitened GPT-2), exp-5 arrays (raw new
# families). Clustering uses the word types with >= WORD_MIN_OCC covered
# occurrences in ALL FOUR tokenizer families (gpt2, neox, qwen3, qwen3_5).
# All poles are clustered (signed profiles, pole = +-axis row); family naming
# and kind categorization use validated labels only.
WORD_MIN_OCC = 20
FAMILY_TAU = 0.70 # Spearman threshold (average linkage, cut 1 - tau)
FAMILY_TAU_SENS = (0.65, 0.75) # stability band (plan: +-0.05)
CROSS_MODEL_MIN = 3 # validated members from >= 3 of 12 models
# (analogue of the raw run's >=3-of-4 rule)
# ---- LLM stages (raw interpretation protocol, verbatim) ---------------------
LLM_MODEL = "anthropic/claude-sonnet-5" # re-verified against the live catalog
LLM_PROVIDER = "openrouter"
REASONING_EFFORT = "low"
LABEL_THREADS = 16
DETECT_THREADS = 16
DETECT_MAX_TOKENS = 2000
DETECT_RETRIES = 3
CONTROL_SEED = 42 # derangement of label -> pole assignments
# Control derangement is WITHIN MODEL (labels never cross tokenizers or
# content domains), never the same (model, layer) block — the within-GPT-2
# refinement of the raw run's block-forbidding derangement, needed because the
# pooled library now spans three tokenizer families.
ORDER_SEED = 42 # per-pole snippet shuffling (ORDER_SEED + pole_id)
VALIDATION_PCTL = 95 # BA must beat this percentile of control BAs
# Headline bar: pooled control q95 over all scored poles (raw-run convention).
# Reported sensitivities: adjacent quantized bar, per-model bars, per-library
# bars (whitened-gpt2 / whitened-new / raw-new).
# ---- kind categorization ----------------------------------------------------
# Every validated pole label and every multi-member family name is classified
# by the judge against the raw library's 15 mirrored sign-pair kinds (names +
# descriptions extracted verbatim from exp-4's family_names/derived_stats into
# data/raw_kinds.json at build time), plus a pinned coarse category set and an
# explicit NEW option. Labels are classified in batches.
KIND_BATCH = 20
KIND_COARSE = ("sentence_boundary", "function_word", "formulaic_continuation",
"word_fragment", "punctuation", "indentation_whitespace",
"noun_semantic", "other_new")
# ---- reference checks (per model, before anchors are trusted) ---------------
# Reference axis rule: among that model's whitened attractor-bearing blocks,
# the block closest to n_layers/2 (ties -> lower); axis = largest share
# (ties -> lowest cluster id). Recompute its held-slice profile in the
# rebuilt frame; top-20 token overlap vs the stored census profile and
# proj_top_mean relative error must pass.
REF_TOKEN_OVERLAP = 0.75
REF_TOP_MEAN_RELERR = 0.02
REF_TOP_STATES = 800 # census pole_top_tokens convention
REF_TOP_TOKENS = 20
# Smoke instrument reference: the raw census gpt2 L6 first attractor axis
# (exp-4's known-interpretable kind-noun reference), rerun end-to-end.
SMOKE_REF_BA = 0.70
SMOKE_BLOCKS = (6,) # gpt2 whitened block for the smoke
SMOKE_TOKENS = 1_524_000 # 12,000 sequences
# ---- constants referenced by the vendored families.py (unused paths) --------
RANDOM_INIT_SEED = 42 # random-init floors are NOT interpreted here
STEER_MAX_NEW = 40 # steering is out of scope; kept for import
STEER_TEMP = 0.9
STEER_TOP_P = 0.95
STEER_SEED = 42