🚀 GradLite
A tiny, elegant automatic differentiation engine built from scratch.
GradLite is a lightweight module for automatic gradient computation, the core mechanism behind training neural networks using backpropagation.
Inspired by:
...but extended to support more features than MicroGrad, without all the complexity of PyTorch. This module supports building complete neural networks and has a clear educational purpose.
✨ Features
- 🧠 Reverse-mode automatic differentiation (backpropagation)
- 🔢 Scalar-based computational graph
- 🔄 Dynamic graph construction
- 🏗️ Build full neural networks (Linear layer support for now! 🗓️)
- 🪶 Lightweight and easy to read
- 📚 Fully Educational
📦 Installation
You can run the following command to install gradlite in your system/virtual environment:
pip install gradlite
🧩 Example Usage
The usage of gradlite to build expressions and run backpropagation (automatic differentation) is shown next:
from gradlite.core import Parameter
a = Parameter(2.0)
b = Parameter(0.3)
c = Parameter(1.0)
ab = a * b
f = ab + c
print(f'f={f.value:.4f}')
f.backward()
print(f'grad_f={f.grad:.4f}')
print(f'grad_a={a.grad:.4f}')
print(f'grad_b={b.grad:.4f}')
print(f'grad_c={c.grad:.4f}')
An example training loop of gradlite is given next:
from gradlite.nn.linear import Linear
from gradlite.nn.activations import ReLU
from gradlite.nn.loss.mse import MSE
from gradlite.optimizer.sgd import SGD
X = [2.00, 2.10, 2.20, 2.30, 2.40]
y = [3.00, 3.10, 3.13, 3.16, 3.19]
epochs = 2000
model = Linear(input_features=1, output_features=1, activation_fn=ReLU())
model.neurons[0].weights[0].value = 0.5 # Using positive weight to prevent Dying ReLU
optimizer = SGD(model.parameters(), lr=1e-2)
loss_fn = MSE()
for _ in range(epochs):
for x_value, y_true in zip(X, y):
optimizer.zero_grad()
y_pred = model([x_value])
loss = loss_fn(y_pred, [y_true])
loss.backward()
optimizer.step()
print(f'Loss: {loss.value:.4f}')
Metadata
Release files for gradlite 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gradlite-0.2.1.tar.gz | 117.7 kB | Without provenance | Details for gradlite-0.2.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gradlite-0.2.1-py3-none-any.whl | Python 3 | none | any | Details for gradlite-0.2.1-py3-none-any.whl |
Total release size: 129.2 kB
Release files / gradlite-0.2.1.tar.gz
| Download URL | gradlite-0.2.1.tar.gz |
|---|---|
| Size | 117.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3f6f7019ce61f78f3a812140fa1745785eef199e539290a27f15d1358d52912b
|
|
BLAKE2b-256 checksum How to use checksums |
1a0c02dcafbb3a3bb0873832829a8d7cc322bfdbfa583c2e7585928fc909ce8e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / gradlite-0.2.1-py3-none-any.whl
| Download URL | gradlite-0.2.1-py3-none-any.whl |
|---|---|
| Size | 11.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3368f81288af2ade12437ef63b59a3f250a4d5b59a8410af4948614f22bd60b0
|
|
BLAKE2b-256 checksum How to use checksums |
14389852641c18091a3187fb8d7e8c5be9c097bfbe013961d0c5580c3020278c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for gradlite 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.