Skip to main content

A lightweight backpropagation package for neural networks

Project description

🧠 Nanograd - Lightweight Autograd Engine for Deep Learning

Nanograd is a minimalistic automatic differentiation engine for building and training neural networks. Inspired by PyTorch’s autograd, it provides an easy-to-use framework for defining computational graphs, performing backpropagation, and training models.

🚀 Features

Automatic Differentiation - Compute gradients with ease using backpropagation.
Graph-Based Computation - Uses a dynamic computation graph to track operations.
Lightweight & Fast - No unnecessary dependencies, optimized for speed.
Custom Neural Networks - Build and train models from scratch.
Graph Visualization - Visualize computational graphs using graphviz.


📦 Installation

You can install Nanograd directly from PyPI:

pip install nanograd

🔧 Usage

1️⃣ Defining Computation

from nanograd.engine import Value

a = Value(2.0)
b = Value(3.0)
c = a * b + 5
c.backward()

print(f"Value of c: {c.data}")        # Output: 11.0
print(f"Gradient of a: {a.grad}")     # Output: 3.0
print(f"Gradient of b: {b.grad}")     # Output: 2.0

2️⃣ Building a Neural Network

from nanograd.nn import MLP
import numpy as np

# Create a 2-layer neural network (2 inputs, 4 hidden, 1 output)
model = MLP(2, [4, 1])

# Dummy data
X = np.array([[1.0, 2.0]])
y = np.array([1.0])

# Forward pass
pred = model.forward(X)
print(f"Prediction: {pred}")

3️⃣ Visualizing Computational Graph

from nanograd.graph import draw_graph
draw_graph(c)  # Generates a graph of computations

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

nanograd-aman-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

File details

Details for the file nanograd-aman-0.1.0.tar.gz.

File metadata

  • Download URL: nanograd-aman-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for nanograd-aman-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d44b5e9936f74fde791ad2149d0d5d0fff1d41a4fa9aacc70a89ec1e3c6d2b33
MD5 50286f4a9a538f0ef0c9384fb904d9ba
BLAKE2b-256 e35b2468ef9f48111e2821bffbd1f60a7d336fab2e8d492036511e05073ab6eb

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