-
Notifications
You must be signed in to change notification settings - Fork 659
deprecate remaining hooked entry points #1592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
b56b786
1338ecd
90f2782
b2f5965
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| """Regression coverage for deprecated legacy entry points.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import warnings | ||
|
|
||
| import pytest | ||
|
|
||
|
|
||
| def _small_config(): | ||
| from transformer_lens import HookedTransformerConfig | ||
|
|
||
| return HookedTransformerConfig( | ||
| n_layers=1, | ||
| d_model=16, | ||
| d_head=4, | ||
| n_heads=4, | ||
| n_ctx=8, | ||
| d_vocab=20, | ||
| attn_only=True, | ||
| ) | ||
|
|
||
|
|
||
| def _assert_single_deprecation(constructor, class_name: str) -> None: | ||
| with pytest.warns(DeprecationWarning, match=class_name) as caught: | ||
| constructor() | ||
|
|
||
| assert len(caught) == 1 | ||
| assert "TransformerBridge.boot_transformers" in str(caught[0].message) | ||
| assert "4.0" in str(caught[0].message) | ||
|
|
||
|
|
||
| def test_importing_transformer_lens_emits_no_deprecation_warning(): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By the time this body runs, |
||
| with warnings.catch_warnings(record=True) as caught: | ||
| warnings.simplefilter("always") | ||
| import transformer_lens # noqa: F401 | ||
|
|
||
| assert not [warning for warning in caught if issubclass(warning.category, DeprecationWarning)] | ||
|
|
||
|
|
||
| def test_hooked_transformer_constructor_warns_once(): | ||
| from transformer_lens import HookedTransformer | ||
|
|
||
| _assert_single_deprecation(lambda: HookedTransformer(_small_config()), "HookedTransformer") | ||
|
|
||
|
|
||
| def test_hooked_encoder_constructor_warns_once(): | ||
| from transformer_lens import HookedEncoder | ||
|
|
||
| _assert_single_deprecation(lambda: HookedEncoder(_small_config()), "HookedEncoder") | ||
|
|
||
|
|
||
| def test_bert_next_sentence_prediction_constructor_warns_once(): | ||
| from transformer_lens import BertNextSentencePrediction | ||
|
|
||
| _assert_single_deprecation( | ||
| lambda: BertNextSentencePrediction(object()), "BertNextSentencePrediction" | ||
| ) | ||
|
|
||
|
|
||
| def test_direct_hooked_root_module_construction_warns_once(): | ||
| from transformer_lens import HookedRootModule | ||
|
|
||
| _assert_single_deprecation(HookedRootModule, "HookedRootModule") | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ | |
|
|
||
| import logging | ||
| import os | ||
| import warnings | ||
| from typing import Any, Dict, List, Optional, Tuple, TypeVar, Union, cast, overload | ||
|
|
||
| import torch | ||
|
|
@@ -58,6 +59,12 @@ def __init__( | |
| **kwargs: Any, | ||
| ): | ||
| super().__init__() | ||
| warnings.warn( | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| "HookedEncoder is deprecated and will be removed in 4.0. Use " | ||
| "TransformerBridge.boot_transformers(...) instead.", | ||
| DeprecationWarning, | ||
| stacklevel=2, | ||
| ) | ||
| if isinstance(cfg, Dict): | ||
| cfg = HookedTransformerConfig(**cfg) | ||
| elif isinstance(cfg, str): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grokking_Demo.ipynbandNo_Position_Experiment.ipynbalso constructHookedTransformer(cfg)in cells with empty stored outputs, and both run undermake notebook-test. Can their outputs be re-recorded as well?