code wiki / _hdl_build / nx_llm_ppl_bench_gate.nx

nx_llm_ppl_bench_gate.nx

buildroot/runtime/_hdl_build/nx_llm_ppl_bench_gate.nx

11510 B142 linesdepth 9pulls 20 transitivereach 0 importersview sourcekind gate/prooftopic llm
docsdependenciesstructsconstsfunctions

about

nx_llm_ppl_bench_gate.nx -- THE QUALITY BENCHMARK: perplexity + next-token accuracy of ANY gguf model on a held-out text, via our sovereign arch-config no-float inference. This is the "compare our quality" instrument the operator asked for -- run it on the real Qwen (track a's family), on OUR trained+exported model (track b), or on a PyTorch-fine-tuned gguf; the NUMBER is comparable across all of them. Perplexity is THE standard LLM metric (lower=better). ★NUMERICS: our integer head logit = realdot*65536 (Q24 normed . Q16 weight, >>24), so logit/65536 = the TRUE real logit -> we compute ABSOLUTE, PyTorch-comparable perplexity by doing the logsumexp reduction in f32 (a tiny standard computation) on top of the sovereign integer forward. CE_t = logsumexp_v(logit[t][v]) - logit[t][tgt_{t+1}] (real nats) perplexity = exp(mean_t CE_t) ; accuracy = fraction of positions whose argmax == the true next token. expect_exit: 0 license_tier: ORIGINAL

dependencies 11 imports · 0 importers

nx_syscalls.nx nx_tier.nx nx_le.nx nx_tensor.nx nx_gguf.nx nx_gguf_load.nx nx_gguf_meta.nx nx_nofloat_llm.nx nx_nofloat_tok.nx nx_nofloat_arch.nx nx_llm_ppl_bench_gate.nx

diagram shows first 10 each side; +1 more imports, +0 more importers in the complete lists below.

imports: nx_syscalls.nxnx_tier.nxnx_le.nxnx_tensor.nxnx_gguf.nxnx_gguf_load.nxnx_gguf_meta.nxnx_nofloat_llm.nxnx_nofloat_tok.nxnx_nofloat_arch.nxnx_f32_hw.nx

imported by: nobody (leaf or entry point)

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

main pw sys_write sys_mmap sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close nx_gguf_parse nx_le_read_u32 nx_le_read_u64 nx_le_read_u32 ↻ _gguf_skip_value nx_le_read_u64 ↻ nx_le_read_u32 ↻ _gguf_skip_value ↻ sys_mmap ↻ nac_read_config sys_mmap ↻ nx_gguf_meta_find nx_le_read_u64 ↻ nx_le_read_u32 ↻ _gmeta_bytes_equal nx_gguf_skip_value _gguf_skip_value ↻ nx_gguf_meta_read_string_l nx_le_read_u64 ↻ nx_gguf_meta_read_string_p nac_u32 sys_mmap ↻ nac_key nx_gguf_meta_find ↻ nx_gguf_meta_read_u32 nx_le_read_u32 ↻ isqrt nac_f32_int sys_mmap ↻ nac_key ↻

structs

none

consts

none

functions

23func pw(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 1: main calls 1: sys_write
24func pn(v: i64) -> i64 { let b: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(1,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;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(1,b,k); return 0 }
called by 2: pm3main calls 2: sys_mmapsys_write
25func pslen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 1: main
26func pm3(x: i64) -> i64 { return pn(f32_int(f32_mul(x, f32_of(1000)))) } // f32 -> milli print
called by 1: main calls 4: pnf32_intf32_mulf32_of
28func f32_le(x: i64, y: i64) -> i64 { let d: i64=f32_sub(x,y) & 0xFFFFFFFF; if ((d>>31)&1)==1 { return 1 } if (d & 0x7FFFFFFF)==0 { return 1 } return 0 }
called by 1: pf_exp calls 1: f32_sub
29func pf_exp(x: i64) -> i64
36func pf_log(x: i64) -> i64 { let b: i64=x & 0xFFFFFFFF; let e: i64=((b>>23)&0xFF)-127; let m: i64=(b & 0x7FFFFF)|0x3F800000; let u: i64=f32_div(f32_sub(m,f32_of(1)),f32_add(m,f32_of(1))); let u2: i64=f32_mul(u,u); var t: i64=u; var s: i64=u; var k: i64=1; while k<=7 { t=f32_mul(t,u2); s=f32_add(s,f32_div(t,f32_of((2*k)+1))); k=k+1 } let ln2: i64=f32_div(f32_of(693147),f32_of(1000000)); return f32_add(f32_mul(f32_of(e),ln2),f32_mul(f32_of(2),s)) }
38func logit_f32(lg_int: i64) -> i64 { return f32_div(f32_of(lg_int), f32_of(65536)) }
called by 1: main calls 2: f32_divf32_of
40func main() -> i64