code wiki / (root) / nx_f32_lazy_weight.nx

nx_f32_lazy_weight.nx

buildroot/runtime/nx_f32_lazy_weight.nx

41152 B886 linesdepth 9pulls 28 transitivereach 62 importersview sourcekind librarytopic f32
docsdependenciesstructsconstsfunctions

about

nx_f32_lazy_weight.nx -- format-tagged weight tensor + matmul dispatcher. The foundation brick for lazy-Q4_K integration into the forward path. Current model bindings (NxF32LlamaLayer) hold raw *i64 pointers to eagerly-dequanted f32 storage. Lazy variants hold either f32 storage OR a (GGUF buffer + offset) pair for on-the- fly Q4_K dequant during matmul. A future v4 forward + binder will use NxF32LazyWeight throughout. This brick provides the type + dispatcher; integration with the per-layer struct + forward is a separate brick to keep scope tight. genealogy_id: tagged_union_dispatch + ggml_format_taxonomy lineage_id: substrate_f32_lazy_weight_v1

dependencies 9 imports · 55 importers

nx_syscalls.nx nx_tier.nx nx_f32_matmul.nx nx_f32_matmul_t.nx nx_f32_q4k_matmul.nx nx_q5_0_to_f32.nx nx_q8_0_to_f32.nx nx_le.nx nx_pteam.nx nx_f32_lazy_weight.nx nx_batched_gate.nx nx_batched_tput.nx nx_batchscale_kat.nx nx_chat_warmcache.nx nx_coder_gen_f32.nx nx_companion_chat.nx nx_companion_voice.nx nx_f32_ffn_path_gate.nx nx_f32_lazy_weight_test.nx nx_f32_llama_block_v4.nx

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

imports: nx_syscalls.nxnx_tier.nxnx_f32_matmul.nxnx_f32_matmul_t.nxnx_f32_q4k_matmul.nxnx_q5_0_to_f32.nxnx_q8_0_to_f32.nxnx_le.nxnx_pteam.nx

imported by: nx_batched_gate.nxnx_batched_tput.nxnx_batchscale_kat.nxnx_chat_warmcache.nxnx_coder_gen_f32.nxnx_companion_chat.nxnx_companion_voice.nxnx_f32_ffn_path_gate.nxnx_f32_lazy_weight_test.nxnx_f32_llama_block_v4.nxnx_f32_llama_block_v4_test.nxnx_f32_llama_layer_lazy_load.nxnx_f32_llama_layer_lazy_load_test.nxnx_f32_llama_stack_v4.nxnx_f32_llama_stack_v4_test.nxnx_f32_llama_v4b.nxnx_f32_llama_v4p.nxnx_f32_llm_bench_test.nxnx_f32_llm_chat_test.nxnx_f32_llm_cohere_test.nxnx_f32_llm_embed_diag_test.nxnx_f32_llm_live_gen_test.nxnx_f32_llm_live_load_only_test.nxnx_f32_llm_live_load_test.nxnx_f32_llm_probe.nxnx_f32_llm_run_v3.nxnx_f32_llm_run_v3_test.nxnx_f32_llm_serve.nxnx_f32_llm_v4.nxnx_f32_llm_v4_test.nxnx_f32_qwen_capital_gate.nxnx_llm_argmax_probe.nxnx_llm_batch_serve.nxnx_llm_diff_probe.nxnx_llm_forward_profile.nxnx_llm_france_probe.nxnx_llm_layerlens_probe.nxnx_llm_sched_gate.nxnx_lowrank_kv_real.nxnx_lw_cache_gate.nxnx_lwq24_probe.nxnx_natmm_bench.nxnx_paged_fwd_gate.nxnx_q5q8_ab.nxnx_q8_coldwarm.nxnx_q8_matmul_micro.nxnx_q8_mix_ab.nxnx_q8_scaling.nxnx_q8_st_bw.nxnx_qwen_native_gate.nxnx_qwen_wsl_timing_gate.nxnx_reason_paged_probe.nxnx_reason_probe.nxnx_reasoning_gate.nxnx_specdec_gate.nx

structs

43struct NxF32LazyWeight

consts

26const NX_LW_DTYPE_F32: nx_int = 0
27const NX_LW_DTYPE_Q4_K: nx_int = 1
28const NX_LW_DTYPE_Q5_0: nx_int = 2 // 2026-07-08: keep Q5_0 quantized (3MB vs 34.9MB F32), fused dequant-dot
29const NX_LW_DTYPE_Q8_0: nx_int = 3 // 2026-07-08: keep Q8_0 quantized; SIMD __f32_i8dot32 dequant-dot = 10.2x (lm_head)
31const NX_LW_OK: nx_int = 0
32const NX_LW_ERR_BAD_TYPE: nx_int = 1
33const NX_LW_ERR_NULL: nx_int = 2
34const NX_LW_ERR_INNER: nx_int = 3 // inner matmul verdict != OK (e.g. Q4_K ERR_ALIGN -- was silently OK before 2026-07-07)
35const NX_LW_N_VERDICTS: nx_int = 4
55const NX_LW_BYTES: nx_int = 64 // 8 fields * 8
130const NX_LW_NATIVE_POOL_W: i64 = 8
178const NX_LW_CACHE_BUDGET_DEFAULT: i64 = 0 // 0 = stream quantized weights (re-measured 2026-08-01)
636const NX_Q8_ST_MAC_MAX: i64 = 0

functions

37func nx_lw_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
57func nx_f32_lazy_weight_new_f32(storage: *i64, rows: nx_int, cols: nx_int) -> *NxF32LazyWeight
70func nx_f32_lazy_weight_new_q4k(buf: *u8, offset: i64,
88func nx_f32_lazy_weight_new_q5_0(buf: *u8, offset: i64,
102func nx_f32_lazy_weight_new_q8_0(buf: *u8, offset: i64,
132func nx_lw_shared_pool() -> *NxThreadPool
183func nx_lw_set_cache_budget(bytes: i64) -> i64
called by 2: mainlwc_run
188func nx_lw_cache_used() -> i64
called by 4: mainmainlwc_runmain
192func _lw_budget() -> i64
called by 1: _lw_try_fill
200func _lw_fill_task(ctx_i: i64) -> i64
218func _lw_fill_f32_task(ctx_i: i64) -> i64
244func _lw_try_fill(W: *NxF32LazyWeight, k: nx_int, n: nx_int) -> i64
307func _lw_dot_x8(a: *u8, b: *u8, count: i64, acc: *u8) -> i64
called by 1: _lw_dot_task
330func _lw_dot_task(ctx_i: i64) -> i64
359func _lw_cached_matmul(W: *NxF32LazyWeight, A: *i64, C: *i64,
435func _lw_q5_consts() -> *u8
called by 1: _lw_q5_0_task calls 1: sys_mmap
455func _lw_q5_0_dot(qbuf: *u8, qoff: i64, Apk: *u8, k: i64, i8scr: *u8, consts: *u8) -> i64
472func _lw_q5_0_task(ctx_i: i64) -> i64
494func _lw_q5_0_matmul(W: *NxF32LazyWeight, A: *i64, C: *i64,
553func _lw_q8_0_dot(qbuf: *u8, qoff: i64, Apk: *u8, k: i64) -> i64
569func _lw_q8_0_task(ctx_i: i64) -> i64
calls 1: _lw_q8_0_dot
599func _q8st_apk(need: i64) -> *u8
607func _lw_q8_0_matmul_st(W: *NxF32LazyWeight, A: *i64, C: *i64,
647func _q8mt_ctxs(need: i64) -> *u8
652func _lw_q8_0_matmul_pool_force(W: *NxF32LazyWeight, A: *i64, C: *i64,
692func _q8_pteam() -> *NxPTeam
called by 1: _lw_q8_0_matmul_pteam calls 1: nx_pteam_new
696func _lw_q8_0_pteam_band(band: i64, ctx: i64) -> i64
calls 1: _lw_q8_0_dot
718func _lw_q8_0_matmul_pteam(W: *NxF32LazyWeight, A: *i64, C: *i64,
737func _lw_q8_0_matmul(W: *NxF32LazyWeight, A: *i64, C: *i64,
756func nx_f32_lazy_matmul(A: *i64, W: *NxF32LazyWeight, C: *i64,