nx_silu.nx
buildroot/runtime/nx_silu.nx
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
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
structs
| none |
consts
| 54 | const NX_SILU_Q10: nx_int = 1024 |
| 58 | const NX_SILU_OK: nx_int = 0 |
| 59 | const NX_SILU_ERR_BAD_DTYPE: nx_int = 1 |
| 60 | const NX_SILU_ERR_SHAPE_MISMATCH: nx_int = 2 |
| 61 | const NX_SILU_ERR_NOT_CONTIGUOUS: nx_int = 3 |
| 62 | const NX_SILU_N_VERDICTS: nx_int = 4 |
functions
| 64 | func nx_silu_verdict_is_valid(v: nx_int) -> nx_int |
| 74 | func nx_sigmoid_q10(x_q10: nx_int) -> nx_int |
| 92 | func nx_silu_q10(x_q10: nx_int) -> nx_int |
| 101 | func nx_silu_forward(x: *NxTensor, out: *NxTensor) -> nx_int called by 3: mainnx_transformer_block_forwardnx_unet_block_forward calls 2: nx_t_is_contiguousnx_silu_q10 |
| 150 | func main() -> i64 |