File size: 9,132 Bytes
e8f36d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
711fbc6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>InKAN β€” Fast B-Spline KAN Layers for PyTorch</title>
    <meta name="description" content="InKAN: Fast uniform cubic B-spline Kolmogorov-Arnold Network (KAN) layers for PyTorch. 2.8-5.4x faster than Cox-de Boor recursion. Drop-in nn.Linear replacement with learnable spline activations.">
    <meta name="keywords" content="inkan, KAN, Kolmogorov-Arnold Network, B-spline, PyTorch, neural network, deep learning, machine learning, learnable activation, spline, interpretable ML">
    <meta name="author" content="Naveen Mysore">
    <link rel="canonical" href="https://pypi.org/project/inkan/">
    <style>
        * { box-sizing: border-box; margin: 0; padding: 0; }
        body {
            font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Helvetica, Arial, sans-serif;
            background: #0d1117; color: #c9d1d9;
            line-height: 1.6; padding: 0;
        }
        .hero {
            background: linear-gradient(135deg, #1a1a2e 0%, #16213e 50%, #0f3460 100%);
            padding: 60px 20px; text-align: center;
        }
        .hero h1 { font-size: 3em; color: #58a6ff; margin-bottom: 10px; }
        .hero h1 span { color: #f0883e; }
        .hero p { font-size: 1.2em; color: #8b949e; max-width: 700px; margin: 0 auto 30px; }
        .install {
            background: #161b22; border: 1px solid #30363d; border-radius: 8px;
            padding: 15px 25px; display: inline-block; font-family: monospace;
            font-size: 1.1em; color: #7ee787; cursor: pointer;
        }
        .install:hover { border-color: #58a6ff; }
        .badges { margin: 20px 0; }
        .badges img { margin: 0 4px; }
        .container { max-width: 900px; margin: 0 auto; padding: 40px 20px; }
        h2 { color: #58a6ff; font-size: 1.5em; margin: 40px 0 15px; border-bottom: 1px solid #21262d; padding-bottom: 8px; }
        .feature-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 20px 0; }
        .feature {
            background: #161b22; border: 1px solid #30363d; border-radius: 8px;
            padding: 20px;
        }
        .feature h3 { color: #f0883e; margin-bottom: 8px; }
        .feature p { color: #8b949e; font-size: 0.95em; }
        pre {
            background: #161b22; border: 1px solid #30363d; border-radius: 8px;
            padding: 20px; overflow-x: auto; font-size: 0.9em;
        }
        code { color: #7ee787; }
        .kw { color: #ff7b72; }
        .fn { color: #d2a8ff; }
        .str { color: #a5d6ff; }
        .cmt { color: #8b949e; }
        .num { color: #79c0ff; }
        a { color: #58a6ff; text-decoration: none; }
        a:hover { text-decoration: underline; }
        .links { display: flex; gap: 15px; justify-content: center; margin: 30px 0; flex-wrap: wrap; }
        .links a {
            background: #21262d; border: 1px solid #30363d; border-radius: 8px;
            padding: 12px 24px; font-size: 1em; transition: 0.2s;
        }
        .links a:hover { border-color: #58a6ff; background: #161b22; text-decoration: none; }
        .comparison { width: 100%; border-collapse: collapse; margin: 20px 0; }
        .comparison th, .comparison td { padding: 10px 15px; border: 1px solid #30363d; text-align: left; }
        .comparison th { background: #161b22; color: #58a6ff; }
        .comparison td { color: #c9d1d9; }
        .highlight { color: #7ee787; font-weight: bold; }
        .math {
            background: #161b22; border: 1px solid #30363d; border-radius: 8px;
            padding: 20px; margin: 15px 0; text-align: center;
            font-family: 'Times New Roman', serif; font-size: 1.2em; color: #c9d1d9;
        }
        footer { text-align: center; padding: 40px; color: #484f58; font-size: 0.9em; }
        @media (max-width: 600px) {
            .feature-grid { grid-template-columns: 1fr; }
            .hero h1 { font-size: 2em; }
        }
    </style>
</head>
<body>

<div class="hero">
    <h1>In<span>KAN</span></h1>
    <p>Fast B-spline Kolmogorov-Arnold Network layers for PyTorch.<br>
    Drop-in <code>nn.Linear</code> replacement with learnable spline activations.</p>

    <div class="badges">
        <a href="https://pypi.org/project/inkan/"><img src="https://img.shields.io/pypi/v/inkan" alt="PyPI"></a>
        <a href="https://pypi.org/project/inkan/"><img src="https://img.shields.io/pypi/dm/inkan" alt="Downloads"></a>
        <img src="https://img.shields.io/pypi/pyversions/inkan" alt="Python">
        <img src="https://img.shields.io/badge/License-MIT-yellow.svg" alt="MIT">
    </div>

    <div class="install" onclick="navigator.clipboard.writeText('pip install inkan')">
        pip install inkan
    </div>
    <p style="font-size: 0.8em; color: #484f58; margin-top: 8px;">click to copy</p>
</div>

<div class="container">

    <h2>What is a KAN?</h2>
    <p>In a standard MLP, each connection has a fixed weight and a shared activation function.
    In a <strong>Kolmogorov-Arnold Network</strong>, each edge has its own learnable univariate function
    &phi;(x) &mdash; a B-spline curve that transforms the scalar flowing along that edge.</p>

    <div class="math">
        MLP: &ensp; y = &sigma;(W&middot;x + b) &emsp;&emsp;&emsp;
        KAN: &ensp; y<sub>j</sub> = &sum;<sub>i</sub> &phi;<sub>ji</sub>(x<sub>i</sub>)
    </div>

    <p>Each &phi;<sub>ji</sub> is a learned cubic B-spline with <strong>local support</strong>:
    changing one coefficient affects the function over only ~4 knot intervals.
    This makes KANs inherently more interpretable and editable than MLPs.</p>

    <h2>Why InKAN?</h2>

    <div class="feature-grid">
        <div class="feature">
            <h3>2.8&ndash;5.4x Faster</h3>
            <p>Stable piecewise polynomial evaluation instead of recursive Cox-de Boor.
            Local 4-basis lookup instead of dense K-basis computation.</p>
        </div>
        <div class="feature">
            <h3>Drop-in Replacement</h3>
            <p><code>KANLayer(in, out)</code> replaces <code>nn.Linear(in, out)</code>.
            Same interface, same optimizer, same training loop.</p>
        </div>
        <div class="feature">
            <h3>Numerically Stable</h3>
            <p>Guaranteed non-negative basis output. Float32 accuracy ~1.2e-7.
            No catastrophic cancellation from alternating sums.</p>
        </div>
        <div class="feature">
            <h3>1D and 2D Splines</h3>
            <p>Univariate spline layers plus tensor-product B-spline surfaces
            for joint function approximation.</p>
        </div>
    </div>

    <h2>Quick Start</h2>
    <pre><code><span class="kw">import</span> torch
<span class="kw">from</span> inkan <span class="kw">import</span> KANLayer, KANNetwork

<span class="cmt"># Single layer β€” drop-in for nn.Linear</span>
layer = <span class="fn">KANLayer</span>(<span class="num">8</span>, <span class="num">4</span>)
x = torch.<span class="fn">randn</span>(<span class="num">32</span>, <span class="num">8</span>)
y = <span class="fn">layer</span>(x)  <span class="cmt"># [32, 4]</span>

<span class="cmt"># Multi-layer network</span>
net = <span class="fn">KANNetwork</span>([<span class="num">784</span>, <span class="num">64</span>, <span class="num">10</span>])
x = torch.<span class="fn">randn</span>(<span class="num">32</span>, <span class="num">784</span>)
y = <span class="fn">net</span>(x)  <span class="cmt"># [32, 10]</span>

<span class="cmt"># Standard PyTorch training</span>
optimizer = torch.optim.<span class="fn">Adam</span>(net.<span class="fn">parameters</span>(), lr=<span class="num">1e-3</span>)
loss = y.<span class="fn">sum</span>()
loss.<span class="fn">backward</span>()
optimizer.<span class="fn">step</span>()</code></pre>

    <h2>Performance</h2>
    <table class="comparison">
        <tr>
            <th>Method</th><th>Grid Size 8</th><th>Grid Size 20</th><th>Grid Size 50</th>
        </tr>
        <tr>
            <td>Cox-de Boor (recursive)</td><td>1.0x</td><td>1.0x</td><td>1.0x</td>
        </tr>
        <tr>
            <td><strong>InKAN (piecewise + local)</strong></td>
            <td class="highlight">2.8x faster</td>
            <td class="highlight">3.9x faster</td>
            <td class="highlight">5.4x faster</td>
        </tr>
    </table>

    <h2>Used In</h2>
    <p><a href="https://github.com/NAVEENMN/attention_manifolds">Attention Manifolds</a> &mdash;
    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.</p>

    <div class="links">
        <a href="https://pypi.org/project/inkan/">πŸ“¦ PyPI</a>
        <a href="https://github.com/NAVEENMN/inkan">πŸ’» GitHub</a>
        <a href="https://arxiv.org/abs/2609.01956">πŸ“„ Paper</a>
        <a href="https://naveenmn.github.io/inkan/">πŸ“– Docs</a>
    </div>

</div>

<footer>
    InKAN &copy; 2026 Naveen Mysore &middot; MIT License
</footer>

</body>
</html>