Files
OBLITERATUS/docs/ANALYSIS_REUSE.md
Joseph MaglyandClaude Opus 5.5 4c67cd3da9 feat(analysis): safe reuse of activation statistics, fits and nulls
Add an opt-in, in-memory reuse cache (O04) for work repeated across
analyses: per-layer and per-fold extraction fits, candidate-discovery
nulls and labeled row selections, plus incremental pooled moments.

- Artifacts are keyed by kind, algorithm version, site, partition/role,
  fold, normalization, tokenizer, model, adapter, weight fingerprint,
  dataset revision, parameters and a data digest. Missing or unknown
  fields never match.
- A statistic fitted on all rows, another fold or held-out rows is never
  served inside a train or held-out fold (contamination refused); other
  mismatches are refused with per-field reasons.
- Exact results only; incremental moments carry a declared error budget
  and a distinct algorithm name. Reports cover hits, misses, avoided work
  and setup cost amortized over hits.
- extract_directions and discover_candidates take reuse=; outputs are
  bit-identical to fresh computation and defaults are unchanged.

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

4.0 KiB

Safe reuse of analysis work

Repeated recipe, layer and rank comparisons often recompute the same layer fits, decompositions and null samples. The reuse cache serves such results again only when every input that can change their value or meaning is identical. Reuse is opt-in. Without it, every analysis runs exactly as before.

Identity

Each cached artifact carries a ReuseIdentity with these fields:

Field Meaning
kind, algorithm Artifact type and versioned algorithm (includes the package version)
site Readout and phase plus layer or site
partition Dataset roles, sets or contrast the rows come from
fold all, train:k/F, heldout:k/F or a declared within-partition scope
normalization Pooling, denoising, dtype or scaling applied before fitting
tokenizer, model, adapter, weights Taken separately from the capture identity, including the weight fingerprint
dataset_revision Content and partition revision of the dataset
parameters Digest of algorithm options and seeds
data Content digest of the input tensors, or a lineage digest of verified rows

A missing or unknown value never matches, so the result is computed fresh and not stored. ReuseScope.from_capture_identity and ReuseScope.from_labeled fill the model, tokenizer, adapter, weight and revision fields. If only the labeled set's combined capture digest is known, all four model-side fields are bound to that digest.

Refusal rules

  • A cache hit requires an exact match on every field. A miss is compared with stored entries of the same kind and site, and the differing fields are recorded. In that case the cache reports refused rather than miss.
  • Fold contamination: a statistic fitted on all rows, on another fold's training rows or on held-out rows is never used for a train: or heldout: request. admit raises ReuseContamination for this case and ReuseRefused for any other mismatch.
  • Consumers that read a labeled set refuse a scope bound to a different capture or dataset revision.
  • Raw activation rows follow the same fold rule. This is stricter than necessary, but simple to audit.

Accounting

ReuseCache.report() returns lookups, hits, misses, refusals, unreusable lookups, evictions and the event log. Each hit event lists the fields that matched and the fold equality. The report also gives avoided work: estimated operations declared by the consumer, input bytes not re-read, and the recorded compute seconds of the original computation. Setup cost is reported next to it: cold computation, identity hashing and copies. Amortization divides setup by uses. Setup cost is spread over later hits; it is not removed. All cached results are exact. No approximate sketch is stored.

Incremental statistics

PooledMoments keeps count, sum and centered scatter in float64. It merges appended blocks with the pairwise update, so earlier rows are not revisited. A merged result is within a declared absolute error budget (8 · count · eps · max|x|, squared and multiplied by count for scatter) of a one-pass recomputation. It carries a distinct algorithm name, so it is never served as an exact result. A merge is refused when identities or fold scopes differ, when the same block is appended twice, or when tracked row keys overlap.

Integrations

  • extract_directions(..., reuse=scope) reuses whole-set and per-fold layer fits. Fold fits are keyed by the fold's held-out indices. Changing only the intervention rule or the preset reuses every fit, and the resulting direction is bit-identical.
  • discover_candidates(..., reuse=scope) reuses the shuffled-label and random-direction nulls of each contrast. These depend only on the discovery rows, labels, groups, basis, seed and null options. Changing reporting options such as top_n or n_bootstrap leaves the report bit-identical.
  • labeled_matrix reuses float64 row selections of a verified labeled set.

The cache lives only for the current process and is never written to disk. Use max_bytes to limit how much it holds.