https://github.com/marcosalvalaggio/kiwigrad
Mini deep learning framework written in Python C-API for Speed
https://github.com/marcosalvalaggio/kiwigrad
c cpython-api cpython-extensions deep-learning pypi-package python pytorch
Last synced: 10 months ago
JSON representation
Mini deep learning framework written in Python C-API for Speed
- Host: GitHub
- URL: https://github.com/marcosalvalaggio/kiwigrad
- Owner: marcosalvalaggio
- License: mit
- Created: 2023-03-04T13:49:43.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-05T10:42:29.000Z (almost 3 years ago)
- Last Synced: 2025-07-02T00:33:14.463Z (12 months ago)
- Topics: c, cpython-api, cpython-extensions, deep-learning, pypi-package, python, pytorch
- Language: C
- Homepage:
- Size: 2.58 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Kiwigrad
[](https://GitHub.com/Naereen/StrapDown.js/graphs/commit-activity) [](https://github.com/mkenney/software-guides/blob/master/STABILITY-BADGES.md#work-in-progress)
*Despite lacking the ability to fly through the skies like **PyTorch** and **TensorFlow**, the Kiwigrad is still a formidable bird that is teeming with untapped potential waiting to be uncovered.* :wink:
- [Kiwigrad](#kiwigrad)
- [Install](#install)
- [Functionalities](#functionalities)
- [Examples](#examples)
- [Running test](#running-test)
Kiwigrad? yes, it is another version of [micrograd](https://github.com/karpathy/micrograd) that was created just for fun and experimentation.
## Install
To install the current release,
```console
pip install kiwigrad==0.28
```
## Functionalities
Kiwigrad is a modified version of the [micrograd](https://github.com/karpathy/micrograd) and the [minigrad](https://github.com/goktug97/minigrad) packages with additional features. The main features added to Kiwigrad are:
* Training is faster due to the C implementation of the Value object.
* Tracing functionalities like the original [micrograd](https://github.com/karpathy/micrograd) package were added. An example of this can be seen in the [ops](examples/ops.ipynb) notebook.
* Methods for saving and loading the weights of a trained model.
* Support for RNN(1) feedforward neural networks.
### Examples
* In the [examples](examples/) folder, you can find examples of models trained using the Kiwigrad library.
* A declaration example of an MLP net using Kiwigrad:
```python
from kiwigrad import MLP, Layer
class PotNet(MLP):
def __init__(self):
layers = [
Layer(nin=2, nout=16, bias=True, activation="relu"),
Layer(nin=16, nout=16, bias=True, activation="relu"),
Layer(nin=16, nout=1, bias=True, activation="linear")
]
super().__init__(layers=layers)
model = PotNet()
```
* Kiwigrad like [micrograd](https://github.com/karpathy/micrograd) comes with support for a number of possible operations:
```python
from kiwigrad import Value, draw_dot
a = Value(-4.0)
b = Value(2.0)
c = a + b
d = a * b + b**3
c += c + Value(1.)
c += Value(1.) + c + (-a)
d += d * Value(2) + (b + a).relu()
d += Value(3.) * d + (b - a).relu()
e = c - d
f = e**2
g = f / Value(2.0)
g += Value(10.0) / f
print(f'{g.data:.4f}') # prints 24.7041, the outcome of this forward pass
g.backward()
print(f'{a.grad:.4f}') # prints 138.8338, i.e. the numerical value of dg/da
print(f'{b.grad:.4f}') # prints 645.5773, i.e. the numerical value of dg/db
draw_dot(g)
```
## Running test
```console
cd test
pytest .
```