Skip to main content

Basic computation graph, 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.

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 using python main.py from an environment with the packages from requirements.txt.

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.0.5.tar.gz (6.6 kB view hashes)

Uploaded Source

Built Distribution

edugrad-0.0.5-py3-none-any.whl (20.6 kB view hashes)

Uploaded Python 3

Supported by

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