Skip to content

fix: register unmapped leaf parameters so module conversions reach them - #1940

Merged
jlarson4 merged 1 commit into
TransformerLensOrg:devfrom
tivris:fix-unmapped-leaf-params
Oct 22, 2026
Merged

jlarson4 merged 1 commit into
TransformerLensOrg:devfrom
tivris:fix-unmapped-leaf-params

Conversation

@tivris

@tivris tivris commented Oct 22, 2026

Copy link
Copy Markdown

Description

Fixes #1935.

_register_unowned_container_state registered unmapped buffers of every module, but unmapped parameters only of modules with children. The per-layer embedding modules on Gemma 4 E2B/E4B and Gemma 3n and the AltUp projections on Gemma 3n are unmapped leaves, so .half() and the other nn.Module._apply conversions, conversions of a parent module, and parent.parameters() missed their weights.

The children check is gone, so unmapped parameters get the same owner views as unmapped buffers. This also reaches the unmapped multimodal modules: the audio tower on Gemma 4 E2B/E4B, the audio and vision towers on Gemma 3n, the vision tower on T5Gemma2 and the VQ tokenizer on Emu3. bridge.state_dict() keys and hooks are unchanged; parent.state_dict() gains _container_state_owners.* keys for the newly reachable parameters. As noted in #1935, test_parent_and_direct_traversal_have_identical_state no longer flags an adapter that leaves a leaf module unmapped.

test_parent_module_traversal.py gains two Gemma 4 cases (per-layer embeddings, and the audio and vision towers) and test_dtype_conversion_updates_unmapped_leaf_parameters for bridge.half() and parent.to(torch.float16); test_gemma3n_bridge.py gains test_half_converts_unmapped_parameters. All five fail on dev and pass with the fix.

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

@jlarson4

Copy link
Copy Markdown
Collaborator

Looks good, merging now!

@jlarson4
jlarson4 merged commit 883571a into TransformerLensOrg:dev Oct 22, 2026
29 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] .half() and parent-module conversions skip some Gemma 4 E2B/E4B and Gemma 3n weights

2 participants