Repository navigation
fix: bridge XGLM's sinusoidal position embedding as pos_embed - #2008
Merged
Merged
Conversation
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
XGLM adds a sinusoidal position table to the scaled token embedding before the first block:
The adapter did not bridge
model.embed_positions. There was nohook_pos_embed, sohook_embed != blocks.0.hook_resid_pre, and every residual decomposition missed the positional term. On a tiny random XGLM (3 layers), the max abs error of each sum against the residual stream, relative to its max abs value:devdecompose_resid()(every layer)get_full_resid_decomposition()(with and without neurons)hook_embed + hook_pos_embedvsblocks.0.hook_resid_prehook_pos_embedFix. Bridge
model.embed_positionsaspos_embedwith the existingPosEmbedBridge. It already handles sinusoidal modules that keep their table in aweightsbuffer (as on M2M100), soW_posis the table, and HF's(position_ids, past_key_values_length)call passes through unchanged. Logits, compatibility mode and greedygeneratestill match HF.supports_center_writing_weightsstaysFalse: the table is a non-persistent buffer, not a weight.Type of change
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
New
tests/integration/model_bridge/test_xglm_pos_embed.pybuilds a tiny randomXGLMForCausalLMlocally and checks that:hook_embed + hook_pos_embed == blocks.0.hook_resid_pre;hook_pos_embedis the offset sinusoidal table, andW_posis the table;decompose_residsums to the residual stream at every layer;get_full_resid_decompositionsums to the final residual stream and has apos_embedrow;generatematches HF.test_xglm_adapter.py: the top-level mapping now includespos_embed, aPosEmbedBridgeonmodel.embed_positions.On
dev, 10 of these tests fail.Local runs (Windows, CPU, torch 2.9.1, transformers 5.20.2,
--jaxtyping-packages=transformer_lens,beartype.beartype,PYTHONUTF8=1):test_symbolic_bridge_hooks.py, the XGLM case oftest_inspect_provider.py): pass; the inspect one skips withoutinspect_ai.tests/unit -m "not slow": 8174 passed, 14 failed. The same 14 fail ondevin my environment (ten Gemma 3n adapter tests need the optionaltimm, threetest_sparse_probing.pytests check optimizer stop reasons, andtest_faithfulness_recovery_is_graded_not_binaryis [Bug Report] test_faithfulness_recovery_is_graded_not_binary passes or fails on the sign of float32 rounding #1993).black(the locked 23.12.1),isort --check-onlyandmypyon the changed files pass.This was prepared with AI assistance (Claude); I reviewed and tested the change.