transformer_lens.benchmarks.adapter_coverage module

Adapter coverage checks: whether an adapter maps and exposes the whole architecture.

verify_models compares logits, which a bridge that delegates its forward to HuggingFace reproduces even when its hooks describe a different computation. These checks ask the complementary question on a path the logits cannot hide behind.

transformer_lens.benchmarks.adapter_coverage.adapter_surface(bridge: TransformerBridge) → Dict[str, set]

The hook names and weight names an adapter exposes on a checkpoint.

transformer_lens.benchmarks.adapter_coverage.annotate_gaps(gaps: Sequence[Dict[str, str]], declarations: Dict[str, str]) → Tuple[List[Dict[str, Any]], List[str]]

Attach each gap’s declared reason; also return declarations that match no gap.

A declaration explains a gap and never removes it, so it cannot change a verdict.

transformer_lens.benchmarks.adapter_coverage.benchmark_expected_hooks(bridge: TransformerBridge, test_input: str | Tensor | _Prompt = 'The capital of France is Paris, and the capital of Italy is Rome.', further_inputs: Sequence[_Prompt] = ()) → BenchmarkResult

The hooks the bridge classes in use promise exist, and fire on a forward pass.

A hook is silent only when it fires on none of the inputs: a vision tower’s hooks never fire on a text prompt, and that is not a gap.

transformer_lens.benchmarks.adapter_coverage.benchmark_hook_consistency(bridge: TransformerBridge, reference_model: Module, test_input: str | Tensor | _Prompt = 'The capital of France is Paris, and the capital of Italy is Rome.', max_interventions: int = 32) → BenchmarkResult

The hooks describe the computation that produces the logits.

transformer_lens.benchmarks.adapter_coverage.benchmark_layer_type_coverage(bridge: TransformerBridge, reference_model: Module, boot_variant: Callable[[Module], TransformerBridge] | None = None, test_input: str | Tensor | _Prompt = 'The capital of France is Paris, and the capital of Italy is Rome.', max_interventions: int = 8, max_variant_params: float | None = None) → BenchmarkResult

The adapter holds on every layer kind the config can describe, not only the checkpoint’s.

transformer_lens.benchmarks.adapter_coverage.benchmark_reference_comparison(surface: Dict[str, set], reference_surface: Dict[str, set]) → BenchmarkResult

Which of a reference adapter’s hook names and weight names the adapter also exposes.

transformer_lens.benchmarks.adapter_coverage.benchmark_residual_floor(bridge: TransformerBridge, test_input: str | Tensor | _Prompt = 'The capital of France is Paris, and the capital of Italy is Rome.') → BenchmarkResult

Every block’s change to the residual stream is accounted for by hooked outputs.

transformer_lens.benchmarks.adapter_coverage.benchmark_scaling_factor_coverage(bridge: TransformerBridge, reference_model: Module, boot_variant: Callable[[Module], TransformerBridge] | None = None, test_input: str | Tensor | _Prompt = 'The capital of France is Paris, and the capital of Italy is Rome.', max_interventions: int = 8, max_variant_params: float | None = None) → BenchmarkResult

The adapter holds when a multiplier the checkpoint leaves at 1.0 takes another value.

transformer_lens.benchmarks.adapter_coverage.benchmark_structural_coverage(bridge: TransformerBridge) → BenchmarkResult

Which HF parameters the bridge component for their module kind owns, and which it does not.

transformer_lens.benchmarks.adapter_coverage.build_reference_model(bridge: TransformerBridge) → Module

A pristine HF twin of the model the bridge wraps, with the same weights.

transformer_lens.benchmarks.adapter_coverage.build_shrunken_model(model_class: type, config: Any, device: device | None = None, dtype: dtype | None = None, max_parameters: float = 50000000.0, probe: Callable[[Module], Tuple[Tensor, Dict[str, Any]]] | None = None) → Tuple[Module, Dict[str, Any]]

A small random-weight model of this architecture, and the config edits that made it small.

Tries the most aggressive shrink first and backs off until HuggingFace builds the model and runs a forward pass, so no per-architecture list of size fields is needed. probe gives that forward’s input for a model that takes more than token ids, so a shrink that breaks the image or audio path is passed over too.

transformer_lens.benchmarks.adapter_coverage.declared_gaps(adapter: Any) → Dict[str, str]

An adapter’s own account of what it leaves unexposed, or {} when it gives none.

transformer_lens.benchmarks.adapter_coverage.default_variant_booter(bridge: TransformerBridge, **boot_kwargs: Any) → Callable[[Module], TransformerBridge]

Boot variants the way the bridge under test was built, reusing its tokenizer.

transformer_lens.benchmarks.adapter_coverage.merge_input_runs(name: str, runs: Sequence[Tuple[str, BenchmarkResult]]) → BenchmarkResult

One result for a check that ran once per input.

Parts from every input after the first carry that input’s name, so a finding says which input it came from; the first input’s parts keep the names a text-only run gives.

transformer_lens.benchmarks.adapter_coverage.model_inputs(bridge: TransformerBridge, test_input: str | Tensor | _Prompt = 'The capital of France is Paris, and the capital of Italy is Rome.', first_only: bool = False) → Tuple[List[_Prompt], List[Dict[str, str]]]

Every input this kind of model takes, and those that could not be built, with why.

A model that reads text gets the text prompt first; one that also has a vision or audio tower gets a second prompt that feeds it. The kind comes from the flags the bridge already sets and the towers the HF config declares. first_only stops after the first, sparing the processor call behind the others.

transformer_lens.benchmarks.adapter_coverage.module_kind(module: Module) → str

Row of MODULE_KIND_OWNERS a parameter-bearing HF module belongs to.

transformer_lens.benchmarks.adapter_coverage.reference_coverage(surface: Dict[str, set], reference_surface: Dict[str, set]) → float

Share of the reference’s hook and weight names the adapter also has, pooled.

transformer_lens.benchmarks.adapter_coverage.shrunken_reference(reference: Module, prompt: _Prompt | None = None) → Tuple[Module, Dict[str, Any]]

The reference architecture rebuilt small with random weights, and how it was shrunk.

A variant is rebuilt whole, so a large checkpoint has to be rebuilt small first. Random weights are fine there: the question is whether the bridge and HuggingFace compute the same thing, not what they compute.