Skip to content

Remove dead _last_input_before_norm write in NormalizationBridge#1528

Merged
jlarson4 merged 1 commit into
TransformerLensOrg:devfrom
Hetens:remove-dead-norm-attr
Jul 22, 2026
Merged

Remove dead _last_input_before_norm write in NormalizationBridge#1528
jlarson4 merged 1 commit into
TransformerLensOrg:devfrom
Hetens:remove-dead-norm-attr

Conversation

@Hetens

@Hetens Hetens commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Description

Dead-code cleanup split out of #1526 per maintainer request there (the bug fix itself is #1527, based on main).

NormalizationBridge.forward wrote self._last_input_before_norm = hidden_states on every call, but nothing in the repo has read that attribute since the #1129 cleanup. The write pins one [batch, seq, d_model] activation per norm module between forwards, and when the input has requires_grad=True it also keeps the upstream autograd graph alive, which is real memory overhead for anyone training through the bridge.

One-line deletion; a repo-wide grep confirms no remaining references. Note for merge ordering: #1527 touches the surrounding lines on main, so whichever lands second may need a trivial rebase when main syncs into dev. Happy to handle that.

The second observation from #1526 (the layer_norm_folding config flag is never set True anywhere, so its branch in forward appears unreachable) is deliberately NOT touched here: removing a public config field or its branch is a design decision I'd rather leave to maintainers.

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

Notes on the checklist:

  • Tests: none added; this deletes an attribute that nothing reads, so there is no behavior to pin. tests/unit/model_bridge/generalized_components/ passes locally (161 passed).
  • Docs: the attribute was never documented.

Drafted with the assistance of Claude (Anthropic's AI assistant), working under my direction.

Written on every forward but never read anywhere in the repo since TransformerLensOrg#1129;
pins one [batch, seq, d_model] activation (and, when requires_grad, its
upstream autograd graph) per norm module between forwards. Noted in TransformerLensOrg#1526.
@Hetens

Hetens commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

Quick note @jlarson4: fixed this one with Claude's help as well; it's a one-line cleanup rather than part of the patch-release fix (#1527), which is why it targets dev.

@jlarson4

Copy link
Copy Markdown
Collaborator

Looks good, thanks @Hetens!

@jlarson4
jlarson4 merged commit c86989f into TransformerLensOrg:dev Jul 22, 2026
25 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.

2 participants