code wiki / (root) / nx_f32_sampler.nx

nx_f32_sampler.nx

buildroot/runtime/nx_f32_sampler.nx

12038 B344 linesdepth 5pulls 8 transitivereach 31 importersview sourcekind librarytopic f32
docsdependenciesstructsconstsfunctions

about

nx_f32_sampler.nx -- temperature + top-k sampler for LLM logits. Production samplers beyond greedy. Composes: nx_f32_lt IEEE 754 compare nx_f32_sub logits shift for numerical stability nx_f32_mul temperature scaling nx_f32_exp softmax exp nx_f32_add cumulative sum nx_q14_to_f32 PRNG uniform conversion nx_prng_uniform_q14 Q14 uniform [0, 16384) Algorithms (canonical): Temperature scaling: Hinton 2015 (Knowledge Distillation) Categorical sampling: Wong 1980 (inverse CDF / Walker's alias) Top-k sampling: Fan 2018 (Hierarchical Neural Story Gen.) genealogy_id: hinton_2015_temperature + fan_2018_top_k + bridle_1990_softmax + wong_1980_inverse_cdf lineage_id: substrate_f32_sampler_v1

dependencies 7 imports · 30 importers

nx_syscalls.nx nx_tier.nx nx_prng.nx nx_f32.nx nx_f32_div.nx nx_f32_cvt.nx nx_f32_exp.nx nx_f32_sampler.nx nx_batched_gate.nx nx_batched_tput.nx nx_coder_gen_f32.nx nx_f32_llm_bench_test.nx nx_f32_llm_cohere_test.nx nx_f32_llm_e2e_test.nx nx_f32_llm_live_gen_test.nx nx_f32_llm_run.nx nx_f32_llm_run_test.nx nx_f32_llm_run_v2.nx

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

imports: nx_syscalls.nxnx_tier.nxnx_prng.nxnx_f32.nxnx_f32_div.nxnx_f32_cvt.nxnx_f32_exp.nx

imported by: nx_batched_gate.nxnx_batched_tput.nxnx_coder_gen_f32.nxnx_f32_llm_bench_test.nxnx_f32_llm_cohere_test.nxnx_f32_llm_e2e_test.nxnx_f32_llm_live_gen_test.nxnx_f32_llm_run.nxnx_f32_llm_run_test.nxnx_f32_llm_run_v2.nxnx_f32_llm_run_v2_test.nxnx_f32_llm_run_v3.nxnx_f32_llm_run_v3_test.nxnx_f32_llm_serve.nxnx_f32_qwen_capital_gate.nxnx_f32_sampler_test.nxnx_llm_batch_serve.nxnx_llm_france_probe.nxnx_llm_sched.nxnx_llm_sched_gate.nxnx_paged_fwd_gate.nxnx_qwen_native_gate.nxnx_qwen_wsl_timing_gate.nxnx_reason_paged_probe.nxnx_reason_probe.nxnx_reasoning.nxnx_reasoning_gate.nxnx_reasoning_paged.nxnx_specdec.nxnx_specdec_gate.nx

structs

none

consts

28const NX_MAGIC_16384: i64 = 16384
30const NX_FSP_OK: nx_int = 0
31const NX_FSP_ERR_BAD_DIM: nx_int = 1
32const NX_FSP_ERR_NULL: nx_int = 2
33const NX_FSP_N_VERDICTS: nx_int = 3

functions

35func nx_fsp_verdict_is_valid(v: nx_int) -> nx_int
called by 1: main
43func nx_f32_sampler_argmax(logits: *i64, vocab_size: nx_int) -> nx_int
62func nx_f32_sampler_sample_temp(logits: *i64, vocab_size: nx_int,
109func nx_f32_sampler_sample_top_k(logits: *i64, vocab_size: nx_int,
172func _fsp_find_top_p_k(logits: *i64, vocab_size: nx_int,
250func nx_f32_sampler_apply_repetition_penalty(
281func _fsp_find_min_p_k(logits: *i64, vocab_size: nx_int,
316func nx_f32_sampler_sample_min_p(logits: *i64, vocab_size: nx_int,
330func nx_f32_sampler_sample_top_p(logits: *i64, vocab_size: nx_int,