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
~60 min
From a 1957 theorem on superpositions to a new class of neural network
Every continuous function $f:[0,1]^n \to \mathbb{R}$ can be written as a finite superposition of continuous univariate functions.
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.
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.
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.
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.
grid_size + spline_order per input channelAfter warm-up (step 500), knot positions adapt to the quantile distribution of actual activations — a once-per-training, non-differentiable operation.
| Component | Shape | Count |
|---|---|---|
| $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
Replace linear Q, K projections with KANLinear feature maps $\varphi$, turning the dot-product similarity into a learned kernel:
Applied per-head on head_dim=64, not d_model=384. V and output projection remain standard linear layers.
| Hyperparameter | Value |
|---|---|
| $d_\text{model}$ | 384 |
| Layers / heads | 6 / 6 (head_dim = 64) |
| Max seq length | 128 |
| Vocab (BPE) | 2,393 |
| Params (approx.) | 9–10M depending on variant |
| Setting | Value |
|---|---|
| Steps / batch | 8,000 / 32 |
| Optimizer | AdamW (β₁=0.9, β₂=0.95, λ=0.1) |
| LR schedule | Cosine 3×10⁻⁴ → 3×10⁻⁵ |
| Grid update | Step 500 (KAN/KAT only) |
arman-bd/guppylm-60k-generic — 60K instruction-response pairs in ChatML format. First-person fish-personality chatbot. BPE tokenizer trained on same corpus.
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.
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.
Masking, B-spline KAN, MLPEdge, KAT attention, and GR-KAN
| Training objective | Val loss | Role-marker in responses |
|---|---|---|
| All tokens (no masking) | 0.4202 | Yes |
| Assistant tokens only | 0.2870 | No |
Any architectural comparison without prompt-response masking measures training objective design, not architecture quality.
| Model | FFN | Attention | Val loss | Eval / 16 | Latency | Params | Train time |
|---|---|---|---|---|---|---|---|
| GuppyLM (MLP) ‡ | Linear → ReLU → Linear | dot-product | 0.3892 | 8–9 | ~180 ms | 8.7M | ~8 min |
| KANpreyLM | KANLinear (B-spline) | dot-product | 0.2894 | 8 | ~880 ms | 9.8M | ~19 min |
| KATpreyLM | KANLinear (B-spline) | KAT | 0.2867 | 13–15 | ~1200 ms | 10.2M | 43 min |
| MLPEdgepreyLM ★ | MLP-per-edge | dot-product | 0.2854 | 14 | ~680 ms | 9.0M | 10 min |
| GR-KANpreyLM † | GroupRational (Safe Padé) | dot-product | 0.2762 | — | 545 ms | 11.6M | 59 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.
Keep the KAN topology — additive decomposition per edge — but replace the B-spline basis with a tiny learned MLP ($\mathbb{R}\to\mathbb{R}$).
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)
Bars show quality (inverted: shorter = worse). Lower val loss is better.
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\}$.
rational_kat_cu — fixes backward-pass memory bottleneck identified in FlashKAT (arXiv 2505.13813)rat₁ → identity; rat₂ → Swish (least-squares fit on $[-4,4]$). This enables weight transfer from pre-trained MLP transformers.
GR-KAN achieves val loss 0.2762 and 545 ms inference — best of all models. Single seed, 10K steps — not directly controlled.
What do 884,736 KAN edge functions actually learn?
Each edge $f_{i,j}(x)$ is reconstructed from model weights:
Evaluated on 200 points from each channel's grid range.
| Metric | Definition |
|---|---|
| NLS (nonlinearity) | $\|f - f_\text{lin}\|_2 / (\|f\|_2 + \varepsilon)$ |
| Activity | $\|f\|_2 / \sqrt{n}$ |
| Roughness | mean $|\Delta^2 f|$ |
Scalar contribution of input channel $i$ to output $j$, all other channels at zero. Sampled on $[-2,2]$.
| Layer | KAN median NLS | MLP median NLS |
|---|---|---|
| 1 | 0.279 | 0.266 |
| 2 | 0.281 | 0.268 |
| 3 | 0.280 | 0.271 |
| 4 | 0.282 | 0.269 |
| 5 | 0.279 | 0.267 |
| 6 | 0.281 | 0.268 |
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.
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.
Does the KAN advantage hold at GPT-2 size? What happens when you chain trained units?
124M params · RTX A6000 · 20K steps · metric: perplexity
| Model | Val ppl ↓ | tok/s |
|---|---|---|
| MLP (GELU) | 16.58 | 54,820 |
| MLPEdge (h=8) | 20.96 | 48,921 |
−26% — per-edge factored topology fails at scale
286M params · H100 NVL · 2520 steps · metrics: bpb + DCLM CORE
| Model | Val bpb ↓ | CORE ↑ | tok/s |
|---|---|---|---|
| MLP (SwiGLU) | 0.8474 | 0.1540 | ~508K |
| GR-KAN (g=8, canonical) | 0.8834 | 0.1286 | ~290K |
bpb gap ~4.2% · CORE gap −0.025 · canonical formula
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.
~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.
Can we progressively add depth by training units independently, then chaining them?
24.7M params
Trained 10K steps
WT103 ppl · LAMBADA 87%
Unit-1 appended,
no joint fine-tuning
LAMBADA 58% ↓
Full 6L, 30M params,
joint training
LAMBADA 72%
Full 6L, 30M params
LAMBADA 95%
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.
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.
| Model | Params | WT103 ppl↓ | LAMBADA | ARC-Easy | HellaSwag |
|---|---|---|---|---|---|
| unit0 (3L) | 24.7M | 64.21 | 87.0% | 28.62% | 25.48% |
| unit1 staged | 30M | 71.73 | 58.0% | 28.62% | 25.04% |
| unit1 joint 10k | 30M | 66.19 | 72.0% | 28.11% | 25.10% |
| unit1 joint 20k | 30M | 59.22 | 95.0% | 29.55% | 25.32% |
| OPT-125M ★ | 125M | — | — | 22.87% | — |
★ Zhang et al. 2022, lm-harness zero-shot, different training data — indicative only.
Eval time: 287.2 s on MPS device.
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.
Sparse mixture-of-experts and recurrent depth via Ouro + EqR
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:
Active FLOPs ≈ top_k / n_experts = 25% of dense GR-KAN.
$f_i$ = fraction of tokens routed to expert $i$; $P_i$ = avg router probability. Encourages uniform expert utilization; prevents collapse.
| n_experts | 8 |
| top_k per token | 2 |
| Load balance coeff | 0.01 |
| Router | Linear(d_model, n_experts) |
Full benchmarks not yet collected — this is an open experimental thread. Initial training shows convergence comparable to dense GR-KAN.
The same GR-KAN body is applied $T_\text{max}$ times — weight-tied, like an RNN at the transformer-block level:
The entropy term $H$ prevents the exit distribution from always using $T_\text{max}$ steps — encouraging adaptive compute allocation.
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.
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.
Questions, discussion, and access to all code and checkpoints at