Add missing calls to reshape_fn_out() in TemporalSAE#695
Open
danra wants to merge 2 commits into
Open
Conversation
…rward Both methods are missing calls to reshape_fn_out() Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Fixes failing tests
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 output reshaping for hook_z-mode TemporalSAE so decoded/reconstructed activations return to (batch, seq, n_heads, d_head) layout, and introduces tests to validate the expected output shape.
Changes:
- Reshape decoder/forward outputs via
reshape_fn_out(..., d_head)to reversehook_zinput reshaping. - Add pytest coverage asserting decode/forward return to the original 4D
hook_zshape.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| tests/saes/test_temporal_sae.py | Adds shape-based tests for decode/forward when reshape_activations="hook_z". |
| sae_lens/saes/temporal_sae.py | Applies reshape_fn_out in decode and forward to reverse hook_z reshaping. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
331
to
337
| # Apply output activation normalization (reverses input normalization) | ||
| sae_out = self.run_time_activation_norm_fn_out(sae_out) | ||
|
|
||
| sae_out = self.reshape_fn_out(sae_out, self.d_head) | ||
|
|
||
| # Add bias (already removed in process_sae_in) | ||
| logger.warning( |
| assert reconstruction.shape == (batch_size, seq_len, cfg.d_in) | ||
|
|
||
|
|
||
| def test_TemporalSAE_decode_reverses_hook_z_reshaping(): |
Comment on lines
+96
to
+99
| assert reconstruction.shape == x.shape | ||
|
|
||
|
|
||
| def test_TemporalSAE_forward_reverses_hook_z_reshaping(): |
|
|
||
| reconstruction = sae(x) | ||
|
|
||
| assert reconstruction.shape == x.shape |
Comment on lines
+80
to
+91
| def test_TemporalSAE_decode_reverses_hook_z_reshaping(): | ||
| n_heads = 4 | ||
| d_head = 8 | ||
| cfg = build_temporal_sae_cfg(d_in=n_heads * d_head, reshape_activations="hook_z") | ||
| sae = TemporalSAE.from_dict(cfg.to_dict()) | ||
| assert sae.hook_z_reshaping_mode | ||
|
|
||
| batch_size = 2 | ||
| seq_len = 6 | ||
| x = torch.randn( | ||
| batch_size, seq_len, n_heads, d_head, dtype=DTYPE_MAP[sae.cfg.dtype] | ||
| ) |
Comment on lines
+99
to
+110
| def test_TemporalSAE_forward_reverses_hook_z_reshaping(): | ||
| n_heads = 4 | ||
| d_head = 8 | ||
| cfg = build_temporal_sae_cfg(d_in=n_heads * d_head, reshape_activations="hook_z") | ||
| sae = TemporalSAE.from_dict(cfg.to_dict()) | ||
| assert sae.hook_z_reshaping_mode | ||
|
|
||
| batch_size = 2 | ||
| seq_len = 6 | ||
| x = torch.randn( | ||
| batch_size, seq_len, n_heads, d_head, dtype=DTYPE_MAP[sae.cfg.dtype] | ||
| ) |
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.
Type of change
Please delete options that are not relevant.
Checklist:
You have tested formatting, typing and tests
make check-cito check format and linting. (you can runmake formatto format code if needed.)