code wiki / _hdl_build / nx_gmmlu_research_fetch.nx
nx_gmmlu_research_fetch.nx source
↩ module page · 76 lines · 4050 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// ⚠DATASET NAME: CohereForAI/Global-MMLU-Lite is RENAMED -> CohereLabs/Global-MMLU-Lite (the old name
8// returns 404 RenamedDatasetError; verified live 2026-07-20).
9// ⚠config=en is ASSUMED (Global-MMLU-Lite is per-language); the splits fetch above it exists precisely to
10// CONFIRM the real config id -- read knowledge/fetched/gmmlu_splits.raw before trusting the rows page.
11// expect_exit: 0 license_tier: ORIGINAL No hw writes (Rule 26).
12import "nx_syscalls.nx"
13import "nx_x509_trust_store.nx"
14import "nx_trust_store_load_from_certdata.nx"
15import "nx_https_fetch_follow.nx"
16
17const GM_CAP: i64 = 8388608
18const GM_ROOTS_MAX: i64 = 512
19const GM_CERTBUF: i64 = 4194304
20const GM_HOPS: i64 = 6
21const GM_MODE: i64 = 0x1a4
22const GM_D0: i64 = 48
23const GM_B10: i64 = 10
24const GM_NUMB: i64 = 24
25
26func 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 }
27func ff_putn(v: i64) -> i64 {
28 if v == 0 { sys_write(1, "0" as *u8, 1); return 0 }
29 var m: i64 = v
30 if m < 0 { sys_write(1, "-" as *u8, 1); m = 0 - m }
31 let d: *u8 = sys_mmap(GM_NUMB)
32 var k: i64 = 0
33 while m > 0 { d[k] = (GM_D0 + (m % GM_B10)) as u8; m = m / GM_B10; k = k + 1 }
34 let o: *u8 = sys_mmap(GM_NUMB)
35 var i: i64 = 0
36 while i < k { o[i] = d[k - 1 - i]; i = i + 1 }
37 sys_write(1, o, k)
38 return 0
39}
40func have_file(path: *u8) -> i64 {
41 let fd: i64 = sys_openat_rd(path)
42 if fd < 0 { return 0 }
43 sys_close(fd)
44 return 1
45}
46func fetch_save(url: *u8, opath: *u8, store: *TrustStore, out: *u8, cap: i64) -> i64 {
47 if have_file(opath) == 1 { ff_puts(opath); ff_puts(" [have-skip]\n" as *u8); return 1 }
48 let status: *i64 = sys_mmap(8) as *i64
49 let n: i64 = nx_https_fetch_follow(url, store, out, cap, GM_HOPS, status)
50 ff_puts(url); ff_puts(" status=" as *u8); ff_putn(status[0]); ff_puts(" bytes=" as *u8); ff_putn(n)
51 if n <= 0 { ff_puts(" FETCH-FAIL\n" as *u8); return 0 }
52 var gz: i64 = 0
53 if n >= 2 { if out[0] == 0x1f as u8 { if out[1] == 0x8b as u8 { gz = 1 } } }
54 if gz == 1 { ff_puts(" [GZIP-skip]\n" as *u8); return 0 }
55 let fd: i64 = sys_openat_wr(opath, GM_MODE)
56 if fd < 0 { ff_puts(" SAVE-FAIL\n" as *u8); return 0 }
57 sys_write(fd, out, n)
58 sys_close(fd)
59 ff_puts(" SAVED\n" as *u8)
60 return 1
61}
62
63func main() -> i64 {
64 let r: i64 = nx_trust_store_load_from_certdata("data/mozilla_certdata.txt" as *u8, GM_ROOTS_MAX, GM_CERTBUF)
65 if r <= 0 { ff_puts("GMMLU: certdata load failed\n" as *u8); return 1 }
66 let store: *TrustStore = r as *TrustStore
67 ff_puts("GMMLU ingest: CA roots=" as *u8); ff_putn(trust_store_count(store)); ff_puts("\n" as *u8)
68 let out: *u8 = sys_mmap(GM_CAP)
69 var ok: i64 = 0
70 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)
71 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)
72 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)
73 ff_puts("GMMLU fetch done ok=" as *u8); ff_putn(ok); ff_puts("/3\n" as *u8)
74 if ok == 3 { return 0 }
75 return 2
76}