Fix TransformerBridge temporary hook cleanup - #1638
Merged
jlarson4 merged 2 commits intoAug 11, 2026
Merged
Conversation
Contributor
Author
|
CI update: all code-related checks on head ede493b are green, including compatibility checks on Python 3.10/3.11/3.12, full coverage, format, type, docstring, and benchmark checks. The two remaining failed notebook jobs (Attribution_Patching_Demo and Activation_Patching_in_TL_Demo) failed while downloading unchanged Hugging Face models with HTTP 429 Too Many Requests (gpt2 and NeelNanda/Attn_Only_2L512W_C4_Code); the later NameErrors are cascading from those load failures. This PR does not modify either notebook. Marking this ready for review. |
emerardd
marked this pull request as ready for review
August 11, 2026 04:17
Collaborator
|
Great work on this @emerardd! Approved and merging as is. |
Closed
1 task
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
Summary
hooks(),run_with_hooks(), andrun_with_cache().run_with_cache()hook attachment until input preprocessing is complete, and make partial hook installation exception-safe.reset_hooks_end=False.Root cause and impact
BridgeCore previously tracked only each touched HookPoint and direction, then called unscoped
remove_hooks(dir=...)when a temporary helper exited. That removed every non-permanent hook in the selected direction, including hooks installed before the helper call or owned by an outer context.This could silently disable an intervention or recording hook after an otherwise successful cache/helper call. Later experiments would continue running without the intended hook and without an exception.
The fix mirrors the established
HookedRootModulelifecycle contract: each helper invocation receives a context level, every temporary hook it owns is tagged with that level, and exception-safe cleanup removes only that level. Publicreset_hooks_end=Falsebehavior remains unchanged.Fixes #1636
Type of change
Screenshots
N/A — code-only hook lifecycle fix.
Validation
89 passed.9 passed, 17 deselected.mypy .: no issues in 424 source files.git diff --check: passed.Checklist: