code wiki / _hdl_build / nx_intfp_block_gradcheck_gate.nx

nx_intfp_block_gradcheck_gate.nx

buildroot/runtime/_hdl_build/nx_intfp_block_gradcheck_gate.nx

12300 B165 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind gate/prooftopic intfp
docsdependenciesstructsconstsfunctions

about

nx_intfp_block_gradcheck_gate.nx -- CAPSTONE assembly pattern: a pre-norm residual block y = x + Attn(RMSNorm(x)) with the FULL end-to-end integer backward, validating the two NEW assembly risks the isolated gates didn't cover: (1) INPUT-gradient propagation dX through a sublayer (attention dh), and (2) RESIDUAL gradient accumulation (dx = dx_residual + dx_norm-path). Gradchecked (integer finite-diff, max-|grad| metric) on gamma, Wq, Wv AND the input X (which flows through BOTH the residual and the norm->attention path), then TRAINED (loss drops). If this holds, the full transformer layer is the same pattern twice (attn block + FFN block). Q20 integer, no float. Ptr-array plumbing to fit arg budget. slots: 0x 1gamma 2Wq 3Wk 4Wv 5Y | 6h 7Q 8K 9V 10A 11O 12y 13rms | 14dgamma 15dWq 16dWk 17dWv 18dX license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_intfp_block_gradcheck_gate.

imports: nx_syscalls.nx

imported by: nobody (leaf or entry point)

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

main w sys_write sys_mmap block_fwd isqrt fp_exp block_bwd sys_mmap ↻ wn sys_write ↻ sys_mmap ↻ gcheck iabs block_fwd ↻ w ↻ wn ↻

structs

none

consts

16const S: i64 = 1048576 // Q20
17const T: i64 = 3
18const DM: i64 = 4
19const SCALE: i64 = 524288 // 1/sqrt(4)=0.5
20const EPS: i64 = 1048576 // eps in Q40 (tiny vs ms)

functions

12func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 2: gcheckmain calls 1: sys_write
13func wn(v: i64) -> i64 { if v==0 { sys_write(1,"0" as *u8,1); return 0 } var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} let t: *u8=sys_mmap(24); var k: i64=0; while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} let o: *u8=sys_mmap(24); var q: i64=k-1; var i: i64=0; while q>=0{o[i]=t[q];i=i+1;q=q-1} sys_write(1,o,i); return 0 }
called by 2: gcheckmain calls 2: sys_writesys_mmap
14func iabs(v: i64) -> i64 { if v<0 { return 0-v } return v }
called by 1: gcheck
22func isqrt(n: i64) -> i64
called by 1: block_fwd
29func fp_exp(xq: i64) -> i64
called by 1: block_fwd
42func block_fwd(P: *i64) -> i64
called by 2: gcheckmain calls 2: isqrtfp_exp
67func block_bwd(P: *i64) -> i64
called by 1: main calls 1: sys_mmap
103func gcheck(name: *u8, P: *i64, tgtslot: i64, dW: *i64, ncell: i64) -> i64
called by 1: main calls 4: iabsblock_fwdwwn
122func main() -> i64