code wiki / (root) / nx_silu.nx

nx_silu.nx

buildroot/runtime/nx_silu.nx

7679 B222 linesdepth 4pulls 6 transitivereach 28 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_silu.nx -- SiLU / Swish activation: x * sigmoid(x). Closes the FFN activation gap. Together with nx_rmsnorm (shipped dfce1e32) this lets NishiLang run a full Llama-class transformer block end-to-end: input -> RMSNorm -> attention -> RMSNorm -> FFN (matmul -> SiLU -> matmul) -> output. SiLU = Sigmoid Linear Unit = x * sigmoid(x). * Ramachandran et al. 2017 _Searching for Activation Functions_ * Elfwing et al. 2018 _Sigmoid-Weighted Linear Units for Neural Network Function Approximation in Reinforcement Learning_ Modern transformer FFN uses SiLU exclusively (or its closely- related variant GeGLU which gates by gelu instead). Used by: Llama 2/3 SwiGLU FFN (uses SiLU as the gate) Mistral, Mixtral, Qwen, Gemma SwiGLU FFN Z-Image / Flux / Stable Diffusion 3 attention FFN ===== Math ======================================================= sigmoid(x) = 1 / (1 + exp(-x)) silu(x) = x * sigmoid(x) Q10 fixed-point: For x >= 0: e_neg = exp(-x) ; sigmoid = Q10 / (Q10 + e_neg) For x < 0: e_neg = exp(x) ; sigmoid = e_neg / (Q10 + e_neg) (Both branches use only the negative-domain exp lookup -- no overflow risk.) Then silu = x * sigmoid / Q10. Per the bits-up cardinal: composes against nx_exp_q10_neg (canonical exp primitive) NxTensor (canonical L1 container) LoopVerdict (bounded-loop discipline) genealogy_id: ramachandran_2017_silu + elfwing_2018_sil + hendrycks_gimpel_2016_gelu (sibling activation) lineage_id: substrate_silu_v1

dependencies 5 imports · 4 importers

nx_syscalls.nx nx_tier.nx nx_loop.nx nx_tensor.nx nx_exp.nx nx_silu.nx nx_f32_llm_probe.nx nx_gelu.nx nx_transformer_block.nx nx_unet_block.nx

imports: nx_syscalls.nxnx_tier.nxnx_loop.nxnx_tensor.nxnx_exp.nx

imported by: nx_f32_llm_probe.nxnx_gelu.nxnx_transformer_block.nxnx_unet_block.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main nx_silu_q10 nx_sigmoid_q10 nx_exp_q10_neg _nx_exp_table_get nx_sigmoid_q10 ↻ sys_mmap nx_t_alloc nx_dt_is_valid nx_dt_element_bytes sys_mmap ↻ nx_t_compute_strides_rowma nx_silu_forward nx_t_is_contiguous nx_silu_q10 ↻

structs

none

consts

54const NX_SILU_Q10: nx_int = 1024
58const NX_SILU_OK: nx_int = 0
59const NX_SILU_ERR_BAD_DTYPE: nx_int = 1
60const NX_SILU_ERR_SHAPE_MISMATCH: nx_int = 2
61const NX_SILU_ERR_NOT_CONTIGUOUS: nx_int = 3
62const NX_SILU_N_VERDICTS: nx_int = 4

functions

64func nx_silu_verdict_is_valid(v: nx_int) -> nx_int
74func nx_sigmoid_q10(x_q10: nx_int) -> nx_int
92func nx_silu_q10(x_q10: nx_int) -> nx_int
called by 2: nx_silu_forwardmain calls 1: nx_sigmoid_q10
101func nx_silu_forward(x: *NxTensor, out: *NxTensor) -> nx_int
150func main() -> i64