-
Notifications
You must be signed in to change notification settings - Fork 148
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
Encode with slice #334
base: main
Are you sure you want to change the base?
Encode with slice #334
Changes from 5 commits
5f17c0e
27933f7
64c6fc4
cbda3a0
aef2fc1
e1d105a
9fd5f2e
393a43a
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 |
---|---|---|
|
@@ -70,6 +70,19 @@ def test_sae_init(cfg: LanguageModelSAERunnerConfig): | |
assert sae.b_dec.shape == (cfg.d_in,) | ||
|
||
|
||
def test_sae_encode_with_slicing(cfg: LanguageModelSAERunnerConfig): | ||
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. nit: It would be good to test with |
||
sae = SAE.from_dict(cfg.get_base_sae_cfg_dict()) | ||
assert isinstance(cfg.d_sae, int) | ||
|
||
activations = torch.randn(10, 4, cfg.d_in, device=cfg.device) | ||
latents = torch.randint(low=0, high=cfg.d_sae, size=(10,)).tolist() | ||
feature_activations = sae.encode(activations) | ||
feature_activations_slice = sae.encode(activations, latents=latents) | ||
torch.testing.assert_close( | ||
feature_activations[..., latents], feature_activations_slice | ||
) | ||
|
||
|
||
def test_sae_fold_w_dec_norm(cfg: LanguageModelSAERunnerConfig): | ||
sae = SAE.from_dict(cfg.get_base_sae_cfg_dict()) | ||
sae.turn_off_forward_pass_hook_z_reshaping() # hook z reshaping not needed here. | ||
|
@@ -106,7 +119,6 @@ def test_sae_fold_w_dec_norm(cfg: LanguageModelSAERunnerConfig): | |
|
||
|
||
def test_sae_fold_norm_scaling_factor(cfg: LanguageModelSAERunnerConfig): | ||
|
||
norm_scaling_factor = 3.0 | ||
|
||
sae = SAE.from_dict(cfg.get_base_sae_cfg_dict()) | ||
|
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.
nit: should this also take a tensor as well? It seems like the code will work with a tensor of ints as well
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.
It also looks like
topk
SAEs go through this codepath and will silently break if anything is passed forlatents
. We should make it non-silent.