code wiki / (root) / nx_f32_rope.nx

nx_f32_rope.nx

buildroot/runtime/nx_f32_rope.nx

7719 B186 linesdepth 5pulls 8 transitivereach 70 importersview sourcekind librarytopic f32
docsdependenciesstructsconstsfunctions

about

nx_f32_rope.nx -- bits-up f32 RoPE (Rotary Position Embedding). L7 composition brick. Composes L6 sin + cos + exp + L4 mul/add/ sub/div/cvt. No libm. Reference (Su 2021, "RoFormer"): For each adjacent dim-pair (x_{2i}, x_{2i+1}) at position m: theta_i = base^(-2i/d) [x'_{2i}, x'_{2i+1}] = R(m*theta_i) @ [x_{2i}, x_{2i+1}] where R(phi) is the 2x2 rotation matrix [[cos,-sin],[sin,cos]]. Concretely: x'_{2i} = x_{2i} * cos(m*theta_i) - x_{2i+1} * sin(m*theta_i) x'_{2i+1} = x_{2i} * sin(m*theta_i) + x_{2i+1} * cos(m*theta_i) base is typically 10000 (Llama-2) or 500000 (Llama-3 / Qwen2). Caller passes log(base) as f32 so it's computed once across all positions. log(10000) ~= 9.2103404 = 0x4113411D in f32 nearest. genealogy_id: su_2021_rope + standard_rotation_compose lineage_id: substrate_f32_rope_v1

dependencies 7 imports · 8 importers

nx_syscalls.nx nx_tier.nx nx_f32.nx nx_f32_div.nx nx_f32_cvt.nx nx_f32_exp.nx nx_f32_sincos.nx nx_f32_rope.nx nx_f32_llama_block.nx nx_f32_llama_block_test.nx nx_f32_llama_block_v4.nx nx_f32_llama_block_v4_test.nx nx_f32_llama_v4b.nx nx_f32_llama_v4p.nx nx_f32_rope_test.nx nx_nofloat_qwen_rope_h2h_gate.nx

imports: nx_syscalls.nxnx_tier.nxnx_f32.nxnx_f32_div.nxnx_f32_cvt.nxnx_f32_exp.nxnx_f32_sincos.nx

imported by: nx_f32_llama_block.nxnx_f32_llama_block_test.nxnx_f32_llama_block_v4.nxnx_f32_llama_block_v4_test.nxnx_f32_llama_v4b.nxnx_f32_llama_v4p.nxnx_f32_rope_test.nxnx_nofloat_qwen_rope_h2h_gate.nx

structs

none

consts

32const NX_F32_ROPE_OK: nx_int = 0
33const NX_F32_ROPE_ERR_BAD_DIM: nx_int = 1
34const NX_F32_ROPE_ERR_ODD_DIM: nx_int = 2
35const NX_F32_ROPE_N_VERDICTS: nx_int = 3

functions

37func nx_f32_rope_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
51func nx_f32_rope_apply_vector(x: *i64, head_dim: nx_int,
106func nx_f32_rope_build_cs(cs_out: *i64, head_dim: nx_int,
130func nx_f32_rope_apply_cs_neox(x: *i64, head_dim: nx_int, cs: *i64) -> nx_int
155func nx_f32_rope_apply_vector_neox(x: *i64, head_dim: nx_int,