mirror of
https://github.com/elder-plinius/OBLITERATUS.git
synced 2026-12-06 11:04:06 +01:00
Weights edited in place under the same model id and revision were not detected, expired captures still loaded, and run stores could not be pruned because reused steps reference earlier attempts. - Fingerprint: a deterministic fingerprint of every parameter and buffer (names, shapes, dtypes and a fixed strided sample of each tensor, with an optional full digest) joins the capture identity and the runner's model identity. Captures and steps from before the fingerprint are refused or recomputed with a recorded reason. The pipeline's entry-point cache identity is unchanged. - Retention: load_capture refuses captures past expires_at unless inspection is requested; comparison inspects stored captures regardless of expiry. - Pruning: `obliteratus experiments prune` (dry run by default) keeps the latest complete attempt, the newest N, active attempts and every attempt a kept one reuses, records a pruned event before deleting, and finishes interrupted removals on the next applied prune. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
127 lines
6.6 KiB
Markdown
127 lines
6.6 KiB
Markdown
# Activation observation
|
|
|
|
Pipeline subclasses can override `_read_activation_hidden(layer, output)` to
|
|
select a model-specific readout. The collector retains its tokenization, batching,
|
|
pooling, and hook cleanup. Readouts must preserve layer outputs and weights.
|
|
|
|
`observe_activations` records detached CPU activations without replacing decoder
|
|
outputs. Supply the current call's binary token mask and a semantic phase label.
|
|
The default token is the last unmasked position in each row. A decode step needs
|
|
its own scope and a mask excluding cached history.
|
|
|
|
```python
|
|
from obliteratus.analysis import (
|
|
deepseek_v41_post_block_readout,
|
|
inspect_deepseek_v41_engram,
|
|
observe_activations,
|
|
)
|
|
|
|
# A loaded native DeepseekV41ForCausalLM; paths are relative to its text backbone.
|
|
layout = inspect_deepseek_v41_engram(model.model)
|
|
layers = {str(i): layer for i, layer in enumerate(model.model.layers)}
|
|
with observe_activations(
|
|
layers,
|
|
attention_mask=inputs["attention_mask"],
|
|
phase="prompt.thinking_off",
|
|
readout=deepseek_v41_post_block_readout,
|
|
readout_name="deepseek_v41.post_block.v1",
|
|
) as observations:
|
|
output = model(**inputs, use_cache=False)
|
|
```
|
|
|
|
Phase labels are caller-supplied. The observer does not parse chat templates,
|
|
detect thinking boundaries, gate interventions, or modify weights. Each selected
|
|
layer must execute exactly once; failures discard partial observations and remove
|
|
hooks. Custom readouts must preserve their inputs.
|
|
|
|
V4.1 returns `(hidden_streams[B,S,hc,H], pre_mix[B,S,hc])`. Its readout uses the
|
|
layer's native weighted collapse. It is not an average across streams or an
|
|
inverse mapping for edits. Generic steering hooks reject unsupported tensor ranks.
|
|
|
|
Engram tables reside at `engram_tables.<layer>`, separately from injections at
|
|
`layers.<layer>.engram`. The inspector validates configuration order, keys, shapes,
|
|
and injection locations. It inventories tables, optional scales, gate/fusion
|
|
parameters, and shared hash buffers, including nonpersistent tokenizer-derived
|
|
state. It neither moves tables nor hashes their contents.
|
|
|
|
The released V4.1 configuration injects at zero-based layers 1 and 14, before
|
|
attention. Outputs of layers 0 and 13 therefore precede those injections; they
|
|
must not be labeled as the next layer's post-Engram input. Positions are derived
|
|
from the loaded configuration rather than fixed to this release.
|
|
|
|
Inventory devices describe loaded tensors, including `meta`. Logical byte counts
|
|
do not estimate resident allocations, local tensor-parallel shards, offload
|
|
buffers, or peak memory. Two BF16 tables of shapes `(384006168, 256)` and
|
|
`(384016682, 256)` require 393,227,699,200 logical bytes, excluding scales.
|
|
|
|
This API does not enable V4.1 weight editing or certify an artifact's integrity.
|
|
Native semantics were reviewed against Transformers revision
|
|
`62d7ebd7de4938e072b7aaeb881593b79dc56835`; the locked dependency does not yet
|
|
provide those model classes. No dependency version is changed by this API.
|
|
|
|
## Activation capture
|
|
|
|
`capture_activations` writes observations to disk for later reuse. Each input
|
|
batch runs once under read-only hooks and produces one safetensors shard in
|
|
`raw/`. Derived results must be stored separately. `manifest.json` records:
|
|
|
|
- identity: model id, revision, realized parameter dtype, tokenizer fields, chat
|
|
template, special tokens, vocabulary digest, adapter state, readout, phase,
|
|
sites, input batch digests, optional dataset `revision` and a weight
|
|
fingerprint of every parameter and buffer;
|
|
- state: `running`, `complete`, `cancelled` or `failed`, with a reason when
|
|
incomplete;
|
|
- a byte estimate labelled `estimate`, plus measured bytes written and wall time;
|
|
- shard digests and retention metadata.
|
|
|
|
```python
|
|
from obliteratus.analysis.activation_capture import capture_activations, load_capture
|
|
from obliteratus.analysis.capture_identity import capture_identity
|
|
|
|
layers = {str(i): block for i, block in enumerate(model.transformer.h)}
|
|
preview = capture_activations(model, tokenizer, layers, batches, "runs/cap",
|
|
model_id="org/model", phase="prompt",
|
|
budget_bytes=2**30, dry_run=True)
|
|
capture_activations(model, tokenizer, layers, batches, "runs/cap",
|
|
model_id="org/model", phase="prompt", budget_bytes=2**30,
|
|
dataset=dataset, check_cancelled=stop_requested)
|
|
current = capture_identity(model, tokenizer, layers, batches,
|
|
model_id="org/model", phase="prompt", dataset=dataset)
|
|
loaded = load_capture("runs/cap", current)
|
|
```
|
|
|
|
An estimate above `budget_bytes` is refused before hooks are registered.
|
|
Measured bytes above the budget fail the capture. `check_cancelled` runs before
|
|
each batch and each selected layer. Any exception it raises removes hooks, marks
|
|
the manifest `cancelled` and propagates. Completed shards remain recorded.
|
|
|
|
`load_capture` refuses incomplete captures unless `allow_incomplete=True`.
|
|
It also refuses a tampered manifest, identity differences and shard digest
|
|
mismatches. Errors name the first differing field, for example
|
|
`tokenizer.chat_template`. Tokenizer and checkpoint fields match the entry-point
|
|
activation cache identity; the weight fingerprint is not part of that cache.
|
|
|
|
The `weights` field digests sorted parameter and buffer names, shapes, dtypes
|
|
and a fixed evenly strided sample of 256 elements per tensor (copied to the CPU
|
|
on its own), so weights edited in place under the same id and revision no
|
|
longer match. Sampled mode can miss an edit that touches no sampled element;
|
|
`capture_identity(..., weight_digest="full")` hashes every element instead and
|
|
detects any byte change, reading all weights. Both sides of a comparison must
|
|
use the same mode. Captures written before the fingerprint existed are refused
|
|
with `Capture predates weight fingerprint; capture again` (field `weights`).
|
|
|
|
Retention is enforced on load. A capture whose `retention.expires_at` is at or
|
|
before the current UTC time is refused, naming `retention.expires_at`, unless
|
|
`allow_expired=True` is passed to inspect it. Captures without an expiry
|
|
(`keep-until-deleted`) never expire. A timestamp without a timezone is refused.
|
|
Pass `clock=` (a function returning a timezone-aware datetime) to evaluate
|
|
expiry at another time. Expired captures are not deleted automatically.
|
|
|
|
Adapter state is `none` when no adapter configuration or known adapter-layer
|
|
markers exist. Readable named configurations with an observable active set are
|
|
`peft`. Every other case is `unknown`, which is never reused. Adapters merged into
|
|
weights leave no marker; only the checkpoint identity covers them.
|
|
|
|
Only dense CPU execution in eval mode is supported. Meta, non-CPU, dispatched,
|
|
offloaded and quantized models are refused.
|