Skip to main content

A lightweight PyTorch-like autograd library built from scratch

Project description

SimpleGrad

SimpleGrad is a lightweight Python library for automatic differentiation and neural networks.
It is inspired by PyTorch and Tinygrad, offering a balance between simplicity, flexibility, and educational value.


Features

  • Tensor operations: +, -, *, /, @ (matmul), pow, exp, log, ln, sin, cos, tanh, relu, sigmoid.
  • Automatic differentiation: .backward() computes gradients for all operations in the computation graph.
  • Neural networks: Build networks using Linear layers and activation functions.
  • Loss functions: MSE, MAE, etc. (can be extended).
  • Gradient descent: Manual update or custom optimizers can be implemented.
  • Minimal and educational: Perfect for learning how autograd works under the hood.

from simplegrad import Tensor

# --------------------------
# Tensor operations
# --------------------------
a = Tensor([[1, 2, 3]], requires_grad=True)
b = Tensor([[2, 1, 0]], requires_grad=True)
c = a + b
d = a * b
e = d.sum()

print("c:", c)
print("d:", d)
print("e:", e)

# Backward pass
e.backward()
print("grad a:", a.grad)
print("grad b:", b.grad)

Installation

Clone the repository and install in editable mode:

git clone https://github.com/mohamedrxo/simplegrad.git
cd simplegrad
pip install -e .

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

simplegrade-0.1.0.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

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

simplegrade-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file simplegrade-0.1.0.tar.gz.

File metadata

  • Download URL: simplegrade-0.1.0.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for simplegrade-0.1.0.tar.gz
Algorithm Hash digest
SHA256 1388e82d6dcf4e58b426533c7a7f5a638007c42f968168d0b398b044f8840ffc
MD5 00669a5ea5df7b56b7ea4f6d03e9fd51
BLAKE2b-256 90c3cc7ab187cce7532da02a8e62dd86ada9a80d138003a7c76a24d324424025

See more details on using hashes here.

File details

Details for the file simplegrade-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: simplegrade-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.2

File hashes

Hashes for simplegrade-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ecb4040c5458a95d51018780584ace84a0fba2afa72bc499dfeb74cf8db131cb
MD5 60d46d0303850318b0621c67427ae331
BLAKE2b-256 a12fa22e4dcde0d986c8bebd48db0d9784888cee1809c1b9a6c614da248cb438

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