Skip to content

[Proposal] Rewrite executable doctests that construct HookedTransformer onto TransformerBridge #1565

Description

@jlarson4

Proposal

Base on dev-4.x. Rewrite the executable >>> doctests that build a HookedTransformer so they construct a TransformerBridge instead, in the modules that keep running doctests after HookedTransformer is removed: transformer_lens/ActivationCache.py (4 HT-constructing doctests), transformer_lens/evals.py (2 HT-constructing doctests, only 1 executable at :326-329 — the other is already # doctest: +SKIP at :554-559), transformer_lens/utilities/exploratory_utils.py (1).

Motivation

HookedTransformer is being deprecated in favour of TransformerBridge. ActivationCache, evals, and exploratory_utils are staying, but their doctests still do HookedTransformer.from_pretrained(...). pytest runs these (pyproject.toml enables --doctest-modules over transformer_lens/), so they will hard-fail the moment HookedTransformer is removed. Migrating them now keeps the examples current and unblocks removal.

Pitch

  • Replace HookedTransformer.from_pretrained("gpt2"...) with TransformerBridge.boot_transformers("gpt2") (add .enable_compatibility_mode() where the example relies on HookedTransformer-exact hook names / numerics).
  • Update expected doctest output to whatever the bridge prints, and any # doctest: +SKIP markers that are no longer needed. Note every executable example also asserts the literal output line Loaded pretrained model ... into HookedTransformer, so each rewrite must update that expected-output line too.
  • Keep each example's teaching intent identical; only the model construction changes.

Acceptance:

  • No doctest in ActivationCache.py, evals.py, utilities/exploratory_utils.py constructs HookedTransformer
  • make docstring-test (or pytest --doctest-modules transformer_lens/) passes
  • make unit-test passes
  • uv run mypy . passes

Mirror: existing bridge examples in docs/source/content/ and the boot_transformers / enable_compatibility_mode usage in tests/unit/model_bridge/.

Checklist

  • I have checked that there is no similar issue in the repo (required)

Metadata

Metadata

Assignees

Labels

TransformerBridgeBug specific to the new TransformerBridge systemcomplexity-moderateModerately complicated issues for people who have intermediate experience with the codeenhancementNew feature or requestgood first issueGood for newcomershelp wantedExtra attention is neededv4.x

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions