nx_gen_rope_verify.nx
buildroot/runtime/nx_gen_rope_verify.nx
about
nx_gen_rope_verify.nx -- SOVEREIGN interleaved RoPE, verified vs the oracle.
y[h][l][2j+r] = x[l][h][2j] * pe[l][j][r][0] + x[l][h][2j+1] * pe[l][j][r][1]
pe holds a 2x2 rotation per (token l, pair j): [[cos, -sin], [sin, cos]], so r=0 gives
x0*cos - x1*sin and r=1 gives x0*sin + x1*cos -- ordinary interleaved rotary embedding.
Derived from rope.hpp's apply_rope (permute/reshape/repeat chain), not assumed.
Usage: nx_gen_rope_verify <model> <x> <pe> <y> <head_dim> <n_heads> [rows]
⚠THE AXIS PERMUTATION IS THE WHOLE DIFFICULTY, and it is silent when wrong:
input x is [head_dim, n_heads, L] -> index (l*n_heads + h)*head_dim + d
output y is [head_dim, L, n_heads] -> index (h*L + l)*head_dim + d
apply_rope permutes head and token axes. Reading either side in the other's order produces
finite, plausible, entirely wrong numbers -- no NaN, no crash, just a silently different
tensor. Both strides are therefore written out explicitly here rather than shared.
pe memory index: ((l*(head_dim/2) + j)*2 + r)*2 + c -- ne = [2, 2, head_dim/2, L]
Hardware __f32_* intrinsics in the hot loop, never the nx_f32_* software twins.
license_tier: ORIGINAL
dependencies 8 imports · 0 importers
imports: nx_syscalls.nxnx_le.nxnx_f32.nxnx_f32_div.nxnx_f32_cvt.nxnx_strconv.nxnx_genfix.nxnx_genver.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| none |
functions
| 32 | func zrp_strlen(s: *u8) -> i64 called by 1: main |
| 38 | func main(argc: i64, argv: *i64) -> i64 |