Add clean-coordinate clamping for JacobianLens swaps - #1747
Open
koriyoshi2041 wants to merge 6 commits into
Open
Add clean-coordinate clamping for JacobianLens swaps#1747koriyoshi2041 wants to merge 6 commits into
koriyoshi2041 wants to merge 6 commits into
Conversation
koriyoshi2041
force-pushed
the
fix/jacobian-lens-swap-clamp-dev
branch
from
September 5, 2026 05:35
de8d3d7 to
b85d449
Compare
This was referenced Sep 5, 2026
1 task
jlarson4
reviewed
Sep 8, 2026
jlarson4
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for documenting and putting together a fix for this @koriyoshi2041. The parity mechanism reproduces as described, and the clamp holds at every band width. Just a couple small comments below on some edge cases that were missed by the CI
jlarson4
reviewed
Sep 8, 2026
- accept either an ActivationCache or the plain dict from run_with_cache(return_cache_object=False) in swap_clamp_hooks, and say so in the docstring - add a unit test that passes the raw cache dict through the clamp - move the demo's rank cell onto swap_clamp_hooks via a shared clamped_logits helper, reword the sweep intro so the live swap is no longer called a clamp, drop the stale swap name from the cleanup cell - re-execute the notebook end to end with the pinned model and lens revisions so the stored outputs match the code, and update the section 3 and 4 prose to this run's numbers
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.
Description
Adds
JacobianLens.swap_clamp_hooks, which fixes each hooked layer's source/target lens coordinates to the exchanged values from a clean-run cache. This implements the multi-layer clamp form without changing the existing live-coordinate semantics ofswap_hooks.Also documents that repeated live swaps are involutive and can cancel across a layer band.
Fixes #1746
Type of change
Screenshots
Not applicable; numerical evidence is attached to #1746.
Validation
make formatuv run pytest tests/unit/tools/test_jacobian_lens.py -q(93 passed)uv run mypy transformer_lens/tools/analysis/jacobian_lens.pygit diff --checkChecklist