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
NumPyfor CPU operations andCuPyfor GPU operations. - Neural Networks: Includes simple layers like
Linearand activations likeReLU - 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 ifnvccis 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d458791085fce9810f7f01589c34955a848871992c06f81ae23bd055bff93f93
|
|
| MD5 |
22a14a4c342a56a6b05805b696b3786a
|
|
| BLAKE2b-256 |
be960e4985f797dad13bdcf0e3d69ed472ee8a5b9096dbe2f4a0dc3543b28eff
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
18b099bf0507fc29f1b61d078b8d5d3a00dccad0fae09ed02eca842a911772a7
|
|
| MD5 |
d873bf6b3755f47dfa0c7a30d22f6f16
|
|
| BLAKE2b-256 |
d79f9b1166bdb525d3ca55bf82393b79017851a47bd6223c6a6f925aade4ff55
|