code wiki / (root) / nx_safetensors.nx

nx_safetensors.nx

buildroot/runtime/nx_safetensors.nx

9233 B143 linesdepth 2pulls 2 transitivereach 0 importersview sourcekind tooltopic safetensors
docsdependenciesstructsconstsfunctions

about

nx_safetensors.nx -- SOVEREIGN safetensors parser (the neural-weights loader foundation). safetensors is the modern HuggingFace weight format (HiFi-GAN / VITS vocoders, image models, etc. are hosted in it): 8-byte LE header-length, then a JSON header {name:{dtype,shape,data_offsets:[s,e]}, ...}, then the raw tensor bytes. This parses the header (bounded per-tensor brace scan so a tensor's keys don't leak into the next) and returns each tensor's dtype/shape/byte-range -> a pointer into the data section. Paired with nx_https_get_stream (streaming download) this is the sovereign path to ACQUIRE + LOAD a neural model ourselves -- no operator-must-download, the real unblock for human-realistic neural voice (and neural image). Self-test builds a synthetic safetensors in memory + parses it back (metadata + f32 values byte-exact). No JSON lib, no ML dep. license_tier: ORIGINAL expect_exit: 0

dependencies 1 imports · 0 importers

nx_syscalls.nx nx_safetensors.nx

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 sw sys_write slen sys_mmap put_u64le put_str put_u32le st_u64le sn sys_mmap ↻ sys_write ↻ st_tensor sys_mmap ↻ st_find slen ↻ st_match_brace st_int_array st_u32le shx sys_mmap ↻ sys_write ↻ sys_exit

structs

none

consts

10const K_MAGIC_65536: i64 = 65536

functions

12func sw(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
13func sn(v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} 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{bb[i]=t[k-1-i];i=i+1} sys_write(1,bb,k); return 0 }
called by 1: main calls 2: sys_mmapsys_write
14func shx(v: i64) -> i64 { let b: *u8=sys_mmap(8); var i: i64=0; while i<8 { let n: i64=(v>>((7-i)*4))&0xF; if n<10 {b[i]=(48+n) as u8} else {b[i]=(87+n) as u8} i=i+1 } sys_write(1,b,8); return 0 }
called by 1: main calls 2: sys_mmapsys_write
15func slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 2: st_findmain
18func st_u64le(buf: *u8, off: i64) -> i64 { var v: i64=0; var i: i64=0; while i<8 { v = v | ((buf[off+i]&0xff) << (i*8)); i=i+1 } return v }
called by 1: main
19func st_u32le(buf: *u8, off: i64) -> i64 { return (buf[off]&0xff) | ((buf[off+1]&0xff)<<8) | ((buf[off+2]&0xff)<<16) | ((buf[off+3]&0xff)<<24) }
called by 1: main
22func st_find(hdr: *u8, start: i64, end: i64, pat: *u8) -> i64
called by 1: st_tensor calls 1: slen
33func st_match_brace(hdr: *u8, obj_start: i64, hlen: i64) -> i64
called by 1: st_tensor
44func st_int_array(hdr: *u8, pos: i64, hlen: i64, arr: *i64) -> i64
called by 1: st_tensor
57func st_tensor(hdr: *u8, hlen: i64, name: *u8, dtype_out: *u8, shape_out: *i64, offs_out: *i64) -> i64
86func put_u64le(buf: *u8, off: i64, v: i64) -> i64 { var i: i64=0; while i<8 { buf[off+i]=((v>>(i*8))&0xff) as u8; i=i+1 } return 0 }
called by 1: main
87func put_u32le(buf: *u8, off: i64, v: i64) -> i64 { var i: i64=0; while i<4 { buf[off+i]=((v>>(i*8))&0xff) as u8; i=i+1 } return 0 }
called by 1: main
88func put_str(buf: *u8, off: i64, s: *u8) -> i64 { var i: i64=0; while s[i]!=(0 as u8){ buf[off+i]=s[i]; i=i+1 } return off+i }
called by 1: main
90func main() -> i64