interlens.interp.capture¶
interlens.interp.capture
¶
CaptureRequest
dataclass
¶
A pending capture handed to generate: where to store records (cache) and what to grab (spec).
The Conversation builds this (via conv.capture(...)) and the participant fills the cache with records
tagged by participant + turn, so the caller ends up with structurally-tagged activations.
CapturedSite
¶
Bases: NamedTuple
One activation captured by capture_activations: the tensor ([seq, d_model]) at a given
layer and site. A lightweight typed row (unpacks like the old (layer, site, tensor) tuple) that
the participant folds into a fully-tagged ActivationRecord.
capture_activations
¶
capture_activations(
model: "PreTrainedModel",
input_ids: Tensor,
spec: CaptureSpec,
) -> list[CapturedSite]
Run one clean forward pass over input_ids and return [(layer, site, tensor[seq, d_model])].
Design choice: capture is a separate forward pass over the full (prompt + generated) sequence rather than
accumulating hooks across the multi-step decode loop. This is simpler and provably complete — every position
is present in one pass — at the cost of one extra forward. Residual-stream activations come from
output_hidden_states (no hooks needed); attn/mlp sublayer outputs come from forward hooks on the
corresponding submodules.
Note: attn captures the attention sublayer output (post-o_proj), which is available under any attention
backend. Attention weights/patterns are NOT captured here — those require attn_implementation='eager' +
output_attentions and are out of scope for the default kernel.