transformer_lens.model_bridge.sources.inspect.profiles module

Per-provider request/response codecs for the Inspect driver.

The driver speaks one internal shape; each provider speaks its own. A Profile encapsulates everything provider-specific: which hooks it serves, whether it returns full-sequence logits, how to phrase the generate request (prompt + extra_args), how to translate interventions, and how to read logits back. Torch-free (numpy only) so the driver stays torch-free.

tl_bridge is our own HF provider (provider.py). vllm-lens is the third-party provider. The vllm-lens codec is written from its documented API and is NOT verified against a live provider (CI has none — it needs their GPU-served provider). It’s isolated here so this is the single place to fix once validated.

class transformer_lens.model_bridge.sources.inspect.profiles.TLBridgeProfile(supported_kinds: Any = None, provides_sequence_logits: bool = True)

Bases: object

Codec for our own tl_bridge provider: residual/attn/mlp hooks, full-seq logits.

supported_kinds is the provider’s structurally-detected boundary set (e.g. resid_mid dropped for parallel/norm-variant archs); None exposes all boundaries.

build_request(ids, wire_keys, interventions, return_logits, tokenizer)
decode_logits(output, n_tokens, d_vocab, tokenizer)
provides_sequence_logits = True
supported_hooks(n_layers: int) frozenset[str]
translate_interventions(intervene, supported)
class transformer_lens.model_bridge.sources.inspect.profiles.VLLMLensProfile

Bases: object

Codec for the third-party vllm-lens provider.

Residual-stream-only, additive-steering-only, and last-token logits synthesized one-hot from the generated token (argmax-only — vllm-lens doesn’t hand back full logits through this path). Prompt is the detokenized text, so vllm-lens re-tokenizes it: activations reflect that re-tokenization, which may differ from the exact ids. UNVERIFIED against a live provider.

build_request(ids, wire_keys, interventions, return_logits, tokenizer)
decode_logits(output, n_tokens, d_vocab, tokenizer)
provides_sequence_logits = False
supported_hooks(n_layers: int) frozenset[str]
translate_interventions(intervene: Mapping[str, Any], supported) list

op=’add’ with a width-shaped vector → vllm-lens SteeringVector; others raise.

Validates before importing vllm_lens so non-additive ops (and the no-intervention case) don’t require the package installed.

transformer_lens.model_bridge.sources.inspect.profiles.for_provider(provider: str) Any

Pick the codec for a provider name (the part before / in get_model).