Skip to main content

atomgrad

pic

Atomgrad is a simple autograd engine that aims to be between micrograd and tinygrad that performs autodiff on vector-valued and scalar-valued tensors (atoms) coupled with a neural network api library.

Features

  • Supports Pytorch-like vector-valued and scalar-valued tensors.
  • Supports basic unary ops, binary ops, reduce ops and movement ops i.e (activn funcs, sum, exp, reshape, randint, uniform, etc).
  • Supports activation functions such as relu, sigmoid, tanh, etc.
  • Supports binary_cross_entropy & binary_accuracy.
  • Supports Graph Visualizations.

Installation

You can install atomgrad using pip:

pip install atomgrad==0.3.0

Usage

Here is a simple example of using atomgrad to compute the gradient of a function:

from atomgrad.atom import Atom
from atomgrad.graph import draw_dot


# create two tensors with gradients enabled
x = Atom(2.0, requires_grad=True)
y = Atom(3.0, requires_grad=True)

# define a function
z = x * y + x ** 2

# compute the backward pass
z.backward()

# print the gradients
print(x.grad) # 7.0
print(y.grad) # 2.0

draw_dot(z)

pic

Here is a simple example of using atomgrad to train a one 16-node hidden layer neural network for binary classification.

import numpy as np
from atomgrad.atom import Atom
from atomgrad.nn import AtomNet, Layer
from atomgrad.optim import SGD
from atomgrad.metrics import binary_cross_entropy, binary_accuracy

# create a model
model = AtomNet(
  Layer(2, 16),
  Layer(16, 16),
  Layer(16, 1)
)
# create an optimizer
optim = SGD(model.parameters(), lr=0.01)

# load some data
x = [[2.0, 3.0, -1.0],
  [3.0, -1.0, 0.5],
  [0.5, 1.0, 1.0],
  [1.0, 1.0, -1.0],
  [0.0, 4.0, 0.5],
  [3.0, -1.0, 0.5]]
y = [1, 1, 0, 1, 0, 1]

x = Atom(x)
y = Atom(y)

model.fit(x, y, optim, binary_cross_entropy, binary_accuracy, epochs=100)

#output
'''
...
epoch: 30 | loss: 0.14601783454418182  | accuracy: 100.0%
epoch: 35 | loss: 0.11600304394960403  | accuracy: 100.0%
epoch: 40 | loss: 0.09604986757040024  | accuracy: 100.0%
epoch: 45 | loss: 0.0816292017698288  | accuracy: 100.0%
'''

Demos

An example of simple autodiff and four binary classifiers including make_moons dataset and MNIST digits dataset is in the examples/demos.ipynb notebook.

Note: Although atom.nn includes softmax activation and cat_cross_entropy, model results are quite dissapointing and are likely due to some bug (plz lmk if you find it!). As a result the AtomNet model is best suited for binary classification neural net tasks.

Metadata

Release files for atomgrad 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for atomgrad 0.3.0
File Size Uploaded Provenance Actions
atomgrad-0.3.0.tar.gz 6.9 kB Without provenance Details for atomgrad-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for atomgrad 0.3.0
File Interpreter ABI Platform Actions
atomgrad-0.3.0-py3-none-any.whl Python 3 none any Details for atomgrad-0.3.0-py3-none-any.whl

Total release size: 13.6 kB

Release files / atomgrad-0.3.0.tar.gz

Download URL atomgrad-0.3.0.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
83ea0f4e17ec3462eb1a8a85bd33cbb936ca38d93ffe12bbcbbadc8576d3476f
BLAKE2b-256 checksum
How to use checksums
3d79b1572155c51c7f4628455a63edecdf3b4c7677b0378651b287524f283487
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / atomgrad-0.3.0-py3-none-any.whl

Download URL atomgrad-0.3.0-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
88b8726a55f8a74c11d1a2f41d8edcdcc7a800abd1197321147bc179c0b44250
BLAKE2b-256 checksum
How to use checksums
ef77d9ae363b2f714baa01dd281f1e58297a753188735b86eaee15a8c5a7d9aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Security for atomgrad 0.3.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page