nx_f32_softmax.nx
buildroot/runtime/nx_f32_softmax.nx
about
nx_f32_softmax.nx -- bits-up f32 numerically-stable softmax.
L7 / L8 composition brick. Composes L4 mul/add/sub/div + L6 exp.
Algorithm (numerically stable via max-subtraction):
m = max_i x[i]
shifted_i = x[i] - m
exps_i = exp(shifted_i) (each in (0, 1])
sum_exp = sum_i exps_i
out[i] = exps_i / sum_exp
Max-subtraction guards against exp overflow without changing the
final probabilities (numerator+denominator scale by the same
1/exp(m) factor, which cancels).
References absorbed clean-room:
Bridle 1990 (original softmax)
Standard logsumexp / max-subtract trick (numerical canon)
genealogy_id: bridle_1990_softmax + logsumexp_max_subtract
lineage_id: substrate_f32_softmax_v1_stable
dependencies 5 imports · 11 importers
diagram shows first 10 each side; +0 more imports, +1 more importers in the complete lists below.
imports: nx_syscalls.nxnx_tier.nxnx_f32.nxnx_f32_div.nxnx_f32_exp.nx
imported by: nx_f32_attention.nxnx_f32_attn_multi.nxnx_f32_attn_multi_test.nxnx_f32_mha.nxnx_f32_mha_test.nxnx_f32_softmax_test.nxnx_f32_transformer.nxnx_lowrank_attn.nxnx_moe.nxnx_moe_gate.nxnx_vit_encoder_layer.nx
structs
| none |
consts
| 29 | const NX_F32_SM_OK: nx_int = 0 |
| 30 | const NX_F32_SM_ERR_BAD_DIM: nx_int = 1 |
| 31 | const NX_F32_SM_N_VERDICTS: nx_int = 2 |
functions
| 33 | func nx_f32_sm_verdict_is_valid(v: nx_int) -> nx_int called by 1: main |
| 42 | func _f32_gt(a: i64, b: i64) -> nx_int |
| 58 | func nx_f32_softmax(x: *i64, n: nx_int, out: *i64) -> nx_int |