Implementing minimal Pytorch for Learning
Project description
MiniTorch
Minitorch is a way of me learning about autograd and creating a pytorch like library.
Features
- Imports like Pytorch,
- Implements basic functions like backpropagation, gradient descent, neurons, linear layers
- Extensible with suport of custom modules like Python
- You can save the model weights and load the earlier model weights too
Remaining Task
- Vectorization
- Implementing CNNs, Transformers
I am working on theory of Jacobian Matrix and it's use for computing derivatives in a vector. So, will do this in V2.
Usage
- Install the necessary packages using
pip install -r requirements.txt
- Run the individual demo using
python demos/00-autograd.py
Development Usage
Use this if only you are planning to update the package. do not use this to run the demo.
Installation
- Install all the necessary requirements using;
pip install -r requirements.txt
- Build the minitorch package for local installation.
python -m build
- Install the minitorch package locally
pip install .
Running Demos
- Demos can be found in
/demos, you can run individual of them by;
python -m ./demos/<example-file-name>.py
- If you want to create your own model, please look at documentation below.
Note that since, the minitorch library doesn't use vectorization things are not efficient hence, you cannot train the model on big data even like on MNIST. It becomes too slow. Try implementing some simpler stuffs.
Documentation
Value
- This is similar to Pytorch Tensor.
from minitorch import Value
a = Value(0.0)
a.grad # gradient of a
a.backward() # backward propagate the value
You can create a complex arithmetic operation and do backward on top to see demo of backprop. See demos/00-autograd.py.
Creating a custom model
You can import
- Linear
- Neuron
- Module
- RNN
- CrossEntropy
- MSE
- NLL
from minitorch.nn and create your own model.
Examples are at demos/01-or-gate.py, demos/02-custom-model.py.
Using activations and optimizers
Following activations;
- Sigmoid
- Softmax
- ReLU
- LogSoftmax
- TanH
can be imported from minitorch.activations.
And you can also load optimizer, for now gradient descent only.
See example at; 05-simple-polynomial.py
Demo Video
Upload from GitHub
Screenshots
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
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 minitorch_ki8yk8-1.0.3.tar.gz.
File metadata
- Download URL: minitorch_ki8yk8-1.0.3.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
121e62895c19f14fbd3e603c7c2a9181a1573390a3592c42ebf6429fd9188b43
|
|
| MD5 |
b504b293753f6321a1d37827d0bd5b32
|
|
| BLAKE2b-256 |
f51390a6dc9db2e3d4102909aae5b911965243ec308bace0db7bcd022b5fddd6
|
File details
Details for the file minitorch_ki8yk8-1.0.3-py3-none-any.whl.
File metadata
- Download URL: minitorch_ki8yk8-1.0.3-py3-none-any.whl
- Upload date:
- Size: 13.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5300c140d50e493297ac1a90e7a8f240e861501e5aca18bd17d33f8166449c8c
|
|
| MD5 |
79c9314538b494c6689ce9a287448a73
|
|
| BLAKE2b-256 |
2efcb68e13b1e0b96567d5e580951c47a9f3d169dfd92d69e4a3d11c03e807bd
|