Skip to content

deprecate remaining hooked entry points - #1592

Open
msaule wants to merge 3 commits into
TransformerLensOrg:devfrom
msaule:fix-hooked-entrypoint-deprecations
Open

deprecate remaining hooked entry points#1592
msaule wants to merge 3 commits into
TransformerLensOrg:devfrom
msaule:fix-hooked-entrypoint-deprecations

Conversation

@msaule

@msaule msaule commented Aug 1, 2026

Copy link
Copy Markdown

Summary

  • Emit DeprecationWarning from the remaining silent legacy entry points.
  • Gate the HookedRootModule warning to direct construction, avoiding duplicate warnings from subclasses.
  • Add regression coverage for one warning per constructor and a warning-free package import.

Why

Users who instantiate these legacy classes directly otherwise receive no migration notice ahead of the 4.0 removal. Each warning points to TransformerBridge.boot_transformers(...).

Closes #1590

Validation

  • pytest tests/unit/test_deprecation_warnings.py -q — 5 passed
  • mypy . — 385 source files, no issues
  • pycln, isort, and black checks passed on changed files

@jlarson4 jlarson4 linked an issue Aug 3, 2026 that may be closed by this pull request
6 tasks

@jlarson4 jlarson4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for picking this up @msaule! Looks pretty good, just a couple small adjustments to request before I can merge this. Detailed below:

**kwargs: Any,
):
super().__init__()
warnings.warn(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HookedEncoder.from_pretrained("bert-base-cased") still surfaces no deprecation notices because stacklevel=2 attributes the warning to HookedEncoder.py itself and Python's default ignore::DeprecationWarning filter then drops it. Can the warning also fire at the from_pretrained entry point, the way the sibling loaders do?

assert "4.0" in str(caught[0].message)


def test_importing_transformer_lens_emits_no_deprecation_warning():

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By the time this body runs, transformer_lens is already in sys.modules, so the import is a no-op that records nothing. I appended a real import-time DeprecationWarning to __init__.py and this test still passed. Is there a way to check import-time cleanliness that would fail?

Comment thread demos/Othello_GPT.ipynb
"execution_count": 56,
"metadata": {},
"outputs": [],
"outputs": [

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Grokking_Demo.ipynb and No_Position_Experiment.ipynb also construct HookedTransformer(cfg) in cells with empty stored outputs, and both run under make notebook-test. Can their outputs be re-recorded as well?

@msaule

msaule commented Aug 3, 2026

Copy link
Copy Markdown
Author

thanks for the thorough review. addressed all three items:

  • added a HookedEncoder.from_pretrained deprecation warning that reaches the caller, with a regression test that stops before any model download
  • changed the import-cleanliness test to run in a fresh python process
  • re-recorded the expected warning output for Grokking and No_Position

verified with pytest tests/unit/test_deprecation_warnings.py -q with 6 passing tests, plus the targeted No_Position notebook check.

**from_pretrained_kwargs: Any,
) -> HookedEncoder:
"""Loads in the pretrained weights from huggingface. Currently supports loading weight from HuggingFace BertForMaskedLM. Unlike HookedTransformer, this does not yet do any preprocessing on the model."""
warnings.warn(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outside pytest from_pretrained sits one frame below its caller, so stacklevel=4 overshoots and CPython attributes the warning to <sys>:0 — a plain script still sees nothing, while the sibling using stacklevel=2 does surface (HookedEncoderDecoder.py:555). The depth and the filename assertion at test_deprecation_warnings.py:91 have to move together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Proposal] Emit DeprecationWarning on remaining Hooked* entry points

2 participants