Fix gated Qwen W_Q analysis weights - #1653
Merged
Merged
Conversation
Collaborator
|
Looks good, great resolution for this issue @emerardd! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #1652.
Qwen3.5 and Qwen3Next use a gated query projection whose rows are interleaved as query and gate values within each head.
TransformerBridge.W_Qpreviously exposed the complete projection as if every row belonged to the query, so its final dimension was2 * cfg.d_head. Weight-space analyses such as composition scores, QK analysis, and SVD therefore consumed query-plus-gate data under a query-only interface.The adapters attempted to remove the gate rows in
preprocess_weights(), but that helper matched Hugging Face-style keys while the real processing path supplies TransformerLens-style state-dict keys. More importantly, preprocessing the parameter would mutate the live projection and remove the gate needed by the model forward.This change:
AttentionBridge.W_Qreturn a query-only per-head view whengated_q_projis enabled;hook_q_gate;build_bridge_from_module()andprocess_weights();W_Qshape, forward parity, gate-hook behavior, live-weight preservation, ordinary Qwen3 as a control, and the multimodal adapter's shared gated-query contract.No new dependencies are required.
Type of change
Screenshots
Not applicable.
Checklist:
Validation
5260 passed, 55 skipped, 54 deselected, 10 xfailed146 passed5 passedpycln,isort, and Black passSuccess: no issues found in 431 source filesgit diff --checkpasses