Support callable filters in TransformerBridge.add_hook()#1186
Merged
jlarson4 merged 1 commit intodev-3.x-canaryfrom Feb 27, 2026
Merged
Support callable filters in TransformerBridge.add_hook()#1186jlarson4 merged 1 commit intodev-3.x-canaryfrom
jlarson4 merged 1 commit intodev-3.x-canaryfrom
Conversation
TransformerBridge.add_hook() now accepts a callable filter `(str) -> bool` as the name parameter, matching the HookedTransformer API. When a callable is passed, the hook is added to every hook point whose name satisfies the filter. This was already supported in run_with_hooks() but missing from add_hook(), causing AttributeError when migrating notebooks that use filter-based hook registration.
ca9c2ed to
459d568
Compare
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
add_hooksfunctionality had the necessary wiring to exist in TransformerBridge, but was not properly configured to be usable.-TransformerBridge.add_hook()now accepts a callable filter(str) -> boolas thenameparameter, matching theHookedTransformer` APIrun_with_hooks()but missing fromadd_hook(), causingAttributeErrorwhen migrating notebooks that use filter-based hook registration (e.g. Attribution Patching Demo)Type of change
Checklist: