code wiki / _hdl_build / nx_hf_enumerate_probe.nx
nx_hf_enumerate_probe.nx source
↩ module page · 67 lines · 3793 B
1// nx_hf_enumerate_probe.nx -- LIVE proof of M2 (enumerate) on the REAL Apertus repo: fetch the HF tree API over
2// sovereign TLS, chunked_decode if needed (dynamic API), parse per-shard path + lfs.oid(sha256) + real size, and
3// print the shard manifest + total bytes -> the concrete input for the operator's go/no-go on the full weights pull.
4// Metadata only (no weights downloaded). Composes the TLS fetch + nx_http_chunked + nx_hf_tree_parse -- all no-crypto
5// here (no nx_sha256), so no M32 collision with the TLS stack. license_tier: ORIGINAL expect_exit: 0
6import "nx_syscalls.nx"
7import "nx_x509_trust_store.nx"
8import "nx_trust_store_load_from_certdata.nx"
9import "nx_https_fetch_follow.nx"
10import "nx_hf_tree_parse.nx"
11const K_MAGIC_4194304: i64 = 4194304
12const K_MAGIC_1000000000: i64 = 1000000000
13
14func w(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
15func wn(v: i64) -> i64 { var m: i64=v; if m<0{w("-" as *u8);m=0-m} let t:*u8=sys_mmap(24); 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; let o:*u8=sys_mmap(24); while i<k{o[i]=t[k-1-i];i=i+1} sys_write(1,o,k); return 0 }
16func en_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
17
18func main() -> i64 {
19 w("=== nx_hf_enumerate_probe: LIVE enumerate of the ungated Apertus-8B-Instruct repo (M2) ===\n" as *u8)
20 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, 512, K_MAGIC_4194304)
21 if r <= 0 { w("certdata load FAILED\n" as *u8); sys_exit(1); return 1 }
22 let store: *TrustStore = r as *TrustStore
23 let cap: i64 = K_MAGIC_4194304
24 let out: *u8 = sys_mmap(cap)
25 let status: *i64 = sys_mmap(8) as *i64
26
27 let url: *u8 = "https://huggingface.co/api/models/adamo1139/Apertus-8B-Instruct-2509-ungated/tree/main?recursive=1" as *u8
28 let tn: i64 = nx_https_fetch_follow(url, store, out, cap, 6, status)
29 w(" tree fetch status=" as *u8); wn(status[0]); w(" raw-bytes=" as *u8); wn(tn); w("\n" as *u8)
30 if tn <= 0 { w(" tree fetch FAILED\n" as *u8); sys_exit(1); return 1 }
31
32 // direct parse (if the fetch reader already delivers clean JSON). If shards==0 on a 200, the body is likely
33 // still chunked-framed -> that's the signal to wire chunked_decode into the reader (separate step).
34 let body: *u8 = out
35 let bn: i64 = tn
36 let shards: i64 = hft_count(body, bn, ".safetensors" as *u8)
37 w(" .safetensors shards=" as *u8); wn(shards); w("\n" as *u8)
38
39 // walk entries by "path"; for each .safetensors path, read its lfs.oid (sha256) + lfs size.
40 var from: i64 = 0
41 var total: i64 = 0
42 var listed: i64 = 0
43 var guard: i64 = 0
44 while guard < 64 {
45 let pathbuf: *u8 = sys_mmap(256)
46 let ps: i64 = hft_path(body, bn, from, pathbuf)
47 if ps < 0 { guard = 64 } else {
48 let pl: i64 = en_slen(pathbuf)
49 if hft_find(pathbuf, pl, 0, ".safetensors" as *u8) >= 0 {
50 let sha: *u8 = sys_mmap(80)
51 let os: i64 = hft_lfs_oid(body, bn, ps, sha)
52 var sz: i64 = 0
53 if os >= 0 { sz = hft_num_field(body, bn, os, "\"size\":" as *u8) }
54 total = total + sz
55 listed = listed + 1
56 w(" - " as *u8); w(pathbuf); w(" size=" as *u8); wn(sz); w(" sha256=" as *u8); w(sha); w("\n" as *u8)
57 }
58 from = ps + 1
59 }
60 guard = guard + 1
61 }
62
63 w("\n TOTAL shards listed=" as *u8); wn(listed); w(" total bytes=" as *u8); wn(total)
64 w(" (~" as *u8); wn(total / K_MAGIC_1000000000); w(" GB)\n" as *u8)
65 w("=== enumerate GREEN (real per-shard path+size+sha256 over sovereign TLS; ready for the verified pull) ===\n" as *u8)
66 sys_exit(0); return 0
67}