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.1.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.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: simplegrade-0.1.1.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.1.tar.gz
Algorithm Hash digest
SHA256 33f8628f5db2c202f72b020ee96e5fd6bef37b7eb0e9d4fd3ed72259ef670ba5
MD5 76108d5200364ee5b17f0521a596affb
BLAKE2b-256 b9252e52c65c2548fa615771142d05f117e5a3c11f0dba02e65236d930d9036f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: simplegrade-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f4d766c331d53e68b8f5a3a06d936212ee03c61adafb7bedcd185655f8ea5866
MD5 4c0d2da34ac01908fb0bcd68cd51c54c
BLAKE2b-256 1f41b2aab9d77e6827c9f0f66d4b5876ee2006c786b346690deed83b1d29c8ad

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