Skip to main content

A minimal scalar-valued autograd engine written in Rust

Project description

PyPI version info PyPI supported Python versions

Key Features

  • Forward and Backward pass on scalar values
  • Backpropagation with a computation graph
  • Activation Functions:
    • Sigmoid
    • ReLU
    • Softmax
  • Loss Criterion:
    • Cross Entropy

Installing

# using pip
pip install oxigrad

# using uv
uv add oxigrad

Note: Python 3.9 or higher is required

Quick Examples

Simple Neuron

from oxigrad import Value, Activation

x1 = Value(1.7, label="x1")
x2 = Value(-0.3, label="x2")

w1 = Value(-1.5, label="w1")
w2 = Value(0.1, label="w2")

b = Value(0.5, label="b")

# Set a label after an operation
x1w1 = (x1 * w1).set_label("x1w1")
x2w2 = x2 * w2

xwb = x1w1 + x2w2 + b

z = Activation.Sigmoid(xwb).set_label("z")

# Run backpropagation
z.backward()

print(z)    # Value(data=0.8889, grad=1.0000, label='z', operation='SIGMOID')
print(w1)   # Value(data=-1.5000, grad=0.1678, label='w1')
print(w2)   # Value(data=0.1000, grad=-0.0296, label='w2')
print(b)    # Value(data=0.5000, grad=0.0987, label='b')

Cross Entropy Loss

from oxigrad import Activation, Loss, Value

a = Value(1.63, label="logit_0")
b = Value(0.27, label="logit_1")

c = Value(1, label="target_0")
d = Value(0, label="target_1")

logits = [a, b]
targets = [c, d]

# Convert logits into probability scores (does not add to computation graph)
probability_scores = Activation.Softmax(logits)
print(probability_scores)       # [0.7957596977159083, 0.20424030228409182]
print(sum(probability_scores))  # 1.0

# Has build in softmax
loss = Loss.CrossEntropy(logits, targets).set_label("loss")
loss.backward()

print(loss) # Value(data=0.2285, grad=1.0000, label='loss', operation='CROSSENTROPY')
print(a)    # Value(data=1.6300, grad=-0.2042, label='logit_0')
print(b)    # Value(data=0.2700, grad=0.2042, label='logit_1')
print(c)    # Value(data=1.0000, grad=0.2285, label='target_0')
print(d)    # Value(data=0.0000, grad=1.5885, label='target_1')

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

oxigrad-0.3.0.tar.gz (14.3 kB view details)

Uploaded Source

Built Distribution

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

oxigrad-0.3.0-cp39-abi3-win_amd64.whl (162.4 kB view details)

Uploaded CPython 3.9+Windows x86-64

File details

Details for the file oxigrad-0.3.0.tar.gz.

File metadata

  • Download URL: oxigrad-0.3.0.tar.gz
  • Upload date:
  • Size: 14.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.9.0

File hashes

Hashes for oxigrad-0.3.0.tar.gz
Algorithm Hash digest
SHA256 3253f16ce75e13d7b27e90a20c8b4d982633e6eb3f796442a30741bf7aad6dc3
MD5 41ab47632f3b71cfb03e751347872db2
BLAKE2b-256 86081966131f47517c8f75035f2596d723ecb0117d2d5d35c932b7c4b2284657

See more details on using hashes here.

File details

Details for the file oxigrad-0.3.0-cp39-abi3-win_amd64.whl.

File metadata

  • Download URL: oxigrad-0.3.0-cp39-abi3-win_amd64.whl
  • Upload date:
  • Size: 162.4 kB
  • Tags: CPython 3.9+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.9.0

File hashes

Hashes for oxigrad-0.3.0-cp39-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 86278eb9a03b71447d31884415ff82bf35f750736b9489d5f4c87fefe0d3b1d8
MD5 43ed3fb00ff0606942dab8288a64f0de
BLAKE2b-256 5d6deb676c3899a61e21d7bdc47694acd4e2ee12254929709ecca514f919175a

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