Repository navigation
RoPE reads its angles from a table, and the backward rotation folds into the join (#88) - #89
Merged
Merged
Conversation
Owner
Author
|
Note on the shas: both branches were |
This was referenced Aug 5, 2026
Owner
Author
|
Cross-check at unthrottled clocks (standalone
The forward rotations at 2.55 ms against 8.53 is the table on its own: same bytes, 3.3× the rate, and the difference is that the angles left the inner loop. #90 then removes even that. |
This was referenced Aug 5, 2026
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.
Phase 1 of #88.
RoPE's angles depend only on
(position, pair)—T × HDfloats, 1 MiB at the training shape — and the kernel recomputed apowf, asinand acosfor every element of every rotated tensor. Two threads redid the same angle for the two halves of one rotated pair, and each loaded both halves, so the pass also moved twice its compulsory reads.bench_rope's own comment had named this in #70; nothing had moved the angles out of the inner loop.The table.
ops::rope_table(sequence_length, head_dim)builds the[T, HD/2](cos, sin)couples on the host, withnn::Rope::sin_cos's expression verbatim. That is the point of building it host-side: the CPU reference and every device consumer now share one set of angles instead of comparing libdevice'ssinfagainst the host's. It is uploaded once per workspace and read from L2 — 1 MiB against a 126 MiB L2, re-readN·H/Ttimes.The rotations.
rope_forward/rope_backwardbecome one thread per rotated pair: two loads, two table loads, four multiplies, two stores. Launches go fromN·Dthreads toN·D/2.The backward join.
join_group3_ropefolds the transposed rotation into the join that was already reading dQ/dK/dV and writing the[N,3D]panel, so the twobackward.*_ropepasses disappear rather than getting faster. The arithmetic isrope_backward's, elementwise and fp32, so the substitution owes exact parity and--kernel opsasserts it at zero tolerance againstrope_backward+join_group3run on device.Measurement
Same-container A/B,
BASELINE_REF=ea8e147 ./run.sh model profile, §13.9 shape. (The container this pair landed on runs the tcgen05 expert GEMMs 3–6× slower than a clean one — its absolute step is 838 ms where a standalone profile of the same baseline commit read 401.8 ms. Both halves saw it, which is what the same-container rule is for; the bandwidth-bound rows below are within 7% of their standalone values either way.)backward.q_ropebackward.k_ropeforward.q_ropeforward.k_ropebackward.qkv_proj.joinRows touched sum to −29.03 against a −26.42 step; the difference is three expert-GEMM rows drifting +0.50 / +0.60 / +0.64, which is this pair's noise floor and nothing this change goes near.
The forward rotations are 3.1× faster on the same bytes. The join is faster than the plain join it replaces (−2.24 ms) despite carrying the rotation: one thread per pair means half the threads and 8-byte accesses where the old join had one thread per element.
Standalone-baseline framing, since the A/B container understates the percentage: against the 401.81 ms profile of
ea8e147, −29 ms of rope rows is −7.2% of the step.Gates
--kernel ops— green, including the new zero-tolerancejoin_group3_ropevsrope_backward+join_group3check and the existingrope y/rope dxchecks againstnn::Ropeat 2e-6.--kernel model— green (full Dense forward/backward + AdamW, Muon, both MoE substitutions, aligned tcgen05 linears, checkpoint v5, all overfit gates).--kernel gemm; no flash kernel touched, so no budget moves.Notes
rope_backwardkeeps its kernel and its parity check: it is the oraclejoin_group3_ropeis tested against (§11 — the naive kernels are never deleted).rope_intolost itsbackwardarm because the model no longer has a caller for it.