Skip to content

Fix RoPE broadcast mismatch in apply_rope - #87

Open
helpdeskdcp wants to merge 1 commit into
kyegomez:mainfrom
helpdeskdcp:fix-rope-slicing
Open

helpdeskdcp wants to merge 1 commit into
kyegomez:mainfrom
helpdeskdcp:fix-rope-slicing

Conversation

@helpdeskdcp

Copy link
Copy Markdown

Summary

  • apply_rope() no longer sliced freqs_cis to the input's sequence length T internally — that slicing was removed in 18cca89 when start_pos offsetting was moved to OpenMythos.forward, which now pre-slices freqs_cis to exactly T rows before calling down into layers.
  • That's fine for the top-level model path, but GQAttention/MLAttention/TransformerBlock/RecurrentBlock unit tests call the attention modules directly with the full, unsliced max_seq_len-length freqs table, causing RuntimeError: The size of tensor a (8) must match the size of tensor b (32) at the RoPE broadcast multiply.
  • Restored freqs_cis = freqs_cis[: x.shape[1]] inside apply_rope, which is a no-op when the caller already passes an exactly-T-length window (preserving the 18cca89 decode-position fix) and correctly truncates when a longer table is passed directly.

Test plan

  • .venv/bin/python -m pytest -q — before: 62 passed, 14 failed; after: 75 passed, 1 failed
  • Focused rerun of RoPE/GQAttention/MLAttention/TransformerBlock/RecurrentBlock tests: 32 passed
  • Remaining failure (TestLTIInjection::test_spectral_radius_stable_after_large_grad_step) confirmed pre-existing and flaky/non-deterministic (no seed set), unrelated to this change — reproduced fail/pass/fail across 3 standalone reruns on main before this fix.

🤖 Generated with Claude Code

apply_rope no longer sliced freqs_cis to x's sequence length internally
(removed in 18cca89 when start_pos offsetting was added at the top-level
OpenMythos.forward). That top-level caller already pre-slices freqs_cis
to exactly T rows via [start_pos:start_pos+T], so the change is a no-op
there. But GQAttention/MLAttention/TransformerBlock/RecurrentBlock unit
tests call the attention modules directly with the full, unsliced
max_seq_len-length freqs table, causing a broadcast mismatch (e.g. T=8
vs max_seq_len=32). Restoring the internal freqs_cis[:T] slice fixes
both call paths since it is idempotent when the input is already
exactly T rows long.
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.

1 participant