Skip to main content

A minimal deep learning framework with automatic differentiation

Project description

minigrad

minigrad is a toy implementation of an autograd engine, inspired by Andrej Karpathy's micrograd project, with and API similar to that of PyTorch. It supports both CPU and GPU operations using NumPy and CuPy, respectively.

My goal with minigrad is to explore and learn the internals of deep learning frameworks — minigrad is not optimized for speed or efficiency. As of now it provides basic tensor operations, back propagation, neural network layers, optimizers, and loss functions.

Features

  • Tensor Operations: Supports basic tensor operations with automatic differentiation.
  • CPU and GPU Support: Use NumPy for CPU operations and CuPy for GPU operations.
  • Neural Networks: Includes simple layers like Linear and activations like ReLU
  • Optimizers: Implements basic optimizers like SGD.
  • Loss Functions: Provides loss functions like MSELoss.

Requirements

If you plan to use CuPy with GPU support, make sure you have the following installed:

  • CUDA Toolkit: Ensure that the appropriate CUDA Toolkit is installed on your machine. You can download it from NVIDIA CUDA Website.

  • nvcc: The CUDA compiler (nvcc) should be available in your environment, as it is used to detect the installed CUDA version. You can check if nvcc is installed by running:

nvcc --version

Installation

To install minigrad:

pip install minigrad-python

Usage

Basic Usage

import minigrad as mg

a = mg.Tensor([1, 2, 3], device='gpu')
b = mg.Tensor([2, 3, 4], device='gpu')
c = a + b
d = c.sum()
d.backward()
print(a.grad)
print(b.grad)

Training a Neural Network

  • A very simple example of training a neural network can be found in examples/simple_nn.py
  • TODO: Add more examples.

Run Tests

To run the unit tests and benchmarks for the project

pytest

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

minigrad_python-0.1.1.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

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

minigrad_python-0.1.1-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: minigrad_python-0.1.1.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/1.0.0 requests/2.32.3 rfc3986/1.5.0 tqdm/4.66.4 urllib3/2.2.3 CPython/3.10.12

File hashes

Hashes for minigrad_python-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d458791085fce9810f7f01589c34955a848871992c06f81ae23bd055bff93f93
MD5 22a14a4c342a56a6b05805b696b3786a
BLAKE2b-256 be960e4985f797dad13bdcf0e3d69ed472ee8a5b9096dbe2f4a0dc3543b28eff

See more details on using hashes here.

File details

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

File metadata

  • Download URL: minigrad_python-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/1.0.0 requests/2.32.3 rfc3986/1.5.0 tqdm/4.66.4 urllib3/2.2.3 CPython/3.10.12

File hashes

Hashes for minigrad_python-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 18b099bf0507fc29f1b61d078b8d5d3a00dccad0fae09ed02eca842a911772a7
MD5 d873bf6b3755f47dfa0c7a30d22f6f16
BLAKE2b-256 d79f9b1166bdb525d3ca55bf82393b79017851a47bd6223c6a6f925aade4ff55

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