A Kolmogorov Arnold Network for Edge Devices
Project description
Micro Kolmogorov–Arnold Network (MicroKAN)
This repository contains a minimal Python implementation of the Kolmogorov–Arnold Network (KAN) architecture, adapted for edge devices such as the Raspberry Pi. It eliminates non-essential dependencies of the original KAN implementations and targets constrained systems.
Features
- Streamlined implementation requiring only PyTorch, NumPy, PyYAML, and tqdm.
- Verified on Raspberry Pi 3 Model B with Python 3.10.
- Removes heavy dependencies such as scikit-learn, pandas, matplotlib, and sympy.
Test Setup
- Raspberry Pi 3 Model B (ARMv7)
- Bullseye OS
- Python 3.10
- PyTorch 1.13
- NumPy 1.23
Installation
System packages
sudo apt-get update
sudo apt-get install --no-install-recommends \
python3 python3-pip libblas3 libgomp1 libopenblas0 python3-typing-extensions libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libgdbm-dev lzma lzma-dev tcl-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev wget curl make build-essential openssl
Python setup
See full tutorial at samwestby
curl https://pyenv.run | bash
# ...
pyenv install 3.10.12
pyenv shell 3.10.12
Python packages
python3.10 -m pip install \
https://github.com/maxisoft/pytorch-arm/releases/download/v1.0.0/numpy-1.23.5-cp310-cp310-linux_armv7l.whl \
https://github.com/maxisoft/pytorch-arm/releases/download/v1.0.0/torch-1.13.0a0+git7c98e70-cp310-cp310-linux_armv7l.whl \
https://github.com/maxisoft/pytorch-arm/releases/download/v1.0.0/PyYAML-6.0-cp310-cp310-linux_armv7l.whl
python3.10 -m pip install tqdm
MicroKAN
python3.10 -m pip install microkan
Example Usage
The API is nearly identical to the original pykan, except that auxiliary arguments related to file saving and verbose outputs have been removed. Refer to the original KAN documentation for detailed parameter options. Here is a working example of microkan:
from microkan import *
import os
set_seed(0)
model = KAN(width=[2, 1, 1], grid=3, k=3, seed=1).speed(compile=False)
f = lambda x: torch.exp(torch.sin(torch.pi * x[:, [0]]) + x[:, [1]] ** 2)
dataset = create_dataset(f, n_var=2, train_num=10, test_num=5)
model.fit(dataset, opt="LBFGS", steps=10)
print(model(dataset["test_input"]))
os.makedirs("microkan", exist_ok=True)
model.saveckpt("microkan/example_model")
# Loading example
loaded = KAN.loadckpt("microkan/example_model")
print(loaded(dataset["test_input"]))
Performance Timing
The table below reports mean inference times (± standard deviation) on a Raspberry Pi 3 Model B and an Intel Core i5-1235U, illustrating typical speed differences across varying KAN architectures.
| Architecture | Grid | k | RPI3 Time (ms) | PC Time (ms) |
|---|---|---|---|---|
| [6, 80, 3] | 9 | 1 | 19.5 ± 2.6 | 1.4 ± 0.4 |
| [6, 40, 55, 75, 3] | 5 | 2 | 98.6 ± 14.9 | 3.6 ± 1.0 |
| [6, 55, 65, 3] | 5 | 4 | 110.1 ± 13.2 | 3.6 ± 1.1 |
| [6, 45, 3] | 3 | 2 | 31.4 ± 4.4 | 1.2 ± 0.7 |
| [6, 80, 75, 3] | 3 | 4 | 116.1 ± 12.7 | 3.7 ± 1.0 |
| [6, 100, 65, 90, 3] | 3 | 2 | 113.6 ± 13.3 | 3.9 ± 1.1 |
Other Platforms
This implementation may also operate on platforms beyond ARMv7, provided that compatible PyTorch builds are available for the target architecture. However, these configurations have not been tested, and functionality or performance is not verified outside the specified ARMv7 environment.
Acknowledgments
- Based on PyEnv Python Version Manager.
- Original Kolmogorov–Arnold Network concept implemented in pykan.
- ARM builds of PyTorch and dependencies courtesy of maxisoft/pytorch-arm.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file microkan-0.1.0.tar.gz.
File metadata
- Download URL: microkan-0.1.0.tar.gz
- Upload date:
- Size: 32.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e846e03e42b1f527c1c121380137b8bc6efa14a34deecdd0d1538422f2d42e68
|
|
| MD5 |
7028feb908343ac02f1ccb866b28f4ec
|
|
| BLAKE2b-256 |
b09876fed6a5e260d3987149bca347a37ec9cd78711b2cda422b8222cfafb6a5
|
File details
Details for the file microkan-0.1.0-py3-none-any.whl.
File metadata
- Download URL: microkan-0.1.0-py3-none-any.whl
- Upload date:
- Size: 32.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f4fa6a918b9971a360766b75f896cd1ad938d2f024c948051bb6fd9f8302c022
|
|
| MD5 |
d92f4430716e0f9792da3bc910c6fcb2
|
|
| BLAKE2b-256 |
14901ab4dfbb1a7942fa4c492d43790d1d540603fcc79521661971b6d9860476
|