Skip to content

Drop optional unused aliases on hybrid architectures - #1579

Open
KYinXu wants to merge 1 commit into
TransformerLensOrg:devfrom
KYinXu:fix/gdn-adaptation
Open

Drop optional unused aliases on hybrid architectures#1579
KYinXu wants to merge 1 commit into
TransformerLensOrg:devfrom
KYinXu:fix/gdn-adaptation

Conversation

@KYinXu

@KYinXu KYinXu commented Jul 31, 2026

Copy link
Copy Markdown

Description

When hybrid layers skip an optional submodule (e.g. attn on GDN / Mamba-2 layers), the shared BlockBridge template still declared HT aliases like hook_attn_out → attn.hook_out. _register_aliases then failed to resolve them and emitted a harmless warning per hybrid layer (notably when loading Qwen3.5; see also #1547).

This PR prunes those inapplicable aliases in setup_submodules when an optional submodule is skipped—per layer, so full-attention siblings keep their HT aliases and real unresolved-alias bugs still warn. Unit tests cover prune behavior and no warning on register. The Jacobian Lens Qwen3.5 demo cell is updated now that boot no longer expects that stderr.

Fixes #1578

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Screenshots

Warnings no longer appear

image

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

@KYinXu KYinXu changed the title Drop optional unused aliases Drop optional unused aliases on hybrid architectures Jul 31, 2026

@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.

Nice, tightly-scoped fix @KYinXu!

A couple small requests before merging, detailed below



def _prune_hook_aliases_for_skipped(component: GeneralizedComponent, skipped: list[str]) -> None:
"""Drop hook aliases whose target path starts at a skipped optional submodule.

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.

The prune fires for every optional skip across 12 architectures, including native SSM aliases on nemotron_h/zamba2. Can we update the docstring to be more general, and add one non-attn test case?

to_drop.append(alias_name)
elif len(kept) != len(target):
aliases[alias_name] = kept
elif _first_segment(target) in skipped_set:

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.

On OLMo-Hybrid, BlockBridge retargets hook_mlp_out onto the optional ln2_post (block.py:78), so this branch drops it on linear-attention layers that do have an mlp, and removes the warning that flagged it. Can the prune keep aliases with a live fallback target?

assert "hook_resid_pre" in blocks[3].hook_aliases
assert "hook_mlp_out" in blocks[3].hook_aliases

def test_pruned_aliases_do_not_warn_on_register(self):

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.

Both new tests call _register_aliases() directly, so nothing asserts a hybrid bridge booting warning-free through TransformerBridge.__init__. Can you add a boot-level assertion using the config-only tiny-bridge fixture in test_qwen3_5_adapter.py:562?

with warnings.catch_warnings(record=True) as caught:
warnings.simplefilter("always")
blocks[3]._register_aliases()
unresolved = [

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.

AttnAdapter declares no ln2/mlp, so block 3 still emits two legitimate unresolved warnings. This forces the substring filter instead of asserting the list is empty. Can the fixture carry those submodules so the assertion can be unconditional?

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.

[Proposal] Hybrid architectures warn on unresolved optional 'hook_attn' aliases when they are skipped

2 participants