KPU (Knowledge Processing Unit) Simulator Python API
Project description
KPU Python Package
High-level Python API for the KPU (Knowledge Processing Unit) simulator with decorator-based compilation.
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 (computes actual values in BEHAVIORAL mode)
result = mlp(x, w1, w2)
print(result.shape) # (32, 10)
# Inspect generated DFX IR
print(mlp.get_dfx().to_json())
Features
- Decorator-based compilation: Use
@kpu.compileto compile Python functions to KPU programs - NumPy-compatible tensors:
kpu.Tensorwraps NumPy arrays with compilation support - Multi-fidelity simulation:
BEHAVIORAL: Computes actual values (functional correctness)TRANSACTIONAL: Statistical timing modelCYCLE_ACCURATE: Full timing simulation
- DFX IR generation: Inspectable intermediate representation
Supported Operations
Matrix Operations
@(matmul): Matrix multiplicationkpu.linear: Linear layer (y = x @ W^T + b)
Activation Functions
kpu.relu: Rectified Linear Unitkpu.gelu: Gaussian Error Linear Unitkpu.silu: Sigmoid Linear Unit (Swish)kpu.sigmoid: Sigmoidkpu.tanh: Hyperbolic tangentkpu.softmax: Softmax
Elementwise Operations
+,-,*,/: Arithmetic operationskpu.exp,kpu.log,kpu.sqrt: Math functions
Reduction Operations
kpu.sum,kpu.mean: Aggregations
Installation
# From the kpu-sim repository
cd python
pip install -e .
# Run tests
pytest tests/ -v
Examples
See examples/mnist_mlp.py for a complete MNIST classifier example.
Architecture
Python Code with @kpu.compile
↓
Tracing (build OpGraph)
↓
DFX IR Emission
↓
Runtime Execution
├── BEHAVIORAL (pure Python, computes values)
├── TRANSACTIONAL (C++ bindings, statistical)
└── CYCLE_ACCURATE (C++ bindings, full timing)
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 stillwater_kpu-0.6.0.tar.gz.
File metadata
- Download URL: stillwater_kpu-0.6.0.tar.gz
- Upload date:
- Size: 58.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
60c3df23419bb24e88e993c054f61c48045ee88a6cabcbdcde836c055129d601
|
|
| MD5 |
7ea89a24f25124f9b833e7f5de1c549c
|
|
| BLAKE2b-256 |
953db8218dd3b9f8cdcc551f99bb559162fd6fc08b82b603051cdc8a03dc3a50
|
Provenance
The following attestation bundles were made for stillwater_kpu-0.6.0.tar.gz:
Publisher:
python-publish.yml on stillwater-sc/kpu-sim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stillwater_kpu-0.6.0.tar.gz -
Subject digest:
60c3df23419bb24e88e993c054f61c48045ee88a6cabcbdcde836c055129d601 - Sigstore transparency entry: 840939049
- Sigstore integration time:
-
Permalink:
stillwater-sc/kpu-sim@4ba152615f533de37ad35bb7cc0a681fb7eb5b61 -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/stillwater-sc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@4ba152615f533de37ad35bb7cc0a681fb7eb5b61 -
Trigger Event:
release
-
Statement type:
File details
Details for the file stillwater_kpu-0.6.0-py3-none-any.whl.
File metadata
- Download URL: stillwater_kpu-0.6.0-py3-none-any.whl
- Upload date:
- Size: 49.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0bd81fd2039beca3bef714793e66a62611a5447a258c1d16671de3997109d05c
|
|
| MD5 |
27c11abe7fb9f4f1f94f6b2a0804d335
|
|
| BLAKE2b-256 |
fb75d2c8317e17d3bf84227383efa1d4662d17e54613b0eb1d6bc6bfee76a744
|
Provenance
The following attestation bundles were made for stillwater_kpu-0.6.0-py3-none-any.whl:
Publisher:
python-publish.yml on stillwater-sc/kpu-sim
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
stillwater_kpu-0.6.0-py3-none-any.whl -
Subject digest:
0bd81fd2039beca3bef714793e66a62611a5447a258c1d16671de3997109d05c - Sigstore transparency entry: 840939083
- Sigstore integration time:
-
Permalink:
stillwater-sc/kpu-sim@4ba152615f533de37ad35bb7cc0a681fb7eb5b61 -
Branch / Tag:
refs/tags/v0.6.0 - Owner: https://github.com/stillwater-sc
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@4ba152615f533de37ad35bb7cc0a681fb7eb5b61 -
Trigger Event:
release
-
Statement type: