code wiki / _hdl_build / nx_f32_qwen2_train_gate.nx

nx_f32_qwen2_train_gate.nx

buildroot/runtime/_hdl_build/nx_f32_qwen2_train_gate.nx

28181 B324 linesdepth 6pulls 17 transitivereach 0 importersview sourcekind gate/prooftopic f32
docsdependenciesstructsconstsfunctions

dependencies 4 imports · 0 importers

nx_gate_gn.nx nx_gate_base.nx nx_autograd_tensor.nx nx_syscalls.nx nx_f32_qwen2_train_gate.nx

imports: nx_gate_gn.nxnx_gate_base.nxnx_autograd_tensor.nxnx_syscalls.nx

imported by: nobody (leaf or entry point)

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

main gw sys_write nx_i32_to_f32 nx_f32_div nx_f32_classify nx_f32_exp_field nx_f32_mant_field nx_f32_sign nx_f32_mant_field ↻ nx_f32_exp_field ↻ f32_sqrtx nx_i32_to_f32 ↻ nx_f32_div ↻ nx_f32_add nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_mant_field ↻ nx_f32_exp_field ↻ sys_mmap gn det_fill f32c nx_f32_div ↻ nx_i32_to_f32 ↻ LB build_rope nx_f32_log nx_f32_classify ↻ nx_f32_sign ↻ nx_f32_exp_field ↻ nx_f32_mant_field ↻ nx_f32_sub nx_f32_add ↻ nx_f32_neg nx_f32_add ↻ nx_f32_div ↻ nx_f32_mul nx_f32_classify ↻ nx_f32_sign ↻

structs

none

consts

15const VMAX: i64 = 40
16const DM: i64 = 16 // perfect square -> trainer 1/sqrt(16)=0.25 EXACTLY equals inference 65536/isqrt(16)
17const HF: i64 = 32
18const NLAYERS: i64 = 2
19const TMAX: i64 = 64
20const EPOCHS: i64 = 1800
21const NODES: i64 = 220
22const CELLS: i64 = 300000

functions

24func grow(name: *u8, ok: i64) -> i64 { if ok==1 { gw(" PASS " as *u8) } else { gw(" FAIL " as *u8) } gw(name); gw("
calls 1: gw
26func gm(x: i64) -> i64 { return gn(ta_f32_to_milli(x)) }
27func f32c(a: i64, b: i64) -> i64 { return nx_f32_div(nx_i32_to_f32(a), nx_i32_to_f32(b)) }
called by 1: main
28func f32_absx(x: i64) -> i64 { return x & 0x7FFFFFFF }
called by 1: main calls 1: nx_f32_gt
29func f32_lex(x: i64, y: i64) -> i64 { if nx_f32_gt(x,y)==1 { return 0 } return 1 }
30func f32_sqrtx(x: i64) -> i64 { if (x & 0x7FFFFFFF)==0 { return nx_i32_to_f32(0) } var y: i64=x; var i: i64=0; while i<16 { y=nx_f32_div(nx_f32_add(y, nx_f32_div(x,y)), nx_i32_to_f32(2)); i=i+1 } return y }
33func build_rope(COS: *i64, SIN: *i64, ROT: *i64) -> i64
45func rope_node(tape: *i64, vals: *i64, st: *i64, xn: i64, COSn: i64, SINn: i64, ROTn: i64) -> i64
49func tile_leaf(tape: *i64, vals: *i64, st: *i64, param: *i64, T: i64, width: i64, scratch: *i64) -> i64
54func reduce_tiled(tape: *i64, grads: *i64, node: i64, T: i64, width: i64, dst: *i64) -> i64
61func rmsnorm_gamma(tape: *i64, vals: *i64, st: *i64, x: i64, gamma: *i64, T: i64, scratch: *i64, gv: *i64, gi: i64) -> i64
69func LB(L: i64) -> i64 { return 3+L*13 }
71func build_fwd(tape: *i64, vals: *i64, st: *i64, M: *i64, toks: *i64, T: i64, vv: i64, scale: i64, Xsrc: *i64, COS: *i64, SIN: *i64, ROT: *i64, tsc: *i64, lv: *i64, gv: *i64, bvn: *i64) -> i64
105func loss_of(tape: *i64, vals: *i64, M: *i64, toks: *i64, tgt: *i64, T: i64, vv: i64, scale: i64, Xsrc: *i64, COS: *i64, SIN: *i64, ROT: *i64, tsc: *i64, lv: *i64, gv: *i64, bvn: *i64) -> i64
110func det_fill(dst: *i64, n: i64, seed: i64) -> i64 { var i: i64=0; while i<n { let s: i64=(((i*2654435761)+seed) % 13) - 6; dst[i]=f32c(s, 100); i=i+1 } return 0 }
called by 1: main calls 1: nx_f32_gt
111func argmax_row(vals: *i64, tape: *i64, lg: i64, row: i64, vv: i64) -> i64 { let off: i64=tape[7*lg+5]+row*vv; var bi: i64=0; var o: i64=1; while o<vv { if nx_f32_gt(vals[off+o], vals[off+bi])==1 { bi=o } o=o+1 } return bi }
112func adam_step(P: *i64, Gd: *i64, Mo: *i64, Vo: *i64, cnt: i64, lr: i64, b1: i64, b2: i64, bc1: i64, bc2: i64, aeps: i64) -> i64
120func w_u8(b: *u8, p: *i64, v: i64) -> i64 { b[p[0]]=(v & 0xff) as u8; p[0]=p[0]+1; return 0 }
called by 3: w_u64w_meta_u32export_gguf calls 1: w_u8
121func w_u32(b: *u8, p: *i64, v: i64) -> i64 { w_u8(b,p,v); w_u8(b,p,v>>8); w_u8(b,p,v>>16); w_u8(b,p,v>>24); return 0 }
called by 2: w_strexport_gguf calls 1: w_u32
122func w_u64(b: *u8, p: *i64, v: i64) -> i64 { w_u32(b,p,v & 0xffffffff); w_u32(b,p,(v>>32) & 0xffffffff); return 0 }
called by 2: w_meta_u32export_gguf calls 1: w_u64
123func w_str(b: *u8, p: *i64, s: *u8, n: i64) -> i64 { w_u64(b,p,n); var i: i64=0; while i<n { b[p[0]]=s[i]; p[0]=p[0]+1; i=i+1 } return 0 }
called by 1: export_gguf
124func w_align(b: *u8, p: *i64) -> i64 { while (p[0] % 32)!=0 { b[p[0]]=0 as u8; p[0]=p[0]+1 } return 0 }
called by 1: export_gguf calls 2: w_strw_u32
125func w_meta_u32(b: *u8, p: *i64, key: *u8, kl: i64, v: i64) -> i64 { w_str(b,p,key,kl); w_u32(b,p,4); w_u32(b,p,v); return 0 }
called by 1: setspec
126func slen2(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
128func transpose(src: *i64, dst: *i64, in_dim: i64, out_dim: i64) -> i64 { var i: i64=0; while i<in_dim { var j: i64=0; while j<out_dim { dst[j*in_dim+i]=src[i*out_dim+j]; j=j+1 } i=i+1 } return 0 }
130func setspec(ts: *i64, idx: i64, name: *u8, ndims: i64, d0: i64, d1: i64, data: *i64, ncells: i64) -> i64
133func blkname(L: i64, suffix: *u8) -> *u8 { let o: *u8=sys_mmap(48); o[0]=98 as u8; o[1]=108 as u8; o[2]=107 as u8; o[3]=46 as u8; var p: i64=4; if L==0 { o[p]=48 as u8; p=p+1 } else { let t: *u8=sys_mmap(16); var k: i64=0; var m: i64=L; while m>0 { t[k]=(48+(m%10)) as u8; m=m/10; k=k+1 } var i: i64=k-1; while i>=0 { o[p]=t[i]; p=p+1; i=i-1 } } var j: i64=0; while suffix[j]!=(0 as u8) { o[p]=suffix[j]; p=p+1; j=j+1 } o[p]=0 as u8; return o }
135func export_gguf(path: *u8, M: *i64, vv: i64) -> i64
186func main() -> i64