KPU Python Package
High-level Python API for the KPU (Knowledge Processing Unit) simulator - a multi-fidelity neural network accelerator simulator with decorator-based compilation and comprehensive quantization support.
Installation
pip install stillwater-kpu
Optional dependencies:
pip install stillwater-kpu[torch] # PyTorch integration (torch.compile backend)
pip install stillwater-kpu[bfloat16] # Native bfloat16 support via ml_dtypes
Quick Start
import kpu
import numpy as np
# Define a neural network with @kpu.compile
@kpu.compile
def mlp(x, w1, w2):
h = kpu.relu(x @ w1)
return h @ w2
# Create tensors
x = kpu.Tensor(np.random.randn(32, 784).astype(np.float32))
w1 = kpu.Tensor(np.random.randn(784, 128).astype(np.float32))
w2 = kpu.Tensor(np.random.randn(128, 10).astype(np.float32))
# Execute
result = mlp(x, w1, w2)
print(result.shape) # (32, 10)
Key Features
Multi-Fidelity Simulation
- BEHAVIORAL: Computes actual values for functional correctness
- TRANSACTIONAL: Statistical timing model for performance estimation
- CYCLE_ACCURATE: Full timing simulation with C++ backend
Comprehensive Operator Support
- Matrix: matmul, linear
- Convolution: conv2d with stride/padding
- Attention: scaled_dot_product_attention, multi_head_attention
- Pooling: max_pool2d, avg_pool2d, adaptive_avg_pool2d
- Activation: relu, gelu, silu, sigmoid, tanh, softmax
- Normalization: layer_norm, batch_norm2d
- Elementwise: exp, log, sqrt, +, -, *, /
- Shape: reshape, transpose, concat, flatten
Quantization Support (v0.7.x)
Full quantization infrastructure for simulating low-precision inference:
| Type | Bits | Memory Reduction |
|---|---|---|
| FP16 | 16 | 2x |
| BF16 | 16 | 2x |
| INT8 | 8 | 4x |
| FP8 (E4M3/E5M2) | 8 | 4x |
| INT4 | 4 | 8x |
| FP4 | 4 | 8x |
# INT8 quantization
from kpu import quantize, dequantize, compute_scale_zero_point
scale, zp = compute_scale_zero_point(weights)
w_int8 = quantize(weights, scale, zp)
# Calibration for post-training quantization
from kpu import CalibrationObserver, CalibrationMethod
observer = CalibrationObserver(method=CalibrationMethod.PERCENTILE)
for batch in calibration_data:
observer.observe(activations)
params = observer.compute_params()
Kernel Fusion
Automatic fusion of common patterns for reduced memory traffic:
- MatMul + Bias + ReLU/GELU/SiLU
- Conv2D + BatchNorm + Activation
@kpu.compile(optimize=True) # Fusion enabled by default
def fused_layer(x, w, b):
return kpu.relu(x @ w + b) # Fused into single operation
PyTorch Integration
Use KPU as a torch.compile backend:
import torch
model = torch.compile(my_model, backend="kpu")
output = model(input)
# With timing statistics
model = torch.compile(my_model, backend="kpu_transactional")
stats = kpu.get_torch_compile_stats()
print(f"Estimated cycles: {stats.cycles}")
Simulation Modes
import kpu
# Functional simulation (default)
kpu.set_fidelity(kpu.BEHAVIORAL)
# Performance estimation
kpu.set_fidelity(kpu.TRANSACTIONAL)
kpu.set_clock_frequency(1.0) # 1 GHz
# Execute and get timing
result = model(input)
stats = model.get_stats()
print(f"Cycles: {stats.cycles}, GFLOPS: {stats.gflops:.1f}")
Architecture
Python Code with @kpu.compile
↓
Tracing (build OpGraph)
↓
Fusion Optimization (optional)
↓
DFX IR Emission
↓
Runtime Execution
├── BEHAVIORAL (pure Python, computes values)
├── TRANSACTIONAL (C++ bindings, statistical timing)
└── CYCLE_ACCURATE (C++ bindings, full timing)
Examples
# CNN for image classification
@kpu.compile
def cnn(x, conv_w, fc_w):
h = kpu.relu(kpu.conv2d(x, conv_w, padding=1))
h = kpu.max_pool2d(h, kernel_size=2)
h = h.reshape(h.shape[0], -1)
return h @ fc_w
# Transformer attention
@kpu.compile
def attention(q, k, v):
return kpu.scaled_dot_product_attention(q, k, v)
# Quantized inference
from kpu import int4_linear, calibrate_percentile
params = calibrate_percentile(weights)
output = int4_linear(x, weights, params)
Links
License
Apache-2.0
Metadata
Release files for stillwater-kpu 0.8.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 | |
|---|---|---|---|
| stillwater_kpu-0.8.0.tar.gz | 174.6 kB | Details |
Built distributions (wheels)
Total release size: 4.8 MB
Release files / stillwater_kpu-0.8.0.tar.gz
| Download URL | stillwater_kpu-0.8.0.tar.gz |
|---|---|
| Size | 174.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f7c80f1fc2111d6454db74876a796e570604b3385362f1ca552040820447b376
|
|
BLAKE2b-256 checksum How to use checksums |
d6f560ddc12acce218e4012956fd097dbe422891db16d25166996920483154d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 25, 2026.
Transparency logRelease files / stillwater_kpu-0.8.0-cp312-cp312-win_amd64.whl
| Download URL | stillwater_kpu-0.8.0-cp312-cp312-win_amd64.whl |
|---|---|
| Size | 389.0 kB |
| Tags | CPython 3.12 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
84bb9b0140a0d99f3f189e9b35dfb7fbd4cb2486b91b66e25e13f7d8e59e54d9
|
|
BLAKE2b-256 checksum How to use checksums |
9cabcf0588883241afbbc621cb7ad2951e7599d3ee5f9e9d19ff01608dd86a0c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 26, 2026.
Transparency logRelease files / stillwater_kpu-0.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | stillwater_kpu-0.8.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 399.9 kB |
| Tags | CPython 3.12 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
5eb09dc77f1410462c50b75ab2d8ce729db97f198ef8016907bb52dcc4afccc3
|
|
BLAKE2b-256 checksum How to use checksums |
619fe7a769ef5a15a9d1f39518adbdd776ae707109d58ed407290a134dde90de
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 25, 2026.
Transparency logRelease files / stillwater_kpu-0.8.0-cp312-cp312-macosx_10_15_x86_64.whl
| Download URL | stillwater_kpu-0.8.0-cp312-cp312-macosx_10_15_x86_64.whl |
|---|---|
| Size | 363.1 kB |
| Tags | CPython 3.12 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
f4fe36f0c215bffe2b910f9f849200a903f546d1597f80ae21cc3df16907e95a
|
|
BLAKE2b-256 checksum How to use checksums |
46f16e4525996dad750a806e71c5b1c9fe81bbad93d5c9df22d398b35fbc47e1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 25, 2026.
Transparency logRelease files / stillwater_kpu-0.8.0-cp311-cp311-win_amd64.whl
| Download URL | stillwater_kpu-0.8.0-cp311-cp311-win_amd64.whl |
|---|---|
| Size | 387.2 kB |
| Tags | CPython 3.11 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
81510912d612ceaee966be968d3aef28e2aa2061f1e9e47cb4bcd19a19bdc99c
|
|
BLAKE2b-256 checksum How to use checksums |
a5aac5a1ba81cc899b968ece8d57abbe2b583804d308c20baa143ba765f61d78
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 26, 2026.
Transparency logRelease files / stillwater_kpu-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | stillwater_kpu-0.8.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 399.8 kB |
| Tags | CPython 3.11 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
a6d8d0041454c5df12b5d98dec80cdcf027491e272a7e9ed763bb97b7852c596
|
|
BLAKE2b-256 checksum How to use checksums |
dae8e9c70598b56ad05e0ec39273b59d1d5029f5273470048b5a1cab7cb43a8f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 25, 2026.
Transparency logRelease files / stillwater_kpu-0.8.0-cp311-cp311-macosx_10_15_x86_64.whl
| Download URL | stillwater_kpu-0.8.0-cp311-cp311-macosx_10_15_x86_64.whl |
|---|---|
| Size | 361.2 kB |
| Tags | CPython 3.11 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
740ec959ff5b2fd11537733322408c064f839139b2ab167196dc719149279765
|
|
BLAKE2b-256 checksum How to use checksums |
ea7a4db250e8b2c372519f77748b10c1a67f7f5c98577899747452aa4aea4af8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 25, 2026.
Transparency logRelease files / stillwater_kpu-0.8.0-cp310-cp310-win_amd64.whl
| Download URL | stillwater_kpu-0.8.0-cp310-cp310-win_amd64.whl |
|---|---|
| Size | 386.6 kB |
| Tags | CPython 3.10 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
7084a3178fc14926be4935d4bb69addfb442e4bc751bc372fd7bc6b9b0ab4918
|
|
BLAKE2b-256 checksum How to use checksums |
9019b4314365446629d00a79a544540c00a09057f8b4db9b0585d0b347069079
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 26, 2026.
Transparency logRelease files / stillwater_kpu-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | stillwater_kpu-0.8.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 398.1 kB |
| Tags | CPython 3.10 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
e3e058638ec7457a377a6a98f6f4ec4a4d6d55ffeb3b679aa0fb8bca504dbd3e
|
|
BLAKE2b-256 checksum How to use checksums |
f1fd630e2ab116e0e22520bd788bcf178e4ded7b2bab61db0a4b3741d30484d7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 25, 2026.
Transparency logRelease files / stillwater_kpu-0.8.0-cp310-cp310-macosx_10_15_x86_64.whl
| Download URL | stillwater_kpu-0.8.0-cp310-cp310-macosx_10_15_x86_64.whl |
|---|---|
| Size | 359.7 kB |
| Tags | CPython 3.10 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
51d4dab8726688eaeee32ddd9f10cf6f218c827ab317365f4c73b346095f15b4
|
|
BLAKE2b-256 checksum How to use checksums |
7560c8770a123485ca0bef8c2d77cc4e157ce5f885e5cb49ca48adb777181fa8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 25, 2026.
Transparency logRelease files / stillwater_kpu-0.8.0-cp39-cp39-win_amd64.whl
| Download URL | stillwater_kpu-0.8.0-cp39-cp39-win_amd64.whl |
|---|---|
| Size | 390.3 kB |
| Tags | CPython 3.9 Windows x86-64 |
|
SHA-256 checksum How to use checksums |
e5743c28aa5db36b5cff0f42007373bd73f1de1885461223560f962e5d2af750
|
|
BLAKE2b-256 checksum How to use checksums |
ca5b917188b27ab5dd1dbe0d2da23b3bb8424b6ea603bfc81444f43f42f51867
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 26, 2026.
Transparency logRelease files / stillwater_kpu-0.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
| Download URL | stillwater_kpu-0.8.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl |
|---|---|
| Size | 398.4 kB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 |
|
SHA-256 checksum How to use checksums |
c8a330348fc047228aca10756043e8c8d736b237877ddb4fdf083a67b2f9d98a
|
|
BLAKE2b-256 checksum How to use checksums |
4de344a15481e338f519647608481373bdba6a14e9b689cc9ece2060b8a67f52
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 25, 2026.
Transparency logRelease files / stillwater_kpu-0.8.0-cp39-cp39-macosx_10_15_x86_64.whl
| Download URL | stillwater_kpu-0.8.0-cp39-cp39-macosx_10_15_x86_64.whl |
|---|---|
| Size | 359.8 kB |
| Tags | CPython 3.9 macOS 10.15+ x86-64 |
|
SHA-256 checksum How to use checksums |
3f8305cd9090f1529b751fb527edce36717f2be7045065fb1488fd8c99d16733
|
|
BLAKE2b-256 checksum How to use checksums |
68d509c68533b59d01569c262327decdd1dcf200c6381ca0b945d60bca9f4dca
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jan 25, 2026.
Transparency log