code wiki / (root) / nx_reasoning.nx

nx_reasoning.nx

buildroot/runtime/nx_reasoning.nx

12663 B322 linesdepth 13pulls 57 transitivereach 14 importersview sourcekind library
docsdependenciesstructsconstsfunctions

about

nx_reasoning.nx -- sovereign TEST-TIME COMPUTE organ (self-consistency). The no.1 2025/26 frontier gap on the LLM census (nx_swcompare_gapmap llm, momentum=11): spend MORE inference compute per question to get a BETTER answer. This organ implements the foundational primitive: Self-consistency majority vote (Wang et al. 2023, ICLR): sample N diverse completions at temperature T, extract each final answer, return the mode. Accuracy rises with N on tasks where the error mode is "diverse wrong answers, consistent right answer". Generation goes through the CHATML TEMPLATE at the TOKEN level (<|im_start|> injected as ids -- the nx_f32_llm_chat_test.nx proven path). MEASURED 2026-07-09: Qwen2.5-Instruct on a RAW continuation prompt ("47 + 38 =") emits garbage even with correct digit-split tokenization (verified by nx_tok_probe); the instruct model is only in-distribution INSIDE its template. Composes the EXISTING sampler (Hinton-2015 temperature + Fan-2018 top-k) + forward_v4 -- ZERO new model machinery. The answers array is the composition point for future best-of-N verifier re-ranking. genealogy_id: wang_2023_self_consistency lineage_id: substrate_reasoning_v2 (v1 = raw-continuation, measured-hostile)

dependencies 8 imports · 14 importers

nx_syscalls.nx nx_tier.nx nx_prng.nx nx_bpe.nx nx_f32_kv_cache.nx nx_f32_llm.nx nx_f32_llm_v4.nx nx_f32_sampler.nx nx_reasoning.nx nx_batched_gate.nx nx_batched_tput.nx nx_f32_llm_serve.nx nx_llm_batch_serve.nx nx_llm_sched.nx nx_llm_sched_gate.nx nx_paged_fwd_gate.nx nx_reason_paged_probe.nx nx_reason_probe.nx nx_reasoning_gate.nx

diagram shows first 10 each side; +0 more imports, +4 more importers in the complete lists below.

imports: nx_syscalls.nxnx_tier.nxnx_prng.nxnx_bpe.nxnx_f32_kv_cache.nxnx_f32_llm.nxnx_f32_llm_v4.nxnx_f32_sampler.nx

imported by: nx_batched_gate.nxnx_batched_tput.nxnx_f32_llm_serve.nxnx_llm_batch_serve.nxnx_llm_sched.nxnx_llm_sched_gate.nxnx_paged_fwd_gate.nxnx_reason_paged_probe.nxnx_reason_probe.nxnx_reasoning_gate.nxnx_reasoning_paged.nxnx_specdec.nxnx_specdec_gate.nxnx_tok_probe.nx

structs

39struct NxReasonCfg

consts

35const NX_REASON_NONE: i64 = 0 - 999999999
54const NX_REASON_CFG_BYTES: nx_int = 96 // 12 fields * 8

functions

56func nx_reason_cfg_alloc() -> *NxReasonCfg
called by 10: mainmainmainmainmainmain+4 calls 1: sys_mmap
61func _nxr_enc(vocab: *NxBpeVocab, text: *u8, tlen: nx_int, toks: *i64, off: nx_int) -> nx_int
79func nx_reason_build_chat_toks(rc: *NxReasonCfg, qtext: *u8, qlen: nx_int,
96func nx_reason_chat_gen(rc: *NxReasonCfg, qtext: *u8, qlen: nx_int,
160func nx_reason_extract_int(text: *u8, n: nx_int) -> i64
called by 1: main
187func nx_reason_extract_last_int(text: *u8, n: nx_int) -> i64
217func nx_reason_majority(answers: *i64, n: nx_int) -> i64
241func nx_reason_selfconsist(rc: *NxReasonCfg, qtext: *u8, qlen: nx_int,
263func _nxr_put_u(buf: *u8, off: i64, v: i64) -> i64
274func _nxr_put_s(buf: *u8, off: i64, s: *u8) -> i64
284func nx_reason_build_q(buf: *u8, a: i64, op_code: i64, b: i64) -> nx_int
300func nx_reason_build_q_short(buf: *u8, a: i64, op_code: i64, b: i64) -> nx_int
310func nx_reason_build_arith_prompt(buf: *u8, a: i64, op_code: i64, b: i64) -> nx_int
called by 1: main calls 1: _nxr_put_u