Leanpass is a lightweight, transparent NumPy-based autodiff library for small neural network experiments. It is designed to be easy to read, simple to inspect, and practical for learning how automatic differentiation works under the hood.
Leanpass is indexed in the awesome-machine-learning repository, under the python section.
I am incredibly grateful to the early contributors helping me shape this project! Click on their profiles below to follow them and check out their work:
| Contributor | Follow | First PR |
|---|---|---|
| eeshsaxena | Follow | #18 |
| VedantMadane | Follow | #40 |
| Chirudeva-Reddy | Follow | #56 |
| bh-official | Follow | #83 |
Made with contrib.rocks.
Want to help out? I am actively looking for fresh eyes to test features, fix bugs, or improve docs. Check out the open Issues or just open a PR.
Note
If your profile picture isn't showing up yet, Contrib.Rocks can take a few days to update due to high traffic.
- Why LeanPass?
- Features
- Installation
- Documentation
- Quick start
- Examples
- Development
- Project status
- Community and contribution
- License
- Star History
- RepoVibes
- Minimal dependency footprint: only NumPy
- Clear, readable implementation instead of heavy abstraction
- Core building blocks for tensors, layers, and optimizers
- Useful for teaching, prototyping, and small-scale experimentation
- Tensor objects with reverse-mode autodiff
- Core arithmetic and matrix operations
- Activation functions such as ReLU, sigmoid, softmax, tanh, LeakyReLU, and GELU
- Linear layers and multilayer perceptrons
- Loss utilities:
mse_loss,cross_entropy_loss, andbinary_cross_entropy_loss - SGD and Adam optimizers
- SGD now supports momentum and L2 weight decay:
optim.SGD(params, lr=..., momentum=0.9, weight_decay=1e-4) - Adam supports an optional L2 weight decay:
optim.Adam(params, lr=..., weight_decay=1e-4) - Dropout layer:
nn.Dropout(p=0.5)for inverted dropout during training - Tensor utilities:
Tensor.clip(a_min, a_max)/Tensor.clamp(min, max)for value clamping - Basic indexing:
Tensor.__getitem__supports slicing/indexing that participates in autodiff - A simple demo script that trains a toy model
pip install leanpassFull documentation is available at leanpass.vercel.app and includes API reference, core concept explanations, and hands-on guides covering regression, classification, MNIST, gradient checking, and custom layers. See the changelog for the complete release history.
To delve more into the development of leanpass, you could check out the devin indexed deepwiki docs. The deepwiki docs update 1 day later of every release or update made to leanpass, note that.
When leanpass is installed, build a small neural network and run a forward pass:
from leanpass import Tensor, nn
x = Tensor([[1.0, 2.0]], requires_grad=False)
model = nn.MLP([2, 16, 3])
logits = model(x)
print(logits)Explore runnable Python examples in examples/:
| Example | File | Description |
|---|---|---|
| Classification | examples/demo.py |
3-class synthetic data with MLP |
| XOR | examples/demo_xor.py |
Classic XOR problem with 2-layer network |
| MNIST-lite | examples/demo_mnist_lite.py |
Digit classification on sklearn digits (8×8 images) |
| Regression | examples/demo_regression.py |
Sine wave fitting with MLP |
Run any example with:
python -m examples.demo # 3-class classification
python -m examples.demo_xor # XOR classification
python -m examples.demo_mnist_lite # MNIST-lite
python -m examples.demo_regression # RegressionRun the test suite from the repository root:
pytestLeanPass is an actively maintained NumPy autodiff project for education and small-scale neural network experiments. The core API is stable; bug reports and documentation improvements are welcome.
- See CONTRIBUTING.md for contribution guidelines.
- See SECURITY.md for the vulnerability disclosure process.
- Bug reports and feature requests can be opened through the issue templates in .github/ISSUE_TEMPLATE.
- Pull requests should follow the template in .github/PULL_REQUEST_TEMPLATE/pull_request_template.md.
This project is licensed under the MIT License. See LICENSE for details.

