Skip to main content

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/backward for 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.

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 the forward/backward API and operates directly on numpy arrays. A decorator @tensor_op converts an Operator into a method that can be directly called on Tensor arguments, 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


Download files

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

Source Distribution

edugrad-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

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

edugrad-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

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

Hashes for edugrad-0.1.0.tar.gz
Algorithm Hash digest
SHA256 92f4ef75ee5bd5fe697d01ae2b4907312c8094938798160b43c30c31f382395c
MD5 e6e0df05bc37b84ecbd61334a07afff4
BLAKE2b-256 21e6a44e48ec9535a904311064a8484c68aa057a749343b1b26667aabe66f3e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for edugrad-0.1.0.tar.gz:

Publisher: publish.yml on shanest/edugrad

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for edugrad-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f3a666424e24fa45e022101d1ff16d9ae1a20b619414ec86b540cdafe5ad7278
MD5 f57b34cb8f6f78ba5ed309884b9b3a29
BLAKE2b-256 8401c54e139a2fd273777ec5ea27cdb60b2a54e9178ea692e4e14f964612cbca

See more details on using hashes here.

Provenance

The following attestation bundles were made for edugrad-0.1.0-py3-none-any.whl:

Publisher: publish.yml on shanest/edugrad

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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