{"id":50596626,"url":"https://github.com/Mattral/KANX","last_synced_at":"2026-06-22T10:00:38.660Z","repository":{"id":238079653,"uuid":"795826428","full_name":"Mattral/KANX","owner":"Mattral","description":"One library, four surfaces. Production-grade Kolmogorov-Arnold Networks || TensorFlow + PyTorch + ONNX. || A small KAN beats a 10× larger MLP on smooth, separable target. One library. Two backends. Real ONNX export. Docker + Kubernetes ready.","archived":false,"fork":false,"pushed_at":"2026-06-19T11:41:09.000Z","size":4146,"stargazers_count":30,"open_issues_count":1,"forks_count":8,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-06-19T12:09:24.802Z","etag":null,"topics":["deep-learning","gpu-acceleration","interpretability","kan","kolmogorov-arnold-networks","machine-learning","neural-networks","onnx","production-ml","symbolic-regression","tensorflow"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Mattral.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":"CITATION.cff","codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":"roadmap.md","authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-05-04T07:04:18.000Z","updated_at":"2026-06-19T11:41:13.000Z","dependencies_parsed_at":"2024-05-04T08:22:29.523Z","dependency_job_id":"5b69d7fe-db93-49fd-9a92-bec8e905d4ed","html_url":"https://github.com/Mattral/KANX","commit_stats":null,"previous_names":["mattral/kolmogorov-arnold-networks","mattral/kanx"],"tags_count":7,"template":false,"template_full_name":null,"purl":"pkg:github/Mattral/KANX","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mattral%2FKANX","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mattral%2FKANX/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mattral%2FKANX/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mattral%2FKANX/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Mattral","download_url":"https://codeload.github.com/Mattral/KANX/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Mattral%2FKANX/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34643624,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-22T02:00:06.391Z","response_time":106,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deep-learning","gpu-acceleration","interpretability","kan","kolmogorov-arnold-networks","machine-learning","neural-networks","onnx","production-ml","symbolic-regression","tensorflow"],"created_at":"2026-06-05T15:00:20.424Z","updated_at":"2026-06-22T10:00:38.654Z","avatar_url":"https://github.com/Mattral.png","language":"Python","funding_links":[],"categories":["Library"],"sub_categories":["Theorem"],"readme":"\u003ch1 align=\"center\"\u003e🚀 kanx\u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cstrong\u003eProduction-grade Kolmogorov-Arnold Networks\u003c/strong\u003e\u003cbr\u003e\n  \u003cem\u003eTensorFlow + PyTorch + ONNX — one library, four surfaces. \u003c/em\u003e\u003cbr\u003e\n  \u003cem\u003e \u003e `kanx` is the only Kolmogorov-Arnold Network (KAN) library purpose-built for production deployment.\u003c/em\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://pypi.org/project/kanx/\"\u003e\u003cimg alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/kanx?style=for-the-badge\u0026logo=pypi\u0026logoColor=white\u0026color=7C3AED\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://pypi.org/project/kanx/\"\u003e\u003cimg alt=\"Downloads\" src=\"https://img.shields.io/pypi/dm/kanx?style=for-the-badge\u0026color=A78BFA\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://pepy.tech/project/kanx\"\u003e  \u003cimg alt=\"Total Downloads\" src=\"https://img.shields.io/pepy/dt/kanx?style=for-the-badge\u0026color=F87171\"\u003e\u003c/a\u003e\n  \u003ca href=\"./CITATION.cff\"\u003e\u003cimg alt=\"Cite\" src=\"https://img.shields.io/badge/cite-CITATION.cff-brightgreen?style=for-the-badge\"\u003e\u003c/a\u003e\n\n  \u003cimg alt=\"Python\" src=\"https://img.shields.io/pypi/pyversions/kanx?style=for-the-badge\u0026logo=python\u0026logoColor=white\"\u003e\n  \u003ca href=\"https://mattral.github.io/KANX/\"\u003e\u003cimg alt=\"Docs\" src=\"https://img.shields.io/badge/docs-mkdocs--material-22C55E?style=for-the-badge\u0026logo=readthedocs\u0026logoColor=white\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://colab.research.google.com/github/Mattral/KANX/blob/main/notebooks/quickstart.ipynb\"\u003e\u003cimg alt=\"Colab\" src=\"https://img.shields.io/badge/Colab-train_in_2_to_5_min-F9AB00?style=for-the-badge\u0026logo=googlecolab\u0026logoColor=white\"\u003e\u003c/a\u003e\n  \u003ca href=\"./LICENSE\"\u003e\u003cimg alt=\"License\" src=\"https://img.shields.io/badge/license-Apache--2.0-A78BFA?style=for-the-badge\"\u003e\u003c/a\u003e\n  \u003ca href=\"https://doi.org/10.5281/zenodo.20615396\"\u003e\n    \u003cimg alt=\"DOI\" src=\"https://img.shields.io/badge/DOI-10.5281%2Fzenodo.20430883-7C3AED?style=for-the-badge\u0026logo=zenodo\u0026logoColor=white\"\u003e\n  \u003c/a\u003e\n\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"docs/assets/benchmark.png\" alt=\"KAN vs MLP benchmark\" width=\"720\"/\u003e\n\u003c/p\u003e\n\n\u003e **`pip install kanx`** \u0026nbsp;·\u0026nbsp; A small KAN beats a 10× larger MLP on smooth, separable targets — **honest, param-matched benchmark below.**\n\u003e One library. Two backends. Real ONNX export. Docker + Kubernetes ready. Prometheus metrics, TensorBoard logging, Hub and symbolic extras are now implemented.\n\n---\n\n\n## ⭐ Why kanx?\n\u003cdiv align=\"center\"\u003e\n\nEvery other KAN library stops at research. `kanx` goes the full distance:\n\n| | [pykan](https://github.com/KindXiaoming/pykan) | [efficient-kan](https://github.com/Blealtan/efficient-kan) | [mlx-kan](https://github.com/Goekdeniz-Guelmez/mlx-kan) | **kanx** |\n|---|:---:|:---:|:---:|:---:|\n| Framework         | PyTorch | PyTorch | MLX (Apple Silicon) | **TF + PyTorch** |\n| Vectorized B-spline | partial | ✅ | ✅ | ✅ |\n| ONNX export       | ❌ | ❌ | ❌ | ✅ **both backends** |\n| REST API service  | ❌ | ❌ | ❌ | ✅ FastAPI |\n| Docker + K8s      | ❌ | ❌ | ❌ | ✅ |\n| Property-based tests | ❌ | ❌ | ❌ | ✅ Hypothesis |\n| Test coverage     | research | research | research | **94%** |\n| PyPI              | ✅ | ✅ | ✅ | ✅ |\n| CI/CD release pipeline | ❌ | ❌ | ❌ | ✅ PyPI + GHCR + Pages |\n\n\u003c/div\u003e\n\nMost of the other KAN implementations are strictly academic. `KANX` bridges the gap between theory and reality by providing:\n1. **Multi-Backend Support:** Native TensorFlow and PyTorch (`MatrixKAN`) implementations.\n2. **Real Deployment:** True ONNX export, FastAPI (`/api/predict`), Docker, and Kubernetes configs out-of-the-box.\n3. **High-Throughput Options:** Vectorized `MatrixKAN` to replace recursive B-splines with batched GEMMs for GPU acceleration.\n4. **Grid Calibration:** Native adaptive and static grid fitting to prevent out-of-bounds input collapse.\n\n\n---\n\n## 📊 Benchmarks (reproducible, fair, multi-baseline)\n\n\u003cdiv align=\"center\"\u003e\n  \nSynthetic 2-D regression target `y = sin(π·x₁) + cos(2π·x₂)`,\n100 epochs, Adam(lr=1e-2), batch=128, CPU.\n\n\n| Model              | Params | Train (s) | Infer 4k (ms) | **Test MSE** |\n|--------------------|------:|---------:|-------------:|-------------:|\n| **KAN[2,16,1]**    |   432 |    12.50 |        68.64 | **2.14 × 10⁻⁵** |\n| KAN[2,32,1]        |   864 |    16.62 |        25.52 | 4.44 × 10⁻⁴ |\n| MLP[2,32,1]        |   129 |     5.07 |         6.17 | 4.61 × 10⁻¹ (undersized) |\n| MLP[2,16,16,1]     |   337 |     5.46 |         4.08 | 1.60 × 10⁻³ |\n| MLP[2,64,64,1]     | 4 417 |     6.00 |         5.74 | 5.51 × 10⁻⁴ |\n\n\u003c/div\u003e\n\n**Honest read.** The smallest KAN (432 params) wins on this smooth separable\ntarget. The same KAN is ~10–15× *slower at inference* than a same-MSE MLP\nbecause each edge does a B-spline evaluation. On non-smooth or\nhigh-dimensional targets, this picture often reverses. We do not claim KANs\nare universally better than MLPs.\n\nReproduce with `python benchmarks/compare_mlp.py` (quick, 100 epochs) or\n`python benchmarks/compare_mlp.py --long` (1000 epochs + early-stopping).\n\n---\n\n## ⚡ The 30-second magic moment\n\n```python\nimport kanx\n\n# Build, train, predict — in one call. No config files. No compile dance.\nmodel = kanx.quickstart()                       # trains on synthetic 2-D data\nmodel.predict([[0.5, 0.2]])                     # → array([[1.04…]])\n```\n\n\u003e **⚠️ Grid calibration — two methods**\n\u003e \n\u003e KANs use B-splines on a fixed input range (default `[-1, 1]`). If your inputs fall outside that range, the spline path **silently returns zero** and you only get the SiLU residual. Fix it one of two ways:\n\u003e \n\u003e **Static approach** (pre-training):\n\u003e ```python\n\u003e from kanx import KAN, fit_grid_to_data\n\u003e model = KAN([n_features, 64, 1])\n\u003e fit_grid_to_data(model, X_train)              # one-time grid fit\n\u003e model.fit(X_train, y_train, epochs=30)\n\u003e ```\n\u003e \n\u003e **Adaptive approach** (during training — recommended):\n\u003e ```python\n\u003e model = KAN([n_features, 64, 1])\n\u003e model.fit(X_train, y_train, epochs=15)\n\u003e model.update_grid_from_samples(X_train)       # ← refine grid based on data\n\u003e model.fit(X_train, y_train, epochs=15)        # continue training\n\u003e ```\n\u003e \n\u003e `kanx.check_input_range(model, X)` will log a warning at inference if input exceeds the grid.\n\n---\n\nWant more control? Same simplicity, your data:\n\n```python\nfrom kanx import KAN\nimport numpy as np\n\nX = np.random.uniform(-1, 1, (1024, 2)).astype(\"float32\")\ny = np.sin(np.pi * X[:, :1]) + X[:, 1:2] ** 2\n\nmodel = KAN([2, 64, 1])\nmodel.fit(X, y, epochs=30, verbose=0)           # auto-compiles with Adam+MSE\nmodel.predict(X[:3])\n```\n\n---\n\n### 🔥 PyTorch? Same API.\n\n```python\nfrom kanx.torch import KAN\nimport torch\n\nmodel = KAN([2, 64, 1])\nX = torch.randn(1024, 2); y = torch.sin(torch.pi * X[:, :1])\nmodel.fit(X, y, epochs=30, lr=1e-2)             # one-liner, same semantics\nmodel.predict([[0.5, 0.2]])\n```\n\n---\n\n\n### ⚡ GPU-optimized MatrixKAN\n\nFor higher throughput on accelerators, use the vectorized `MatrixKAN` (replaces recursion with batched GEMM):\n\n```python\nfrom kanx.torch import MatrixKAN\n\nmodel = MatrixKAN([4, 32, 1])  # same interface as KAN\nmodel.fit(X, y, epochs=30)      # ~1.5–2× faster on GPU vs standard KAN\n```\n\n---\n\n## 📦 Installation\n\n```bash\npip install kanx                # core (TensorFlow)\npip install \"kanx[torch]\"       # +PyTorch backend\npip install \"kanx[onnx]\"        # +tf2onnx + onnxruntime\npip install \"kanx[api]\"         # +FastAPI service\npip install \"kanx[hub]\"         # +HuggingFace Hub integration\npip install \"kanx[symbolic]\"    # +Symbolic regression hooks\npip install \"kanx[all]\"         # everything (api + torch + onnx + hub + symbolic + dev + docs)\n```\n\nOptional extras:\n* `kanx[api]` adds FastAPI serving with `/metrics` Prometheus scraping.\n* `kanx[torch]` adds the PyTorch backend, `MatrixKAN`, and symbolic helpers.\n* `kanx[hub]` adds `push_to_hub()` / `from_pretrained()` for HuggingFace integration.\n* `kanx[symbolic]` adds `SymbolicFitter` for post-hoc edge function extraction.\n\n→ Open in Colab: **[Train a KAN in 2-to-5 minutes](https://colab.research.google.com/github/Mattral/KANX/blob/main/notebooks/quickstart.ipynb)**\n\n---\n\n\n\n## 🏗️ Production Serving\n\nWe include out-of-the-box serving. Simply install `kanx[api]` and run:\n\n```bash\n# Starts a FastAPI server with Prometheus scraping at /metrics\npython -m kanx.serve \n\n```\n\n**API Contract:**\n\n* `GET /api/health` - Liveness \u0026 model load source\n* `GET /api/info` - TF/Torch backend version and summary\n* `POST /api/predict` - Batched inference\n\n*For enterprise scaling, see our `/k8s` directory for Helm charts and Kubernetes manifests.*\n\n---\n\n## 🌐 REST API\n\n```bash\ndocker run --rm -p 8000:8000 ghcr.io/mattral/kanx:latest\n# or\nuvicorn api.app:app --port 8000\n```\n\n\u003cdiv align=\"center\"\u003e\n  \n| Method | Path           | Purpose |\n|-------:|:--------------|:--------|\n| `GET`  | `/api/health`  | Liveness + model load source |\n| `GET`  | `/api/info`    | Version + TF/Torch + model summary |\n| `GET`  | `/metrics`     | Prometheus scrape endpoint |\n| `POST` | `/api/predict` | Inference (single or batch) |\n| `POST` | `/api/load`    | Hot-swap checkpoint |\n| `POST` | `/api/reset`   | Re-init from `KANX_CONFIG` |\n\n\u003c/div\u003e\n\n```bash\ncurl -X POST http://localhost:8000/api/predict \\\n     -H 'content-type: application/json' \\\n     -d '{\"x\": [[0.1, -0.2], [0.5, 0.7]]}'\n```\n\nThe startup contract loads `KANX_CHECKPOINT` if it exists, otherwise falls\nback to a fresh model built from `KANX_CONFIG`. Boundaries are validated:\nwrong feature count → `400`, oversized batch → `413`, missing checkpoint → `404`.\n\n---\n\n## 🔄 ONNX export\n\n```python\n# From PyTorch\nfrom kanx.torch import KAN, export_onnx\nmodel = KAN([2, 64, 1])\nexport_onnx(model, \"kan.onnx\")\n```\n\n```python\n# From TensorFlow\nfrom kanx import KAN, export_onnx_tf\nimport tensorflow as tf\nmodel = KAN([2, 64, 1]); model(tf.zeros((1, 2)))\nexport_onnx_tf(model, \"kan.onnx\")\n```\n\n✔ Dynamic batch\n✔ Verified numerical consistency (1e-5)\n✔ Works with ONNX Runtime / TensorRT / OpenVINO\n\n---\n\n## 🐳 Docker / ☸️ Kubernetes\n\n```bash\ndocker run --rm -p 8000:8000 ghcr.io/mattral/kanx:latest\nkubectl apply -f k8s/    # Deployment + Service + Ingress + HPA + PVC\n```\n\nK8s manifests ship with rolling updates, readiness/liveness probes on\n`/api/health`, an HPA (2 ↔ 10 replicas, CPU-target 70%) and a PVC for the\nmodel registry.\n\n---\n\n## 🛠️ CLI\n\n```bash\npython -m kanx info                                          # versions\npython -m kanx train --config configs/default.yaml           # train\npython -m kanx predict --checkpoint model.keras --input X.json\n```\n\n---\n\n## ⭐ Quality\n\n- **95 tests** across 8 files — unit, integration, E2E, property-based, performance regression\n- **94% library coverage** (99% layers, 100% model)\n- **Hypothesis property tests**: partition of unity, shape invariants, gradient finiteness\n- **Numerical contracts**: ONNX parity within 1e-5, save/load roundtrip identity\n- **Performance regression alarms**: latency budgets on forward pass and predict\n- CI matrix: Python 3.10 / 3.11 / 3.12 + lint + Docker smoke + MkDocs build\n\n```bash\npytest tests/ -v --cov=src/kanx\n```\n\n---\n\n## 📚 Documentation\n\n\u003cdiv align=\"center\"\u003e\n\n→ **\u003chttps://mattral.github.io/KANX/\u003e** (MkDocs Material)\n\n| Page | What's inside |\n|------|---------------|\n| [Quickstart](https://mattral.github.io/KANX/quickstart/) | Train your first KAN in 60 seconds |\n| [Architecture](https://mattral.github.io/KANX/architecture/) | Package layout, module contracts |\n| [System Design](https://mattral.github.io/KANX/system_design/) | Serving topology, scaling, failure modes |\n| [REST API](https://mattral.github.io/KANX/api/) | Endpoint reference + curl examples |\n| [Testing](https://mattral.github.io/KANX/testing/) | Test pyramid, numerical invariants |\n| [Deployment](https://mattral.github.io/KANX/deployment/) | CI/CD, rollout, observability |\n| [Benchmarks](https://mattral.github.io/KANX/benchmarks/) | KAN vs MLP — methodology + numbers |\n\n\u003c/div\u003e\n\n---\n\n## 📄 Research Paper\n\nIf you use kanx in academic work, please cite both the original paper and\nthe library. \n\nOur work is formally documented and available as a preprint:\n\n- 📘 Title: *KANX: A Production-Grade Open-Source Library for Kolmogorov-Arnold Networks*\n- 📍 DOI: https://doi.org/10.5281/zenodo.20615396\n- 📂 Zenodo: https://zenodo.org/records/20430883\n- 📄 [Read Paper (preprint)](docs/preprint.pdf)\n- 📄 [Read Paper (ArXiv)](docs/KANX_ArXiv_Paper.pdf)\n\n\n\n### Citation\n\n```bibtex\n@article{mattral2026kanx,\n  title={KANX: A Production-Grade Open-Source Library for Kolmogorov-Arnold Networks},\n  author={Myet, Min Htet},\n  year={2026},\n  doi={10.5281/zenodo.20615396},\n  publisher={Zenodo}\n}\n\n@article{liu2024kan,\n  title   = {KAN: Kolmogorov-Arnold Networks},\n  author  = {Liu, Ziming and Wang, Yixuan and Vaidya, Sachin and Ruehle,\n             Fabian and Halverson, James and Soljačić, Marin and\n             Hou, Thomas Y. and Tegmark, Max},\n  journal = {arXiv preprint arXiv:2404.19756},\n  year    = {2024}\n}\n```\n\n### References\n\n- Liu et al., *KAN: Kolmogorov-Arnold Networks* — [arXiv:2404.19756](https://arxiv.org/abs/2404.19756)\n- The Kolmogorov-Arnold representation theorem ([Wikipedia](https://en.wikipedia.org/wiki/Kolmogorov%E2%80%93Arnold_representation_theorem))\n- B-splines \u0026 de Boor algorithm — [Carl de Boor (1972)](https://doi.org/10.1016/0021-9045(72)90080-9)\n\n---\n\n## 🤝 Contributing\n\nPRs welcome! See [`CONTRIBUTING.md`](CONTRIBUTING.md). Good places to start:\n\n- 🔖 [Good first issues](https://github.com/Mattral/KANX/labels/good%20first%20issue)\n- 🗺️ [`roadmap.md`](roadmap.md) — P0 / P1 / P2 backlog\n- 💬 [Discussions](https://github.com/Mattral/KANX/discussions)\n\n---\n\n## 📜 License\n\n[Apache 2.0](LICENSE). Use it. Ship it. Tell us when you do — we'd love to\nhear how kanx is being used in the wild.\n\n\u003cp align=\"center\"\u003e⭐ \u003cstrong\u003eStar the \u003ca href=\"https://github.com/Mattral/KANX\"\u003erepo\u003c/a\u003e\u003c/strong\u003e if kanx saved you time!\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMattral%2FKANX","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMattral%2FKANX","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMattral%2FKANX/lists"}