code wiki / _hdl_build / nx_nofloat_rope_gate.nx

nx_nofloat_rope_gate.nx

buildroot/runtime/_hdl_build/nx_nofloat_rope_gate.nx

10286 B186 linesdepth 3pulls 4 transitivereach 0 importersview sourcekind gate/prooftopic nofloat
docsdependenciesstructsconstsfunctions

about

nx_nofloat_rope_gate.nx -- HARD-EVIDENCE gate for RoPE (rotary position embedding) backward + RoPE composed into the attention path. Advances CAP-NF-ATTN-FULL: with RoPE the attention is positionally-aware AND still fully differentiable in pure integer Q16. RoPE is parameter-free (orthogonal rotation), so its backward is the inverse rotation -- here proven correct by finite differences AND inside the full attention block. A1 RoPE gradcheck : loss=mse(RoPE(x), t); tape grad dL/dx == central finite difference. A2 attention+RoPE gradcheck: X->{Q,K,V}; RoPE(Q),RoPE(K); S=QK^T; scale; causal softmax; O=A.V; mse; gradcheck dL/dWq -- the gradient flowing through RoPE + softmax + both matmuls (the real RoPE-attn backward). D neg-control teeth : a wrong RoPE grad is rejected. C bit-exact : the attention+RoPE gradient is identical across two runs (determinism). Evidence -> knowledge/status/nofloat_rope.log. Sovereign: imports nx_nofloat_autograd (pure integer) + nx_syscalls. HONEST scope: single-head; output-projection + multi-head/GQA remain (bookkeeping over matmul+vadd). expect_exit: 0

dependencies 3 imports · 0 importers

nx_nofloat_autograd.nx nx_syscalls.nx nx_gate_emit_lib.nx nx_nofloat_rope_gate.nx

imports: nx_nofloat_autograd.nxnx_syscalls.nxnx_gate_emit_lib.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main g_puts sys_write sys_mmap rope_loss nfa_leaf nfa_new nfa_rope nfa_new ↻ nfa_fxexp nfa_cosf nfa_reduce2pi nfa_cosq nfa_qmul nfa_sinf nfa_reduce2pi ↻ nfa_sinq nfa_qmul ↻ nfa_qmul ↻ nfa_mse nfa_new ↻ nfa_backward nfa_qmul ↻ nfa_silud nfa_sigmoid nfa_fxexp ↻ nfa_qmul ↻ nfa_isqrt nfa_fxexp ↻ nfa_cosf ↻ nfa_sinf ↻ nfa_grad rope_lossval sys_mmap ↻ rope_loss ↻ nfa_val g_abs g_pn sys_mmap ↻ sys_write ↻

structs

none

consts

18const RLOG: *u8 = "knowledge/status/nofloat_rope.log"
19const Q16: i64 = 65536

functions

22func g_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v }
called by 1: main
23func r_ws(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 }
called by 1: main calls 1: sys_write
24func r_wn(fd: i64, v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(fd,"-" as *u8,1);m=0-m} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(fd,b,k); return 0 }
called by 1: main calls 2: sys_mmapsys_write
27func rope_loss(tape: *i64, vals: *i64, st: *i64, Xs: *i64, T: i64, hd: i64, Ts: *i64, leaves: *i64) -> i64
36func rope_lossval(tape: *i64, vals: *i64, st: *i64, Xs: *i64, T: i64, hd: i64, Ts: *i64) -> i64
called by 1: main calls 3: sys_mmaprope_lossnfa_val
43func ar_fwd(tape: *i64, vals: *i64, st: *i64, Xs: *i64, Wqs: *i64, Wks: *i64, Wvs: *i64, T: i64, d: i64, scale: i64, leaves: *i64) -> i64
61func ar_loss(tape: *i64, vals: *i64, st: *i64, Xs: *i64, Wqs: *i64, Wks: *i64, Wvs: *i64, Ts: *i64, T: i64, d: i64, scale: i64, leaves: *i64) -> i64
66func ar_lossval(tape: *i64, vals: *i64, st: *i64, Xs: *i64, Wqs: *i64, Wks: *i64, Wvs: *i64, Ts: *i64, T: i64, d: i64, scale: i64) -> i64
called by 1: main calls 3: sys_mmapar_lossnfa_val
72func main() -> i64