mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-06 19:13:55 +01:00
Add F21: architecture adapters that record tensor semantics and staged support levels, MoE observation with explicit coverage, and transfer dossiers compared against within-model baselines. - Adapters record site meaning, block order, norm placement and module roles (attention, MLP, router, routed and shared experts) and check residual semantics on a real forward. Support is staged: observation, then reversible intervention, then persistent editing. Dense decoders support all three; sparse MoE decoders support observation and residual intervention and refuse persistent editing. - MoE observation reports per-expert routed tokens and rows with intervals; experts below the coverage floor are insufficient coverage with null effects, never no effect. Route and load changes, shared expert contributions and routing restoration are measured. - Transfer needs its own alignment-fit and test rows (refused on overlap), the same row budget for a direction fitted directly on the target, and must beat that baseline and random directions with bootstrap intervals. Tested and untested conditions are listed; experts listed as tested must be covered on the test rows; new modalities need their own targets and scoring tasks. - `obliteratus experiments transfer run` and `arch-profile`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
138 lines
7.0 KiB
Markdown
138 lines
7.0 KiB
Markdown
# Architecture adapters and transfer dossiers
|
|
|
|
Architecture adapters record what each tensor of a model family means, and
|
|
which capabilities are supported on it. Transfer dossiers evaluate a direction
|
|
from one model (source) on another model, family or domain (target) against
|
|
baselines fitted on the target itself.
|
|
|
|
```bash
|
|
obliteratus experiments arch-profile --model ./models/tiny-moe [--verify] \
|
|
[--require reversible_intervention --scope residual_stream]
|
|
obliteratus experiments transfer run ./transfer-spec.json --out ./dossiers
|
|
```
|
|
|
|
```python
|
|
from obliteratus.arch_adapters import bind, check_residual_semantics, residual_readout
|
|
from obliteratus.analysis.moe_observation import observe, observe_intervention
|
|
from obliteratus.analysis.transfer_dossier import build_transfer_dossier
|
|
|
|
bound = bind(model) # refuses unknown families and layouts
|
|
profile = bound.profile(check_residual_semantics(bound, input_ids))
|
|
report = observe_intervention(bound, batches, direction, layer=0)
|
|
dossier = build_transfer_dossier(spec, tensors)
|
|
```
|
|
|
|
## Adapters
|
|
|
|
| Adapter | Model types | Observation | Reversible intervention | Persistent editing |
|
|
| --- | --- | --- | --- | --- |
|
|
| `dense_decoder` | `gpt2`, `llama`, `mistral`, `qwen2`, `qwen3` | residual stream, attention, MLP | residual stream | residual stream (persistent candidates) |
|
|
| `sparse_moe_decoder` | `mixtral`, `olmoe`, `qwen2_moe`, `qwen3_moe` | residual stream, attention, MLP, router, routed experts, shared expert | residual stream only | refused (not implemented) |
|
|
|
|
Capabilities extend in order: observation, then reversible intervention, then
|
|
persistent editing. An adapter cannot declare a capability unless every earlier
|
|
one is supported. An unsupported capability or scope raises
|
|
`CapabilityRefused` with the reason; nothing falls back to another path. Model
|
|
types without an adapter are refused for every capability.
|
|
|
|
A profile (`obliteratus.architecture-profile`, version 1) records:
|
|
|
|
- the block structure (sequential pre-norm) and the norm module names;
|
|
- site semantics: `layer.<i>` is the decoder layer output, i.e. the residual
|
|
stream after block i and before the final norm;
|
|
- per layer, every role with its meaning: attention and MLP norms, attention,
|
|
MLP or sparse MoE block, router (logits, top-k weights and indices;
|
|
probabilities are `softmax(logits)`), routed experts, shared expert and its
|
|
sigmoid gate, expert count and top-k. Dense layers inside an MoE model are
|
|
marked `dense`;
|
|
- the support level of each capability and the module that implements it.
|
|
|
|
`--verify` (or `check_residual_semantics`) loads the weights and checks the
|
|
site meaning on a forward pass: `layer.i` must equal the model's hidden state
|
|
i + 1, and the final norm of the last site must equal its last hidden state.
|
|
|
|
The dense adapter resolves layers, attention and MLP modules through the same
|
|
helpers as the rest of the package, so it reads the same modules as existing
|
|
observation and intervention code. The MoE adapter is separate from Neuron Lab
|
|
and from the concept pipeline's MoE edits.
|
|
|
|
## MoE observation
|
|
|
|
`observe` and `observe_intervention` (`obliteratus.moe-observation`,
|
|
version 1) report per sparse layer:
|
|
|
|
- **Routed coverage per expert**: routed tokens, distinct rows, routed token
|
|
share with a Wilson interval. Padding is excluded.
|
|
- **Coverage floor** (default 8 tokens and 2 rows): an expert below it is
|
|
`insufficient_coverage`, `tested: false`, and every effect field is `null`.
|
|
It is never reported as zero or as no effect.
|
|
- **Expert-level effects** under an intervention, on the tokens the expert
|
|
processed at baseline: retention (share still routed to it, Wilson interval)
|
|
and mean change of its choice probability (normal interval). Both intervals
|
|
use the expert's own routed count, so they widen as coverage falls.
|
|
- **Route and load changes**: token-aligned KL between routing distributions,
|
|
share of tokens whose choices changed, expert load before and after, and
|
|
per-expert load deltas with intervals.
|
|
- **Shared-module contributions**: mean routed and shared output norms and
|
|
the shared share of the block output. The block output must equal the routed
|
|
plus gated shared output; the maximum error is recorded. Families without a
|
|
shared expert report `present: false`.
|
|
|
|
The intervention is a projection ablation at one residual site, applied by
|
|
a forward hook that is removed afterwards. A third pass must reproduce the
|
|
baseline routing exactly. Routers at or before the intervened block must not
|
|
change, since the hook cannot reach them.
|
|
|
|
## Transfer protocol
|
|
|
|
A spec (`obliteratus.transfer-spec`, version 1) names:
|
|
|
|
- `source` and `target`: `model_id`, `family`, `domain`, optional `modality`
|
|
(default `text`), a residual `site` and its recorded `semantics` (from
|
|
`BoundAdapter.site`). The source also gives the `fit_rows` its direction was
|
|
fitted on. The target may list `experts_tested`, which requires
|
|
`expert_coverage` (the experts map of an `expert_coverage` report on the
|
|
test rows); an expert below the coverage floor is refused rather than listed
|
|
as tested;
|
|
- `data`: row ids (optionally with `content_sha256`) for `alignment`,
|
|
`baseline_fit` and `test`;
|
|
- `conditions`: the families, domains, layers and experts the claim is about;
|
|
- `tensors`: a safetensors file with `source_direction`, `alignment_source`,
|
|
`alignment_target`, `baseline_fit`, `baseline_labels`, `test` and
|
|
`test_labels`, plus an optional SHA-256;
|
|
- optional `settings`: `ridge`, `bootstrap`, `random_directions`, `seed`,
|
|
`confidence`, `random_quantile`.
|
|
|
|
The spec is refused before anything is computed when:
|
|
|
|
- any fit rows (alignment, baseline or source direction) overlap the test rows,
|
|
by id or by content digest;
|
|
- the baseline does not use the same number of rows as the alignment;
|
|
- a site is not a residual site or lacks residual-stream semantics;
|
|
- a modality other than `text` does not declare its own `target_definitions`
|
|
and `scoring_tasks`;
|
|
- the conditions are not declared;
|
|
- the tensors do not match the row lists;
|
|
- the test set has fewer than 5 rows per class.
|
|
|
|
Method:
|
|
|
|
1. Fit a ridge map from target to source activations on the alignment rows.
|
|
The transferred readout is `u = P @ v_source`.
|
|
2. Within-model baseline: the difference of class means on the target's own
|
|
baseline rows, using the same budget.
|
|
3. Random baseline: seeded random directions, using the 0.95 quantile of their
|
|
sign-folded AUC.
|
|
4. Score every direction by the AUC of the test projections on the same
|
|
stratified paired bootstrap resamples.
|
|
|
|
A transfer gain is claimed only if the lower bound of the paired difference
|
|
interval is above zero against every baseline. Otherwise the claim states
|
|
which baseline was not beaten. A higher point estimate alone is not a gain.
|
|
|
|
The dossier (`obliteratus.transfer-dossier`, version 1) is written once, as
|
|
`transfer-<name>.json`. It holds the spec and tensor digests, the semantics of
|
|
both sides, alignment fit quality, scores and intervals, comparisons, the
|
|
claim kinds (`cross_family`, `cross_domain`, `cross_modality`), and the tested
|
|
and untested conditions. Untested conditions carry no claim.
|