Skip to content

Fix direct TransformerBridge config flag assignment - #1709

Merged
jlarson4 merged 3 commits into
TransformerLensOrg:devfrom
emerardd:fix/bridge-config-flag-assignment
Aug 21, 2026
Merged

Fix direct TransformerBridge config flag assignment#1709
jlarson4 merged 3 commits into
TransformerLensOrg:devfrom
emerardd:fix/bridge-config-flag-assignment

Conversation

@emerardd

Copy link
Copy Markdown
Contributor

Description

Fixes #1689.

Direct assignment to bridge.cfg.use_attn_result, use_attn_in, use_hook_mlp_in, or use_split_qkv_input previously updated only the top-level config and silently left the constructed block components unchanged.

This change:

  • binds a live TransformerBridgeConfig to its bridge through a weak reference;
  • routes direct assignments for the four managed flags through the existing public setters, preserving propagation, mutual-exclusivity checks, and unsupported-architecture validation;
  • keeps standalone/deep-copied configs unbound and rebinds deep-copied or deserialized bridges to their own config;
  • updates the migration guide to document direct-assignment parity;
  • adds regression coverage for hook behavior, validation, and deepcopy isolation.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • This change requires a documentation update

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

Testing

  • Complete unit-test suite passes locally.
  • Direct-assignment regression tests pass for all four managed flags.
  • Formatting and uv run mypy . pass.

@koriyoshi2041 koriyoshi2041 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified at f10b46ea41. Direct assignments for all four managed flags take the same setter path without recursion, and deepcopy leaves standalone configs unbound while rebinding copied bridges. The focused regression passes locally (10/10 on Python 3.13); the CI-only left-padding failure also passes twice at this head and is outside the changed surface.

@jlarson4 jlarson4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for putting this together, @emerardd, routing assignment through the setters via a weakref, and keeping copies unbound with __getstate__/__setstate__ is a clean way to solve this issue. A couple small comments, let me know if you have any questions.

Comment thread transformer_lens/model_bridge/bridge.py
Comment thread transformer_lens/model_bridge/bridge.py
Comment thread tests/unit/model_bridge/test_config_flag_assignment.py Outdated

@jlarson4 jlarson4 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing these updates @emerardd! one small comment related to config reuse, and one documentation request, and then this should be good to go.

Comment thread transformer_lens/config/transformer_bridge_config.py
Comment thread transformer_lens/model_bridge/bridge.py
@jlarson4

Copy link
Copy Markdown
Collaborator

Thanks for the quick turn around @emerardd! Assuming CI passes, this is approved and will be merged!

@jlarson4
jlarson4 merged commit 2fbcb1e into TransformerLensOrg:dev Aug 21, 2026
69 of 75 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.

[Bug Report] Assigning cfg.use_attn_result / use_hook_mlp_in / use_split_qkv_input directly is silently ignored

3 participants