FlashKAN
Fast B-spline Kolmogorov-Arnold Network layers for PyTorch.
6-15x faster than standard Cox-de Boor implementations (PyKAN, efficient-kan), faster than Gaussian RBF alternatives (FastKAN) — while producing exact B-spline basis values with compact support, C2 continuity, and partition of unity.
How it works
Standard KAN implementations compute B-spline basis functions using the Cox-de Boor recursion — 3 sequential passes for cubic splines, each creating intermediate tensors. FlashKAN replaces this with the truncated power closed form:
N(u) = (1/6) [relu(u)³ - 4·relu(u-1)³ + 6·relu(u-2)³ - 4·relu(u-3)³ + relu(u-4)³]
This single expression computes exact B-spline values with no recursion, no span lookups, and no gather operations. torch.compile fuses all elementwise ops into one GPU kernel.
Installation
pip install flashkan
Requirements: Python >= 3.9, PyTorch >= 2.0
Supported devices: CPU, CUDA (NVIDIA), MPS (Apple Silicon)
From source
git clone https://github.com/NAVEENMN/flashkan.git
cd flashkan
pip install -e .
Quick start
import torch
from flashkan import KANLayer, KANNetwork
# Drop-in replacement for nn.Linear
layer = KANLayer(784, 64)
x = torch.randn(32, 784)
y = layer(x) # [32, 64]
# Multi-layer network
net = KANNetwork([784, 64, 10])
y = net(torch.randn(32, 784)) # [32, 10]
MNIST example
import torch
import torch.nn as nn
from flashkan import KANNetwork
model = KANNetwork([784, 64, 10])
optimizer = torch.optim.Adam(model.parameters(), lr=1e-3)
criterion = nn.CrossEntropyLoss()
# Standard PyTorch training loop
for images, labels in train_loader:
output = model(images.view(-1, 784))
loss = criterion(output, labels)
optimizer.zero_grad()
loss.backward()
optimizer.step()
See examples/ for complete runnable scripts.
API
KANLayer(in_features, out_features, grid_size=5, spline_order=3)
A single KAN layer. Drop-in replacement for nn.Linear.
| Parameter | Default | Description |
|---|---|---|
in_features |
— | Input dimension |
out_features |
— | Output dimension |
grid_size |
5 | Number of knot intervals (more = finer approximation) |
spline_order |
3 | B-spline degree (3 = cubic, recommended) |
grid_range |
(-1, 1) | Input range for the spline grid |
KANNetwork(layer_dims, grid_size=5, spline_order=3)
Stack of KAN layers.
# 3-layer KAN: 784 -> 128 -> 64 -> 10
net = KANNetwork([784, 128, 64, 10])
Benchmarks
Forward pass time (ms) on Apple M-series GPU (MPS), batch=256:
| Layer | MNIST (784→64) | FashionMNIST (784→64) | CIFAR-10 (3072→64) |
|---|---|---|---|
| FlashKAN (compiled) | 0.27 | 0.20 | 0.39 |
| FastKAN (Gaussian RBF) | 0.38 | 0.31 | 0.99 |
| NoGather (unrolled) | 0.99 | 1.02 | 4.85 |
| Vanilla (Cox-de Boor) | 1.69 | 1.67 | 5.98 |
FlashKAN is 6.3x faster than vanilla Cox-de Boor on MNIST and 15.3x faster on CIFAR-10.
Why it's fast
91% of a standard KAN forward pass is spent computing B-spline basis functions. FlashKAN eliminates this bottleneck:
| Approach | Basis cost | Why |
|---|---|---|
| Cox-de Boor (PyKAN) | 3 sequential GPU passes | Each pass depends on previous |
| Gaussian RBF (FastKAN) | 1 exp() call |
Fast but not a true B-spline |
| Truncated power (FlashKAN) | 1 fused kernel | clamp + multiply is cheaper than exp() |
B-spline properties preserved
Unlike Gaussian RBF approximations, FlashKAN computes exact B-spline basis values:
- Compact support — each basis function is exactly zero outside its knot span window
- C2 continuity — second derivatives are continuous at every knot
- Partition of unity — basis values sum to 1 at every point in the interior
- Non-negativity — all basis values are >= 0
Verified: max difference vs Cox-de Boor reference is < 5e-5 in float32.
Project structure
src/flashkan/
├── __init__.py # Public API
├── basis.py # Truncated power B-spline + torch.compile (core math)
├── layer.py # KANLayer
└── network.py # KANNetwork
4 source files. The core innovation is in basis.py — 30 lines of math.
Citation
If you use FlashKAN in your research, please cite:
@software{flashkan2026,
title={FlashKAN: Fast B-spline KAN Layers via Truncated Power Basis},
author={Mysore, Naveen},
year={2026},
url={https://github.com/NAVEENMN/flashkan}
}
License
MIT
Metadata
Release files for flashkan 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| flashkan-0.2.0.tar.gz | 13.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flashkan-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 25.3 kB
Release files / flashkan-0.2.0.tar.gz
| Download URL | flashkan-0.2.0.tar.gz |
|---|---|
| Size | 13.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bd277de98fc1b1f7242567f30ba1b2fbd18ed4ad8eac21400ecccca4810729f7
|
|
BLAKE2b-256 checksum How to use checksums |
cfc4678df85e33009aa979d19ba5dd1fbd4070d0edbda9d99dd33eea745bea97
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / flashkan-0.2.0-py3-none-any.whl
| Download URL | flashkan-0.2.0-py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d6968b372dec9cf3620081302a7087b4c662738748a34b5fcc018cc8b33a7c2c
|
|
BLAKE2b-256 checksum How to use checksums |
5f8d020e175c381e45b25cd0fa0717c3dbb1d3bdc3c28decf7f81e4be33fbb56
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Security for flashkan 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.