Skip to main content

No project description provided

Project description

monograd

Something between PyTorch and tinygrad


Monograd supports

  • Tensor library and API
  • Reverse-mode autograd differentiation with a dynamic graph (DAG)
  • JIT GPU Kernel compiler
  • nn / optim / datasets for training

It is a lightweight, define-by-run deep learning framework built from scratch. Designed to be readable and hackable. It's a very small framework aimed at simplicity that can train real networks to high accuracy.


Making a simple neural net in monograd:

from monograd.tensor import Tensor
from monograd.nn import Module, Linear, optim

class MyNet(Module):
    def __init__(self):
        self.l1 = Linear(784, 128)
        self.l2 = Linear(128, 10)

    def forward(self, x):
        x = self.l1(x).relu()
        x = self.l2(x)
        return x

model = MyNet()
optim = optim.SGD(model.parameters(), lr=0.01)
# Training is the same as pytorch

monograd vs Pytorch

from monograd.tensor import Tensor

y = Tensor([[2.0,0,-2.0]], requires_grad=True)
z = y.matmul(x).sum()
z.backward()

print(x.grad) # dz/dx
print(y.grad) # dz/dy

Same thing but in PyTorch

import torch

y = torch.tensor([[2.0,0,-2.0]], requires_grad=True)
z = y.matmul(x).sum()
z.backward()

print(x.grad.tolist())  # dz/dx
print(y.grad.tolist())  # dz/dy

Turns out you can build 95% of real world networks with monograd's available framework

Available Optimizers

  • SGD(Stochastic Gradient Descent) with momentum
  • Adam(Adaptive Momet Estimation)

Available Network Layers

  • Linear
  • Conv2D
  • MaxPool2D

Available OPs

  • ADD
  • SUM
  • SUB
  • MUL
  • Transpose
  • ReLu
  • LeakyReLu
  • Reshape
  • LOG
  • EXP

Running tests

chmod +x test-all.sh
./test-all.sh # will run all available tests

Run MNIST! (running on Conv2D and MaxPool2D)

PYTHONPATH=. python3 examples/mnist.py

Roadmap

  • Conv2d (CPU)
  • MaxPool2D (CPU)
  • general refactoring with tinygrad-like file struct(nn, datasets)
  • GPU Support (CUDA/HIP)
  • GPU kernel code gen (JIT)

Installation & Dependencies

Only dependency is numpy!

git clone https://github.com/yourusername/monograd.git
cd monograd
pip install numpy

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

monograd-0.1.1.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

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

monograd-0.1.1-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: monograd-0.1.1.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for monograd-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7066dfc15d3904a10b1c30fcb55a8bf8645fb90f298c3f30e2c5b9dadd1d47b5
MD5 13892319ae1adfb9f53910fd66877881
BLAKE2b-256 702951dcd6ca531c8f6bcd0824ec60067736b941be453156a1fe34b5655e6b40

See more details on using hashes here.

File details

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

File metadata

  • Download URL: monograd-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for monograd-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 85497e2ac6bb8a521c4310ab1dd2827042c314a36a550ed3793bb4bca33b953f
MD5 b4cea656c56fe66083857d0fb8ad309f
BLAKE2b-256 f5a00b80b6aae116014f339b5e30c854b0b831240198d0cd224cda573d3b84e5

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