code wiki / _hdl_build / nx_gmmlu_research_fetch.nx

nx_gmmlu_research_fetch.nx source

↩ module page · 72 lines · 3669 B

1// nx_gmmlu_research_fetch.nx -- F786 rung-1: ingest the PUBLIC Global-MMLU-Lite benchmark (a LITERAL row 2// on the model card, b16) so the reasoning/chat battery is scored on REAL public data, never on questions 3// I invented (self-authored questions = a self-quiz, not a benchmark -- scale law, no toys). 4// Fetches the dataset contract + rows pages over own TLS-1.3 to knowledge/fetched/gmmlu_*.raw. 5// Named *research_fetch* so nx_job_run's family gate can launch it ASYNC (pages exceed the 64KB MCP 6// envelope and the whole run exceeds the 15s edge window). ff_putn writes its digits (seq206 class fixed). 7// expect_exit: 0 license_tier: ORIGINAL No hw writes (Rule 26). 8import "nx_syscalls.nx" 9import "nx_x509_trust_store.nx" 10import "nx_trust_store_load_from_certdata.nx" 11import "nx_https_fetch_follow.nx" 12 13const GM_CAP: i64 = 8388608 14const GM_ROOTS_MAX: i64 = 512 15const GM_CERTBUF: i64 = 4194304 16const GM_HOPS: i64 = 6 17const GM_MODE: i64 = 0x1a4 18const GM_D0: i64 = 48 19const GM_B10: i64 = 10 20const GM_NUMB: i64 = 24 21 22func ff_puts(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 } 23func ff_putn(v: i64) -> i64 { 24 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 } 25 var m: i64 = v 26 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m } 27 let d: *u8 = sys_mmap(GM_NUMB) 28 var k: i64 = 0 29 while m > 0 { d[k] = (GM_D0 + (m % GM_B10)) as u8; m = m / GM_B10; k = k + 1 } 30 let o: *u8 = sys_mmap(GM_NUMB) 31 var i: i64 = 0 32 while i < k { o[i] = d[k - 1 - i]; i = i + 1 } 33 sys_write(1, o, k) 34 return 0 35} 36func have_file(path: *u8) -> i64 { 37 let fd: i64 = sys_openat_rd(path) 38 if fd < 0 { return 0 } 39 sys_close(fd) 40 return 1 41} 42func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 { 43 if have_file(opath) == 1 { ff_puts(opath); ff_puts(" [have-skip]\n" as *u8); return 1 } 44 let status: *i64 = sys_mmap(8) as *i64 45 let n: i64 = nx_https_fetch_follow(url, store, out, cap, GM_HOPS, status) 46 ff_puts(url); ff_puts(" status=" as *u8); ff_putn(status[0]); ff_puts(" bytes=" as *u8); ff_putn(n) 47 if n <= 0 { ff_puts(" FETCH-FAIL\n" as *u8); return 0 } 48 var gz: i64 = 0 49 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } } 50 if gz == 1 { ff_puts(" [GZIP-skip]\n" as *u8); return 0 } 51 let fd: i64 = sys_openat_wr(opath, GM_MODE) 52 if fd < 0 { ff_puts(" SAVE-FAIL\n" as *u8); return 0 } 53 sys_write(fd, out, n) 54 sys_close(fd) 55 ff_puts(" SAVED\n" as *u8) 56 return 1 57} 58 59func main() -> i64 { 60 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, GM_ROOTS_MAX, GM_CERTBUF) 61 if r <= 0 { ff_puts("GMMLU: certdata load failed\n" as *u8); return 1 } 62 let store: *TrustStore = r as *TrustStore 63 ff_puts("GMMLU ingest: CA roots=" as *u8); ff_putn(trust_store_count(store)); ff_puts("\n" as *u8) 64 let out: *u8 = sys_mmap(GM_CAP) 65 var ok: i64 = 0 66 ok = ok + fetch_save("https://datasets-server.huggingface.co/info?dataset=CohereLabs/Global-MMLU-Lite" as *u8, "knowledge/fetched/gmmlu_info.raw" as *u8, store, out, GM_CAP) 67 ok = ok + fetch_save("https://datasets-server.huggingface.co/splits?dataset=CohereLabs/Global-MMLU-Lite" as *u8, "knowledge/fetched/gmmlu_splits.raw" as *u8, store, out, GM_CAP) 68 ok = ok + fetch_save("https://datasets-server.huggingface.co/rows?dataset=CohereLabs/Global-MMLU-Lite&config=en&split=test&offset=0&length=100" as *u8, "knowledge/fetched/gmmlu_rows_000.raw" as *u8, store, out, GM_CAP) 69 ff_puts("GMMLU fetch done ok=" as *u8); ff_putn(ok); ff_puts("/3\n" as *u8) 70 if ok == 3 { return 0 } 71 return 2 72}