Fast B-spline Kolmogorov-Arnold Network layers for PyTorch.
Drop-in nn.Linear replacement with learnable spline activations.
click to copy
In a standard MLP, each connection has a fixed weight and a shared activation function. In a Kolmogorov-Arnold Network, each edge has its own learnable univariate function φ(x) — a B-spline curve that transforms the scalar flowing along that edge.
Each φji is a learned cubic B-spline with local support: changing one coefficient affects the function over only ~4 knot intervals. This makes KANs inherently more interpretable and editable than MLPs.
Stable piecewise polynomial evaluation instead of recursive Cox-de Boor. Local 4-basis lookup instead of dense K-basis computation.
KANLayer(in, out) replaces nn.Linear(in, out).
Same interface, same optimizer, same training loop.
Guaranteed non-negative basis output. Float32 accuracy ~1.2e-7. No catastrophic cancellation from alternating sums.
Univariate spline layers plus tensor-product B-spline surfaces for joint function approximation.
import torch
from inkan import KANLayer, KANNetwork
# Single layer — drop-in for nn.Linear
layer = KANLayer(8, 4)
x = torch.randn(32, 8)
y = layer(x) # [32, 4]
# Multi-layer network
net = KANNetwork([784, 64, 10])
x = torch.randn(32, 784)
y = net(x) # [32, 10]
# Standard PyTorch training
optimizer = torch.optim.Adam(net.parameters(), lr=1e-3)
loss = y.sum()
loss.backward()
optimizer.step()
| Method | Grid Size 8 | Grid Size 20 | Grid Size 50 |
|---|---|---|---|
| Cox-de Boor (recursive) | 1.0x | 1.0x | 1.0x |
| InKAN (piecewise + local) | 2.8x faster | 3.9x faster | 5.4x faster |
Attention Manifolds — Learned B-spline coordinate curves for AI safety and mechanistic interpretability in transformer attention. Per-coordinate spline curves on Q/K projections, trained on Llama-3.2-1B and 3B.