Add missing hooks#704
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds/extends hook-point coverage across multiple SAE variants (including TemporalSAE and JumpReLU) and introduces regression tests to ensure hook caches are populated with expected tensors during forward passes.
Changes:
- Add
hook_sae_acts_pre/hook_sae_acts_postcalls to TemporalSAE and JumpReLU encode paths. - Add tests across SAEs/Transcoders verifying hook cache keys and (where feasible) cached values.
- Minor test import/type updates to support new parametrized coverage.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/saes/test_transcoder.py | Adds parametrized test asserting transcoder hook caches are populated and consistent. |
| tests/saes/test_topk_sae.py | Adds hook-cache assertions for TopK SAE training and inference paths. |
| tests/saes/test_temporal_sae.py | Adds TemporalSAE hook-cache regression test and needed helper import. |
| tests/saes/test_standard_sae.py | Adds hook-cache assertions for Standard SAE training and inference paths; imports TrainStepInput. |
| tests/saes/test_matryoshka_batchtopk_sae.py | Adds hook-cache assertions for Matryoshka BatchTopK training path. |
| tests/saes/test_jumprelu_sae.py | Extends existing training test to assert hook-cache contents. |
| tests/saes/test_gated_sae.py | Adds hook-cache assertions for Gated training path. |
| tests/saes/test_batchtopk_sae.py | Adds hook-cache assertions for BatchTopK training path. |
| sae_lens/saes/temporal_sae.py | Wires hook_sae_acts_pre/hook_sae_acts_post into novel-code path in TemporalSAE. |
| sae_lens/saes/jumprelu_sae.py | Wires hook_sae_acts_pre/hook_sae_acts_post into JumpReLU encode path. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+303
to
+304
| hidden_pre = self.hook_sae_acts_pre(torch.matmul(x_residual * self.lam, W_enc)) | ||
| z_novel = F.relu(hidden_pre) |
| mask = torch.zeros_like(z_novel) | ||
| mask.scatter_(-1, topk_indices, 1) | ||
| z_novel = z_novel * mask | ||
| z_novel = self.hook_sae_acts_post(z_novel) |
Comment on lines
+895
to
+908
| def test_StandardTrainingSAE_training_forward_pass_calls_hooks(): | ||
| sae = StandardTrainingSAE(build_sae_training_cfg()) | ||
| x = torch.randn(32, sae.cfg.d_in) | ||
| train_step_output = sae.training_forward_pass( | ||
| step_input=TrainStepInput( | ||
| sae_in=x, | ||
| coefficients={"l1": sae.cfg.l1_coefficient}, | ||
| dead_neuron_mask=None, | ||
| n_training_steps=0, | ||
| is_logging_step=False, | ||
| ), | ||
| ) | ||
|
|
||
| _, cache = sae.run_with_cache(x) |
Comment on lines
+45
to
+52
| def test_TemporalSAE_forward_pass_calls_hooks(): | ||
| sae = TemporalSAE(build_temporal_sae_cfg(dtype="float32")) | ||
| x = torch.randn(4, 16, sae.cfg.d_in) | ||
| out, cache = sae.run_with_cache(x) | ||
| assert_close(cache["hook_sae_input"], x) | ||
| assert "hook_sae_acts_pre" in cache | ||
| assert_close(cache["hook_sae_acts_post"], sae.encode(x)) | ||
| assert_close(cache["hook_sae_output"], out) |
Comment on lines
+482
to
+504
| def test_TopKTrainingSAE_training_forward_pass_calls_hooks(): | ||
| sae = TopKTrainingSAE(build_topk_sae_training_cfg()) | ||
| x = torch.randn(32, sae.cfg.d_in) | ||
| train_step_output = sae.training_forward_pass( | ||
| step_input=TrainStepInput( | ||
| sae_in=x, | ||
| coefficients={}, | ||
| dead_neuron_mask=None, | ||
| n_training_steps=0, | ||
| is_logging_step=False, | ||
| ), | ||
| ) | ||
|
|
||
| _, cache = sae.run_with_cache(x) | ||
| assert_close(cache["hook_sae_input"], x) | ||
| # topk rescales hidden_pre by the decoder norm after hook_sae_acts_pre fires, | ||
| # so the hook captures the raw pre-activation, not train_step_output.hidden_pre | ||
| assert_close( | ||
| cache["hook_sae_acts_pre"], sae.process_sae_in(x) @ sae.W_enc + sae.b_enc | ||
| ) | ||
| assert_close(cache["hook_sae_acts_post"], train_step_output.feature_acts) | ||
| assert_close(cache["hook_sae_recons"], train_step_output.sae_out) | ||
| assert_close(cache["hook_sae_output"], train_step_output.sae_out) |
…ingSAE and TemporalSAE fail Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
chanind
approved these changes
Jun 16, 2026
chanind
left a comment
Collaborator
There was a problem hiding this comment.
Good catch! Thanks you for this!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add missing
hook_sae_acts_pre/postinJumpReLUTrainingSAEandTemporalSAEChecklist:
You have tested formatting, typing and tests
make check-cito check format and linting. (you can runmake formatto format code if needed.)