transformer_lens.benchmarks.adapter_coverage_runner module

Run the adapter coverage checks on one adapter, as a command or a function.

python -m transformer_lens.benchmarks.adapter_coverage_runner

–adapter my_adapter.py –checkpoint org/tiny-foo –output report.json

Omit --adapter to check the adapter already registered for the checkpoint. An adapter file is registered for the run only; no repo file or registry entry is written. run_coverage_checks runs the same checks on a bridge that is already built.

transformer_lens.benchmarks.adapter_coverage_runner.load_adapter_class(source: str, module_name: str = 'coverage_adapter_under_test') → type

The one adapter class a file or importable module defines.

transformer_lens.benchmarks.adapter_coverage_runner.main(argv: Sequence[str] | None = None) → int
transformer_lens.benchmarks.adapter_coverage_runner.register_adapter(hf_class: str, adapter_class: type) → None

Point the adapter factory at adapter_class for this process.

transformer_lens.benchmarks.adapter_coverage_runner.run_adapter_coverage(checkpoint: str, adapter_path: str | None = None, hf_class: str | None = None, reference_adapter: str | None = None, device: str = 'cpu', dtype: str = 'float32', output_path: str | None = None, trust_remote_code: bool = False, variant_checkpoint: str | None = None, max_variant_params: float = 20000000.0, timeout: float = 600.0) → Dict[str, Any]

Run the coverage checks in a fresh subprocess and return the report.

transformer_lens.benchmarks.adapter_coverage_runner.run_checks_in_process(checkpoint: str, adapter_path: str | None = None, hf_class: str | None = None, reference_adapter: str | None = None, device: str = 'cpu', dtype: str = 'float32', trust_remote_code: bool = False, variant_checkpoint: str | None = None, max_variant_params: float = 20000000.0) → Dict[str, Any]

Boot a checkpoint and run every check in this process.

Prefer run_adapter_coverage(), which isolates the run in a subprocess: an adapter file given here stays registered for the rest of the process.

transformer_lens.benchmarks.adapter_coverage_runner.run_coverage_checks(bridge: TransformerBridge, reference_model: nn.Module | None = None, boot_variant: BootVariant | None = None, test_input: PromptInput = 'The capital of France is Paris, and the capital of Italy is Rome.', reference_surface: Dict[str, set] | None = None, variant_bridge: TransformerBridge | None = None, max_variant_params: float = 20000000.0, **header: Any) → Dict[str, Any]

Run every check on a bridge that is already built and return the report.

Needs no checkpoint name, adapter file or subprocess: any bridge will do.

Parameters:
  • bridge – The bridge whose adapter is under test.

  • reference_model – A pristine HF twin with the same weights; rebuilt from the bridge when omitted.

  • boot_variant – Builds a bridge around a rebuilt HF model, for the layer-type and scaling checks; defaults to the way bridge itself was built.

  • test_input – Prompt text, or token ids for a bridge with no tokenizer.

  • reference_surface – adapter_surface of a reference adapter’s bridge on the same checkpoint; the reference comparison is skipped without it.

  • variant_bridge – A smaller bridge of the same class to rebuild variants from.

  • max_variant_params – Above this size, variants are rebuilt from a shrunken config.

  • **header – Extra fields copied into the report.

transformer_lens.benchmarks.adapter_coverage_runner.summarize(results: Sequence[BenchmarkResult], declarations: Dict[str, str] | None = None, **header: Any) → Dict[str, Any]

The report: blocking findings decide passed; gaps only lower coverage.