rope: the head ladder rotates the whole head, as HF's proportional RoPE

ladder=head kept the rotary_dim-wide pairing: pair i = (i, i + rotary_dim/2). HF's proportional
RoPE (and vLLM's Gemma4RotaryEmbedding) rotates the whole head: inv_freq has head_dim/2 entries,
the first rotary_dim/2 of them 1 / theta^(2i/head_dim) and the rest zero, so pair i is
(i, i + head_dim/2). On Gemma 4's global layers (128 of 512) the old pairing turned channels
64..127 and left 256..319 alone.

rope in libr4d, libref and libavx now rotates the whole head under ladder=head, with the
frequencies past rotary_dim/2 at zero. The rotary ladder is unchanged. op_rope_ladder and the
r4d_selftest mirror check the HF pairing.
This commit is contained in:
keptn42 authored and sfjes committed 2026-10-10 08:08:43 -07:00
1 parent 921b02b60b
commit c045ff85e9
5 files changed
+48 -13

No files matched your search

+2 -1
View File
@@ -4634,7 +4634,8 @@ static void rope_ladder_case(const Plugin& pl) {
for (int64_t h = 0; h < n_rope; ++h) {
for (int64_t i = 0; i < half; ++i) {
const size_t i0 = base + (size_t)h * hd + i;
const size_t i1 = i0 + half;
/* `head` is HF's proportional RoPE: pair i is (i, i + head_dim/2). */
const size_t i1 = i0 + ((lad && !std::strcmp(lad, "head")) ? hd / 2 : half);
const float x0 = h_bf16(saved[(size_t)i0]), x1 = h_bf16(saved[(size_t)i1]);
const float inv = 1.0f / powf(theta, (float)(2 * i) / (float)den);
float s, c;