Skip to content

Support callable filters in TransformerBridge.add_hook()#1186

Merged
jlarson4 merged 1 commit intodev-3.x-canaryfrom
bug/add_hook_callable_filter
Feb 27, 2026
Merged

Support callable filters in TransformerBridge.add_hook()#1186
jlarson4 merged 1 commit intodev-3.x-canaryfrom
bug/add_hook_callable_filter

Conversation

@jlarson4
Copy link
Collaborator

@jlarson4 jlarson4 commented Feb 27, 2026

Description

add_hooks functionality 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` 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 (e.g. Attribution Patching Demo)
  • Adds 4 regression tests covering forward/backward callable filters, string names, and empty matches

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have not rewritten tests relating to key interfaces which would affect backward compatibility

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.
@jlarson4 jlarson4 force-pushed the bug/add_hook_callable_filter branch from ca9c2ed to 459d568 Compare February 27, 2026 18:29
@jlarson4 jlarson4 merged commit 4df137c into dev-3.x-canary Feb 27, 2026
29 of 30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant