A Rust-backed scalar autograd engine. Drop-in replacement for Karpathy's micrograd, but 13-75x faster.
Project description
micrograd-rust
A Rust-backed scalar autograd engine and neural network library for Python. Drop-in replacement for Karpathy's micrograd, but 13-75x faster.
Install
pip install micrograd-rust
Usage
from micrograd_rust import Value, MLP
# scalar autograd
a = Value(2.0)
b = Value(3.0)
c = (a * b + a).tanh()
c.backward()
print(a.grad) # dc/da
print(b.grad) # dc/db
# neural network
mlp = MLP(3, [4, 4, 1])
x = [Value(1.0), Value(2.0), Value(3.0)]
out = mlp(x)
out[0].backward()
API
Value(data, label="")
.data— the scalar value.grad— the gradient (populated after.backward())- Supports
+,*,**,-,/,.tanh(),.exp(),.backward()
MLP(nin, nouts)
mlp(x)/mlp.forward(x)— forward pass, returns list ofValuemlp.parameters()— list of allValueparametersmlp.zero_grad()— reset all gradients to 0
How it works
Uses PyO3 to call into a Rust autograd engine under the hood. All computation happens in Rust. See the GitHub repo for benchmarks and source.
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 micrograd_rust-0.1.0.tar.gz.
File metadata
- Download URL: micrograd_rust-0.1.0.tar.gz
- Upload date:
- Size: 7.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03c2f0c824714cec69320df96cb7fe7ed39d9ab473ab6c299a056f5ed2e0570b
|
|
| MD5 |
4f4354408c28d490cf0b4609fe71860e
|
|
| BLAKE2b-256 |
7e9d378b32c251667b0def39d049595602b58ab20ada8829d8e29830f2c3df5e
|
File details
Details for the file micrograd_rust-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.
File metadata
- Download URL: micrograd_rust-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
- Upload date:
- Size: 280.5 kB
- Tags: CPython 3.12, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35bab4a5a965f380870b94e87238c1d172aacdf6a8c702c7b29f259f13abe569
|
|
| MD5 |
77b08b893e8d9712ff394d00212673e7
|
|
| BLAKE2b-256 |
758d901b9e755cf10f5fa783c67c5412c064233a6d0a4dfc5d0eca59144f041a
|