Skip to main content

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 of Value
  • mlp.parameters() — list of all Value parameters
  • mlp.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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

micrograd_rust-0.1.0.tar.gz (7.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

micrograd_rust-0.1.0-cp312-cp312-macosx_11_0_arm64.whl (280.5 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

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

Hashes for micrograd_rust-0.1.0.tar.gz
Algorithm Hash digest
SHA256 03c2f0c824714cec69320df96cb7fe7ed39d9ab473ab6c299a056f5ed2e0570b
MD5 4f4354408c28d490cf0b4609fe71860e
BLAKE2b-256 7e9d378b32c251667b0def39d049595602b58ab20ada8829d8e29830f2c3df5e

See more details on using hashes here.

File details

Details for the file micrograd_rust-0.1.0-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for micrograd_rust-0.1.0-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 35bab4a5a965f380870b94e87238c1d172aacdf6a8c702c7b29f259f13abe569
MD5 77b08b893e8d9712ff394d00212673e7
BLAKE2b-256 758d901b9e755cf10f5fa783c67c5412c064233a6d0a4dfc5d0eca59144f041a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page