Files
OBLITERATUS/obliteratus/experiments/transfer_cli.py
Joseph MaglyandClaude Opus 5.5 abae042774 feat(analysis): architecture adapters, MoE coverage and transfer dossiers
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>
2026-11-16 13:31:08 -05:00

61 lines
2.7 KiB
Python

"""``obliteratus experiments transfer run`` and ``obliteratus experiments arch-profile``."""
import json
def add_transfer(commands):
parser = commands.add_parser(
"transfer", help="Transfer dossiers: evaluate a source-model direction on a target "
"model/domain against within-model and random baselines")
sub = parser.add_subparsers(dest="transfer_command", required=True)
run = sub.add_parser("run", help="Evaluate one transfer spec and write its dossier")
run.add_argument("spec", help="Transfer spec JSON (schema obliteratus.transfer-spec v1)")
run.add_argument("--out", required=True, help="Output directory (write-once dossier)")
def add_arch_profile(commands):
parser = commands.add_parser(
"arch-profile", help="Architecture adapter profile: tensor semantics and capability "
"support levels of a local model")
parser.add_argument("--model", required=True, help="Local model directory (no downloads)")
parser.add_argument("--verify", action="store_true",
help="Load the weights on CPU and verify residual-site semantics")
parser.add_argument("--require", choices=("observation", "reversible_intervention",
"persistent_editing"),
help="Refuse (exit 4) unless this capability is supported")
parser.add_argument("--scope", help="Scope the --require check (e.g. residual_stream)")
def run_transfer_command(args):
from obliteratus.analysis.transfer_dossier import run_transfer_spec
return run_transfer_spec(args.spec, args.out)
def run_arch_profile_command(args):
import torch
from transformers import AutoConfig, AutoModelForCausalLM
from obliteratus.arch_adapters import adapter_for, bind, check_residual_semantics
config = AutoConfig.from_pretrained(args.model, local_files_only=True)
adapter = adapter_for(config)
if args.require:
adapter.require(args.require, args.scope)
check = None
if args.verify:
model = AutoModelForCausalLM.from_pretrained(
args.model, local_files_only=True, dtype=torch.float32).eval()
bound = bind(model)
ids = torch.arange(min(8, config.vocab_size)).unsqueeze(0)
check = check_residual_semantics(bound, ids)
else:
with torch.device("meta"):
model = AutoModelForCausalLM.from_config(config)
bound = bind(model)
profile = bound.profile(check)
profile["source"] = {"model": str(args.model), "weights_loaded": bool(args.verify)}
return json.loads(json.dumps(profile, default=str))
__all__ = ["add_arch_profile", "add_transfer", "run_arch_profile_command", "run_transfer_command"]