nx_fnet_mix.nx
buildroot/runtime/nx_fnet_mix.nx
about
nx_fnet_mix.nx -- FNET-001: SUB-QUADRATIC Fourier token-mixer (FNet, Lee-Thorp/Ainslie/Eckstein/Ontanon 2021).
The escape from the transformer VRAM/compute exponential is JUST MATH. Self-attention mixes tokens with an
all-pairs softmax(Q@K^T)@V -- O(n^2 * d) multiplies, the quadratic that explodes VRAM as context grows. FNet
replaces that learned attention sublayer with a parameter-FREE 2D Discrete Fourier Transform and keeps the
REAL part: y = Re( FFT_seq( FFT_hidden(x) ) ). Token mixing becomes O(n * d * log(n*d)) -- linearithmic, not
quadratic -- with ZERO attention parameters and ZERO n-by-n score matrix to hold in memory.
This is the sovereign realization of that math:
* a GENERALIZED radix-2 FFT for ANY power-of-2 length (the shipped nx_fft caps at N=32 via a hardcoded
twiddle table; here twiddles are synthesized for arbitrary N by the sovereign CORDIC fx_cos/fx_sin),
* the FNet 2D-DFT real-part token mixer composed from it,
* an integer-MULTIPLY op counter threaded through so the gate can MEASURE (never assert) the sub-quadratic
crossover against scaled-dot-product attention.
DRY: reuses nx_fft_log2 + nx_fft_bit_reverse (already length-generic) and the SAME Q14 butterfly arithmetic as
the shipped, gated nx_fft, so the generalized FFT is bit-comparable to it (proven in nx_fnet_mix_gate.nx).
genealogy_id: cooley_tukey_1965_fft + lee_thorp_2021_fnet + vaswani_2017_attention(as the incumbent it exceeds)
lineage_id: fnet_sovereign_fourier_token_mixer_v1
license_tier: ORIGINAL
nx_safety_envelope:
intended_use: "parameter-free sub-quadratic token mixing for sovereign sequence models (FNet block);
the no-VRAM-exponential alternative to self-attention"
sil_target: SIL2
evidence: [Q14_fixed_point_deterministic, FFT_equals_naive_DFT_gated,
twiddles_match_shipped_nx_fft, measured_subquadratic_crossover_vs_attention]
residual_risk: "N and hidden-dim d must be powers of two (radix-2 contract); Q14 saturates above |x|>=2."
verdict: GREEN (nx_fnet_mix_gate 2026-06-14: C1 FFT==naive-DFT, C2 twiddles match nx_fft within 1 Q14,
measured sub-quadratic crossover vs attention 6->22->75->264x at n=64..4096; see fnet_mix.log)
dependencies 3 imports · 2 importers
imports: nx_fft.nxfx.nxnx_syscalls.nx
imported by: nx_fnet_grad_gate.nxnx_fnet_mix_gate.nx
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| none |
functions
| 39 | func fnet_q16_to_q14(v: i64) -> i64 |
| 47 | func fnet_build_twiddles(n: i64, tw_re: *i64, tw_im: *i64) -> i64 |
| 63 | func fnet_fft_fwd(re: *i64, im: *i64, n: i64, tw_re: *i64, tw_im: *i64, opc: *i64) -> i64 |
| 118 | func fnet_mix(x_re: *i64, x_im: *i64, n: i64, d: i64, opc: *i64) -> i64 called by 4: fg_forwardfnet_mix_backwardmainfn_fnet_measure calls 3: sys_mmapfnet_build_twiddlesfnet_fft_fwd |
| 182 | func fnet_mix_backward(g_re: *i64, g_im: *i64, n: i64, d: i64, opc: *i64) -> i64 calls 1: fnet_mix |
| 189 | func main() -> i64 |