← → to navigate
ACS-USP. TELUS Digital Research Hub, University of São Paulo


KAN for
Language Models

Interpretability, Efficiency, and the MLPEdge Variant — an empirical study of Kolmogorov-Arnold Networks as FFN replacements in GPT-style transformers.


Felippe Alves

ACS-USP · TELUS Digital Research Hub · felippe.pereira@usp.br

ACS-USP/kanprey-lm

~60 min

Overview

Contents

  • 1The Kolmogorov-Arnold Theorem — from 1957 to neural networks8 min
  • 2KANLinear: B-spline basis, forward pass, grid update8 min
  • 3KANs in transformers: replacing the FFN, KAT attention7 min
  • 4Experiments: masking, B-spline vs MLPEdge vs GR-KAN12 min
  • 5Interpretability: what do 884,736 KAN edges actually learn?8 min
  • 6Scale: GPT-2 size, GR-KAN 30M, and ModuleChain staging10 min
  • 7Advanced: MoE GR-KAN and LoopGRKAN (Ouro + EqR)5 min
  • 8Discussion, caveats, and next steps2 min
Part One

The Kolmogorov-Arnold
Representation Theorem

From a 1957 theorem on superpositions to a new class of neural network

§1 · Kolmogorov-Arnold Theorem

The Original Theorem, 1957

Every continuous function $f:[0,1]^n \to \mathbb{R}$ can be written as a finite superposition of continuous univariate functions.

Kolmogorov, 1957 · Arnold, 1957
$$f(\mathbf{x}) = \sum_{q=0}^{2n} \Phi_q\!\left(\sum_{p=1}^{n} \phi_{q,p}(x_p)\right)$$
  • $\phi_{q,p}: [0,1] \to \mathbb{R}$ — inner univariate functions
  • $\Phi_q: \mathbb{R} \to \mathbb{R}$ — outer univariate functions
  • Only 1D operations; no multivariate terms needed
  • Existence guaranteed; functions may be non-smooth

Why does this matter for AI?

The universal approximation theorem tells us what MLPs can approximate. The KA theorem tells us something deeper: any continuous multivariate function fundamentally decomposes into sums of 1D functions.


The KAN insight (Liu et al., ICLR 2024)

If every multivariate function reduces to 1D functions, why not build networks where every learnable parameter is a 1D function? Each "weight" becomes a visualizable curve — interpretable, and in principle, symbolically regressionable.

Important caveat

The exact theorem covers two-layer networks. Liu et al. use it as motivation for a general-depth architecture — not a formal proof of its properties.

§1 · Topology Shift

MLP vs KAN — A Change in Where Nonlinearity Lives

MLP — fixed activations, learned scalars

$$y_j = \sigma\!\left(\sum_i W_{ji}\, x_i + b_j\right)$$
  • $\sigma$ is fixed (ReLU, GELU, …)
  • $W_{ji}$ is a scalar — a single number per edge
  • Nonlinearity sits at the node

KAN — fixed structure, learned functions

$$y_j = \sum_i f_{i,j}(x_i)$$
  • Each $f_{i,j}$ is a learnable 1D function (a curve)
  • No scalar weights — every edge carries a function
  • Nonlinearity sits at the edge
MLP σ σ KAN f(·)
Consequence for interpretability

With $d_\text{in}=384$ and $d_\text{out}=384$, a single KAN FFN layer contains $384 \times 384 = 147{,}456$ visualizable 1D functions. Over 6 layers: 884,736 inspectable curves.

§2 · KANLinear (EfficientKAN, Blealtan 2024)

The B-Spline KAN Layer

$$\text{out} = \underbrace{\text{SiLU}(x)\,W_{\text{base}}^\top}_{\text{residual path}} + \underbrace{\text{einsum}\!\left(B(x),\, W_{\text{spline}}\right)}_{\text{spline path}}$$

B-spline basis $B(x)$

  • Evaluated via Cox-de Boor recursion on a fixed grid
  • $n_{\text{basis}}$ = grid_size + spline_order per input channel
  • Default: grid=5, order=3 → $n_{\text{basis}}=8$
  • Grid spans $[-1,1]$, extended with $k$ extra knots on each side

Grid update

After warm-up (step 500), knot positions adapt to the quantile distribution of actual activations — a once-per-training, non-differentiable operation.

Parameter count

ComponentShapeCount
$W_\text{base}$$d_\text{out}\times d_\text{in}$$384^2 = 147\text{K}$
$W_\text{spline}$$d_\text{out}\times d_\text{in}\times n_{\text{basis}}$$384^2\times 8 = 1.18\text{M}$
Grid buffer$d_\text{in}\times n_\text{knots}$non-trainable
# Cox-de Boor recursion (simplified)
def b_splines(x, grid, order):
    # x: (B, d_in) → bases: (B, d_in, n_basis)
    bases = (x >= grid[:,:-1]) & (x < grid[:,1:])
    for k in range(1, order+1):
        left  = (x-t_i)/(t_ik-t_i).clamp(1e-8) * bases[...,:-1]
        right = (t_ik1-x)/(t_ik1-t_i1).clamp(1e-8) * bases[...,1:]
        bases = left + right
    return bases
§3 · KANs in Transformers

Replacing the FFN in a Transformer Block

Standard transformer block

LayerNorm norm
Multi-Head Attention  $K(\mathbf{q},\mathbf{k})=\mathbf{q}\cdot\mathbf{k}/\sqrt{d}$ attn
LayerNorm norm
FFN: Linear → GELU → Linear (4×) ffn
↓ our replacement
LayerNorm
Attention (standard)  or KAT
LayerNorm
KAN FFN: KANLinear / MLPEdge / GR-KAN

KAT Attention (Yang & Wang, ICLR 2025)

Replace linear Q, K projections with KANLinear feature maps $\varphi$, turning the dot-product similarity into a learned kernel:

$$K(\mathbf{q},\mathbf{k}) = \varphi(\mathbf{q})\cdot\varphi(\mathbf{k})\,/\,\sqrt{d}$$

Applied per-head on head_dim=64, not d_model=384. V and output projection remain standard linear layers.


Why replace only the FFN?

  • FFN ≈ 2/3 of parameters — the largest compute block
  • FFN is applied independently per token — ideal for KAN's 1D decomposition along feature axes
  • Attention does relational computation; the benefit of splines on score functions is less clear
§3 · KanpreyLM Testbed

Our Testbed: KanpreyLM

Shared architecture

HyperparameterValue
$d_\text{model}$384
Layers / heads6 / 6 (head_dim = 64)
Max seq length128
Vocab (BPE)2,393
Params (approx.)9–10M depending on variant

Training

SettingValue
Steps / batch8,000 / 32
OptimizerAdamW (β₁=0.9, β₂=0.95, λ=0.1)
LR scheduleCosine 3×10⁻⁴ → 3×10⁻⁵
Grid updateStep 500 (KAN/KAT only)

Dataset: GuppyLM-60k

arman-bd/guppylm-60k-generic — 60K instruction-response pairs in ChatML format. First-person fish-personality chatbot. BPE tokenizer trained on same corpus.


Why this scale?

At $d_\text{model}=384$, each KAN FFN layer has 147,456 edge functions — small enough to reconstruct and characterize every single one exhaustively. At GPT-2 scale ($d=768$) that's 4× more, making a full edge-level study infeasible.

The single-domain corpus provides coherent semantic categories for token-conditioned interpretability analysis.

Prompt-response masking

Loss computed on assistant tokens only: targets for user prompt tokens set to -100 (ignored by cross-entropy). This single change proved to be the most impactful in the entire project.

Part Four

Experiments &
Key Findings

Masking, B-spline KAN, MLPEdge, KAT attention, and GR-KAN

§4 · Finding 1 — The Most Impactful Change

Prompt-Response Masking Matters

Without masking

0.4202
validation loss
  • Loss computed over all tokens including the user prompt
  • Model learns to predict the prompt itself
  • Outputs leak role markers — generates "assistant" as part of responses
  • 4,000 training steps wasted on diluted signal

With masking  $y[\text{:prompt\_len}-1] = -100$

0.2867
validation loss (−31%)
  • Loss computed only on assistant tokens
  • Role-marker leakage eliminated
  • Clean, in-character fish-personality responses

Training objectiveVal lossRole-marker in responses
All tokens (no masking)0.4202Yes
Assistant tokens only0.2870No

Any architectural comparison without prompt-response masking measures training objective design, not architecture quality.

§4 · Model Variants

All Models at a Glance

ModelFFNAttentionVal loss Eval / 16LatencyParamsTrain time
GuppyLM (MLP) ‡ Linear → ReLU → Linear dot-product 0.3892 8–9~180 ms8.7M~8 min
KANpreyLM KANLinear (B-spline) dot-product 0.28948~880 ms9.8M~19 min
KATpreyLM KANLinear (B-spline) KAT 0.286713–15~1200 ms10.2M43 min
MLPEdgepreyLM ★ MLP-per-edge dot-product 0.285414 ~680 ms9.0M10 min
GR-KANpreyLM † GroupRational (Safe Padé) dot-product 0.2762 545 ms11.6M59 min

‡ All-tokens loss (no prompt-response masking); different tokenizer (vocab 2,393). † Single seed, 10K steps (2K more than others) — not a controlled comparison. ★ Proposed in this work.

faster training — MLPEdge vs KATprey
1.8×
faster inference — MLPEdge vs KATprey
0.2762
best val loss — GR-KAN (single seed)
§4 · MLPEdge — Proposed Variant

Our Contribution: MLPEdge

Keep the KAN topology — additive decomposition per edge — but replace the B-spline basis with a tiny learned MLP ($\mathbb{R}\to\mathbb{R}$).

$$\mathbf{H} = \sigma\bigl(\text{einsum}(\mathbf{x}, W_1) + b_1\bigr) \;\in \mathbb{R}^{B\times d_\text{in}\times h}$$ $$\text{out} = \text{einsum}(\mathbf{H}, W_2) + b_\text{out}$$

The einsum structure is identical to KANLinear's spline path. Each $f_{i,j}(x)$ remains a visualizable 1D scalar function. No grid update needed.

# B-spline path          vs   MLP-edge path
splines = b_splines(x)          H = σ(einsum("bi,ih→bih", x, W1) + b1)
out = einsum("bik,oik→bo",      out = einsum("bih,oih→bo", H, W2)
             splines, W_spline)

Hidden size $h$ ablation

h = 1
0.2828
h = 2
0.2836
h = 5
0.2854
h = 10
0.2863
h = 20
0.2886

Bars show quality (inverted: shorter = worse). Lower val loss is better.

Why does h = 1 win?

Larger per-edge networks overfit on this 60K dataset. A single learned scalar transformation per edge channel is sufficient. The sweet spot is $h\in\{1,2\}$.

§4 · GR-KAN (Yang & Wang, ICLR 2025)

Group-Rational KAN: GR-KAN

Safe Padé rational activation

$$F(x) = \frac{a_0 + a_1 x + \cdots + a_m x^m}{1 + \left|b_1 x + \cdots + b_n x^n\right|}$$
  • Numerator $\{a_k\}$ — shared across all groups
  • Denominator $\{b_k\}$ — per group (g=8 groups)
  • Denominator $\geq 1$ everywhere — numerically safe
  • $m=5$, $n=4$: only $(m{+}1)+n{\cdot}g=38$ extra params over an equivalent MLP

GR-KAN FFN structure

GroupRational rat₁  (init: identity)
Linear(d_model → 4 × d_model)
GroupRational rat₂  (init: Swish)
Linear(4 × d_model → d_model)

Why rational functions?

  • GPU-friendly: pure tensor ops — no Cox-de Boor recursion
  • Smooth everywhere: no knot discontinuities
  • Expressive: Padé approximants converge faster than polynomials of the same degree
  • Fused CUDA kernel available via rational_kat_cu — fixes backward-pass memory bottleneck identified in FlashKAT (arXiv 2505.13813)

Initialization

rat₁ → identity; rat₂ → Swish (least-squares fit on $[-4,4]$). This enables weight transfer from pre-trained MLP transformers.

At GuppyLM scale

GR-KAN achieves val loss 0.2762 and 545 ms inference — best of all models. Single seed, 10K steps — not directly controlled.

Part Five

Interpretability Study

What do 884,736 KAN edge functions actually learn?

§5 · Interpretability Study

Characterizing 884,736 Edge Functions

Reconstruction

Each edge $f_{i,j}(x)$ is reconstructed from model weights:

$$f_{i,j}(x) = W_\text{base}[j,i]\cdot\text{SiLU}(x) + \sum_k W_\text{spline}[j,i,k]\cdot B_{i,k}(x)$$

Evaluated on 200 points from each channel's grid range.


Three per-function metrics

MetricDefinition
NLS (nonlinearity)$\|f - f_\text{lin}\|_2 / (\|f\|_2 + \varepsilon)$
Activity$\|f\|_2 / \sqrt{n}$
Roughnessmean $|\Delta^2 f|$

MLP effective edge functions

$$f_{i,j}^\text{MLP}(x) = W_2[j,:]\cdot\text{ReLU}(W_1[:,i]\cdot x + b_1)$$

Scalar contribution of input channel $i$ to output $j$, all other channels at zero. Sampled on $[-2,2]$.

87.8%
nonlinear edges (NLS > 0.1)
0.4%
dead edges (activity ≤ 0.01)

NLS consistency across layers

LayerKAN median NLSMLP median NLS
10.2790.266
20.2810.268
30.2800.271
40.2820.269
50.2790.267
60.2810.268
Statistical caveat

Mann-Whitney U test gives $p<10^{-300}$ (KAN > MLP). But edges within a layer share the same B-spline grid, violating independence. Read as descriptive, not inferential.


Functional PCA

Top-4 components explain 99.9% of variance per layer (PC1: 60–62%, PC2: 30–32%, PC3: 7%, PC4: <0.3%). Note: $n_\text{basis}=8$ means the function space is at most 8-dimensional — this is partly parametric.

Part Six

Scaling Up:
GPT-2 Scale & GR-KAN 30M

Does the KAN advantage hold at GPT-2 size? What happens when you chain trained units?

§6 · Two GPT-2 Scale Experiments

Scale Separates Topology from Basis

Experiment A — MLPEdge · WikiText-103

124M params · RTX A6000 · 20K steps · metric: perplexity

ModelVal ppl ↓tok/s
MLP (GELU)16.5854,820
MLPEdge (h=8)20.9648,921

−26% — per-edge factored topology fails at scale

  • einsum overhead: 11% throughput penalty
  • Same $h=8$ per-edge budget is underpowered for WikiText-103 complexity at $d=768$

Experiment B — GR-KAN · ClimbMix

286M params · H100 NVL · 2520 steps · metrics: bpb + DCLM CORE

ModelVal bpb ↓CORE ↑tok/s
MLP (SwiGLU)0.84740.1540~508K
GR-KAN (g=8, canonical)0.88340.1286~290K

bpb gap ~4.2% · CORE gap −0.025 · canonical formula

Implementation correction

Earlier GR-KAN results used a per-coefficient-abs denominator (bug). Canonical Safe Padé: $Q(x)=1+|b_0x+b_1x^2+b_2x^3+b_3x^4|$. Gap widened from ~1.2% to ~4.2%. COPA advantage was an artifact.

Engineering prerequisite

~480 CUDA kernel launches/step → 10 s/step, 5.6% MFU. Fused Triton backward kernel: 2.87 s/step, 19.4% MFU — 3.5× speedup.

The canonical GR-KAN gap (4.2% BPB, −0.025 CORE) is wider than initially reported but still substantially narrower than MLPEdge's 26% gap. Rational activations remain more favorable than per-edge MLPs at scale — though the evidence is weaker than previously claimed.

§6 · ModuleChain — Staged Depth Scaling

GR-KAN at 30M: Staging Mismatch

Can we progressively add depth by training units independently, then chaining them?

Unit-0 (3 layers)

24.7M params
Trained 10K steps

64.21

WT103 ppl · LAMBADA 87%

Staged only

Unit-1 appended,
no joint fine-tuning

71.73 ↑

LAMBADA 58% ↓

Joint 10K steps

Full 6L, 30M params,
joint training

66.19

LAMBADA 72%

Joint 20K steps ✓

Full 6L, 30M params

59.22

LAMBADA 95%

Staging mismatch

Appending fresh unit-1 layers atop trained unit-0 degrades performance: perplexity rises from 64.21 to 71.73 (+7.5 points) and LAMBADA accuracy drops from 87% to 58%. Unit-0's output distribution is not a suitable input domain for randomly initialized unit-1 layers.

Joint fine-tuning is essential

20K joint steps recover and surpass the single-unit baseline. The staged approach only pays off when followed by joint fine-tuning for at least as many steps as unit-0 training. Omitting it not only wastes the staged investment — it actively harms the model.

§6 · Final Benchmark Results

GR-KAN 30M: Benchmark Results

ModelParamsWT103 ppl↓LAMBADAARC-EasyHellaSwag
unit0 (3L)24.7M64.2187.0%28.62%25.48%
unit1 staged30M71.7358.0%28.62%25.04%
unit1 joint 10k30M66.1972.0%28.11%25.10%
unit1 joint 20k30M59.2295.0%29.55%25.32%
OPT-125M ★125M22.87%

★ Zhang et al. 2022, lm-harness zero-shot, different training data — indicative only.
Eval time: 287.2 s on MPS device.


Muon optimizer

Newton-Schulz-5 orthogonalization of the momentum buffer for 2D weight matrices. Active on CUDA only; falls back to AdamW on MPS/CPU. Converges ~2× faster per token vs AdamW, halving cloud compute cost.

GR-KAN at 30M params outperforms OPT-125M on ARC-Easy — 29.55% vs 22.87% — at 4× fewer parameters.

59.22
WT103 perplexity — unit1 joint 20k
95%
LAMBADA accuracy after joint FT
Part Seven

Advanced Architectures:
MoE GR-KAN & LoopGRKAN

Sparse mixture-of-experts and recurrent depth via Ouro + EqR

§7 · Sparse Mixture-of-Experts GR-KAN

MoE GR-KAN

Architecture

Each transformer block replaces the single GR-KAN FFN with 8 independent GR-KAN expert FFNs. A linear router selects the top-2 experts per token:

$$\text{out}(x) = \sum_{k\,\in\,\text{top-2}(g(x))} g_k(x)\cdot E_k(x)$$

Active FLOPs ≈ top_k / n_experts = 25% of dense GR-KAN.


Load balance loss

$$\mathcal{L}_\text{lb} = \alpha\cdot N_e\sum_{i=1}^{N_e} f_i\cdot P_i$$

$f_i$ = fraction of tokens routed to expert $i$; $P_i$ = avg router probability. Encourages uniform expert utilization; prevents collapse.

Configuration

n_experts8
top_k per token2
Load balance coeff0.01
RouterLinear(d_model, n_experts)

Expected benefits

  • Parameter efficiency: 8 specialized experts, only 2 active per token
  • Each expert can specialize in different token types or syntactic contexts
  • Combines GR-KAN's rational expressiveness with conditional computation
Status

Full benchmarks not yet collected — this is an open experimental thread. Initial training shows convergence comparable to dense GR-KAN.

§7 · LoopGRKAN (Ouro + EqR)

LoopGRKAN: Recurrent Depth

Ouro architecture (arXiv 2510.25741)

The same GR-KAN body is applied $T_\text{max}$ times — weight-tied, like an RNN at the transformer-block level:

$$x_t = \text{body}(x_{t-1}), \quad \lambda_t = \sigma\bigl(\text{gate}(\bar{x}_t)\bigr)$$
  • $\lambda_t$ = per-step exit probability
  • Inference exits when $\text{CDF} > 0.8$ or after $T_\text{max}=4$ steps

Training objective

$$\mathcal{L} = \sum_t p_\phi(t|x)\cdot\mathcal{L}_\text{LM}^{(t)} - \beta\cdot H(p_\phi(\cdot|x))$$

The entropy term $H$ prevents the exit distribution from always using $T_\text{max}$ steps — encouraging adaptive compute allocation.

EqR enhancements (arXiv 2605.21488)

  • RI (Random Init): $z_0\sim\mathcal{N}(0,\sigma^2 I)$ added at embedding — breaks symmetry, enables breadth scaling
  • NI (Noisy Iteration): $x_{t+1} = x_t + (1{-}\lambda)(\text{body}(x_t){-}x_t) + \beta\varepsilon$ — shapes attractor landscape

Breadth scaling

Run $B=4$ independent RI restarts at inference; select by lowest mean residual $\|x_t - x_{t-1}\|$. Trades latency for quality at test time — no retraining needed.


Why loop a GR-KAN?

  • Rational functions define a smooth dynamical system — convergence is more stable than with splines
  • Weight tying reduces parameters while increasing effective depth
  • Exit gate learns adaptive compute: simple tokens exit early
Part Eight

Discussion &
Open Questions

§8 · Summary

What We Learned

  • Masking is critical. Computing loss on all tokens dilutes signal by 31%. Architectural comparisons without it are unreliable.
  • KAN topology matters more than the basis at small scale. MLPEdge matches B-spline KAN quality at 4× faster training, no grid update.
  • KAT attention helps quality but costs speed. 14–15/16 accuracy vs 8/16 for dot-product, but 1.4× more inference latency.
  • GR-KAN is the best FFN replacement. 30M params beats OPT-125M on ARC-Easy at 4× fewer params. At 286M params (g=8), only ~1.2% behind MLP on ClimbMix bpb, and 6.6% behind on DCLM CORE — with a striking +0.12 advantage on COPA.
  • MLPEdge does not scale; GR-KAN does. MLPEdge is 26% worse than MLP at GPT-2 scale. GR-KAN is only ~1.2% worse on bpb — same scale, same protocol. Rational activations are what scales, not the per-edge factored topology.
  • GR-KAN trails MLP at GPT-2 scale. Canonical Safe Padé formula: val_bpb 0.8834 vs 0.8474 (+4.2%), CORE 0.1286 vs 0.1540 (−0.025). MLP leads 20 of 22 tasks. The ~1.2% gap previously reported was inflated by a per-coefficient-abs denominator bug — now corrected.
  • MLPEdge does not scale; GR-KAN partially does. MLPEdge is 26% worse than MLP at GPT-2 scale. GR-KAN is ~4.2% worse — same scale, same protocol. Rational activations are more favorable than per-edge MLPs, but the gap is larger than initially believed.

Still open

  • GR-KAN at 286M is ~1.2% behind MLP on bpb; g=8 narrows the gap vs g=4. Does the trend continue at g=16? Can longer training close the 6.6% CORE gap? Ablations queued.
  • COPA anomaly (+0.12 for GR-KAN): only 100 examples — needs replication on larger causal reasoning benchmarks.
  • Can MLPEdge close the GPT-2 gap with higher $h$? Untested.
  • MoE GR-KAN full benchmarks — in progress.
  • Symbolic regression on rational edge functions — planned.
  • ModuleChain staging recipe at 286M scale — next run.

Honest caveats

  • GR-KAN GuppyLM result: single seed, 2K extra steps — not controlled
  • GR-KAN 286M result: 2520 steps, ~1.32B tokens only; longer training may change the bpb and CORE gaps
  • GR-KAN 286M result: 2520 steps, ~1.32B tokens only, single seed; longer training may change the bpb and CORE gaps
  • Mann-Whitney $p$-value: edges share grids — not inferential
§8 · Next Steps

Future Work

Near term

  • Complete MoE GR-KAN benchmarks (WT103, ARC, HellaSwag)
  • Fully benchmark LoopGRKAN adaptive compute and reasoning capabilities
  • Multi-seed controlled comparison for GR-KAN vs MLP at GuppyLM scale
  • Update paper with canonical GR-KAN GPT-2 scale results and formula correction

Research questions

  • Do rational activations close the GPT-2 gap for KAN-topology models?
  • Symbolic regression on GR-KAN rational edge functions
  • Pruning circuits: which edges determine fish-domain vs generic behavior?
  • Token-conditioned activation atlases for KAN edges

Scale

  • Train GR-KAN at 125M+ params on a richer corpus (Pile subset)
  • Test weight transfer: init GR-KAN from pre-trained MLP weights (KAT paper recipe)
  • LoopGRKAN breadth scaling evaluation at inference time
  • MoE routing patterns as an interpretability signal

KANs bring genuine interpretability machinery to language models. The rational basis achieves this with negligible parameter overhead. But the architectural advantage is scale-dependent — understanding the crossover point is the most valuable next step.



Thank you.

Questions, discussion, and access to all code and checkpoints at

ACS-USP/kanprey-lm


884K
edge functions studied
59.22
WT103 ppl at 30M
29.6%
ARC-Easy at 30M params
~1.2%
bpb gap vs MLP at 286M

Liu et al. 2024 — KAN Yang & Wang 2025 — KAT / GR-KAN Blealtan 2024 — EfficientKAN Jordan 2024 — Muon Ouro arXiv 2510.25741 EqR arXiv 2605.21488