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
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
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
structs
| none |
consts
| none |
functions
| 23 | func pw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } |
| 24 | func 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 } |
| 25 | func pslen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n } called by 1: main |
| 26 | func pm3(x: i64) -> i64 { return pn(f32_int(f32_mul(x, f32_of(1000)))) } // f32 -> milli print |
| 28 | func 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 } |
| 29 | func pf_exp(x: i64) -> i64 |
| 36 | func 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)) } |
| 38 | func logit_f32(lg_int: i64) -> i64 { return f32_div(f32_of(lg_int), f32_of(65536)) } |
| 40 | func main() -> i64 |