Minimal dynamic computation graph with backpropagation, for pedagogical purposes
Project description
edugrad
This is a library intended for pedagogical purposes illustrating a very minimal implementation of dynamic computational graphs with reverse-mode differentiation (backpropagation) for computing gradients. Three guidelines motivate design choices made in the implementation:
- Mimicking PyTorch's API as closely as possible.
- Simple
forward/backwardfor operations (operating on numpy arrays). - Dynamic computation graphs, built as operations are run.
The library has been inspired by several other similar projects. Specific acknowledgments are in the source where appropriate.
microgradby Karpathyautodidact: a pedagogical implementation ofautogradjoelnet
Installation
To simply use edugrad, you can pip install edugrad or uv add edugrad.
For an editable installation, clone the repo and run uv sync from the root directory.
Usage
In examples/toy_half_sum, you will find a basic use case. main.py exhibits a basic use case of defining a feed-forward neural network (multi-layer perceptron) to learn a basic function (in this case, y = sum(x)/2 where x is a binary vector). You can run it by running uv run python -m examples.toy_half_sum.main from the main directory of this repo.
Basics
There are a few important data structures:
Tensor: this is a wrapper around a numpy array (stored in.value), which corresponds to a node in a computation graph, storing information like its parents (if any) and a backward method.Operator: an operator implements theforward/backwardAPI and operates directly on numpy arrays. A decorator@tensor_opconverts anOperatorinto a method that can be directly called onTensorarguments, which will build the graph dynamically.nn.Module: as in PyTorch, these are wrappers for graphs that keep track of parameters, sub-modules, etc.
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 edugrad-0.1.0.tar.gz.
File metadata
- Download URL: edugrad-0.1.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92f4ef75ee5bd5fe697d01ae2b4907312c8094938798160b43c30c31f382395c
|
|
| MD5 |
e6e0df05bc37b84ecbd61334a07afff4
|
|
| BLAKE2b-256 |
21e6a44e48ec9535a904311064a8484c68aa057a749343b1b26667aabe66f3e3
|
Provenance
The following attestation bundles were made for edugrad-0.1.0.tar.gz:
Publisher:
publish.yml on shanest/edugrad
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
edugrad-0.1.0.tar.gz -
Subject digest:
92f4ef75ee5bd5fe697d01ae2b4907312c8094938798160b43c30c31f382395c - Sigstore transparency entry: 1111035381
- Sigstore integration time:
-
Permalink:
shanest/edugrad@f711ab461d601859937a7973f4b7939ed4305bfd -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/shanest
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f711ab461d601859937a7973f4b7939ed4305bfd -
Trigger Event:
push
-
Statement type:
File details
Details for the file edugrad-0.1.0-py3-none-any.whl.
File metadata
- Download URL: edugrad-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.7 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 |
f3a666424e24fa45e022101d1ff16d9ae1a20b619414ec86b540cdafe5ad7278
|
|
| MD5 |
f57b34cb8f6f78ba5ed309884b9b3a29
|
|
| BLAKE2b-256 |
8401c54e139a2fd273777ec5ea27cdb60b2a54e9178ea692e4e14f964612cbca
|
Provenance
The following attestation bundles were made for edugrad-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on shanest/edugrad
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
edugrad-0.1.0-py3-none-any.whl -
Subject digest:
f3a666424e24fa45e022101d1ff16d9ae1a20b619414ec86b540cdafe5ad7278 - Sigstore transparency entry: 1111035411
- Sigstore integration time:
-
Permalink:
shanest/edugrad@f711ab461d601859937a7973f4b7939ed4305bfd -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/shanest
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@f711ab461d601859937a7973f4b7939ed4305bfd -
Trigger Event:
push
-
Statement type: