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

Uploaded Python 3

File details

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

File metadata

  • Download URL: monograd-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 eb8aa8bca5277dc039692b18cfea6854be9a167251ce725d545e320bbc098605
MD5 ee360f55ccda452baf2db4ab773ba431
BLAKE2b-256 ba6cb8e13b5022c02b575692a2cd6aa0b162560467fde8ffe15f06be4bbbdcad

See more details on using hashes here.

File details

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

File metadata

  • Download URL: monograd-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e16feb0832d9abee5a1c3574db783469720d3afe9e70e5e6675b2aed56e8e2ac
MD5 e802c075427af151185bf6ba78797dc8
BLAKE2b-256 d5994112280a4344e4d1c4aeef25fa7df5ae06f54501c67c3ab5b2ba68e60183

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