Skip to main content

LeanPass

LeanPass is a lightweight NumPy-based autodiff library for building small neural network models and understanding automatic differentiation in a simple, readable way.

pip install leanpass

Public API

Tensor

The core data structure is Tensor, which wraps a NumPy array and supports automatic differentiation.

from leanpass import Tensor

x = Tensor([[1.0, 2.0]], requires_grad=False)
y = Tensor([[3.0, 4.0]])
z = x + y

Supported operations:

  • Tensor + Tensor
  • Tensor - Tensor
  • Tensor * Tensor
  • Tensor / Tensor
  • Tensor ** Tensor
  • Tensor @ Tensor
  • Tensor.sum()
  • Tensor.mean()
  • Tensor.relu()
  • Tensor.sigmoid()
  • Tensor.tanh()
  • Tensor.leaky_relu()
  • Tensor.gelu()
  • Tensor.softmax()
  • Tensor.backward()
  • Tensor.clip(a_min, a_max) / Tensor.clamp(min, max)
  • Basic indexing via Tensor[...] which participates in autodiff

Neural network layers

from leanpass import nn

layer = nn.Linear(4, 8)
mlp = nn.MLP([4, 16, 8])

Available components:

  • nn.Linear(in_features, out_features) creates a linear layer with weights and bias.
  • nn.MLP(layer_sizes) creates a multilayer perceptron with ReLU activations between layers.
  • nn.Dropout(p=0.5) creates an inverted-dropout layer for training-time regularization.
  • nn.mse_loss(predictions, targets) computes mean squared error.
  • nn.cross_entropy_loss(predictions, targets) computes categorical cross-entropy for multi-class targets.
  • nn.binary_cross_entropy_loss(predictions, targets) computes binary cross-entropy for binary classification.

Optimizers

from leanpass import optim

optimizer = optim.SGD(model.parameters(), lr=0.01)
# or
optimizer = optim.Adam(model.parameters(), lr=0.001)

Available optimizers (options):

  • optim.SGD(parameters, lr=..., momentum=0.0, weight_decay=0.0) supports momentum and L2 weight decay.
  • optim.Adam(parameters, lr=..., weight_decay=0.0) supports an optional L2 weight decay term.

Example

from leanpass import Tensor, nn, optim

x = Tensor([[1.0, 2.0]], requires_grad=False)
model = nn.MLP([2, 16, 3])
output = model(x)
print(output)

Notes

This package is intended for clarity and educational use, with a compact implementation that makes the autodiff process easier to inspect.

Full documentation: https://leanpass.kilobyte136.workers.dev/

Metadata

Release files for leanpass 0.1.11

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for leanpass 0.1.11
File Size Uploaded Provenance Actions
leanpass-0.1.11.tar.gz 15.2 kB Without provenance Details for leanpass-0.1.11.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for leanpass 0.1.11
File Interpreter ABI Platform Actions
leanpass-0.1.11-py3-none-any.whl Python 3 none any Details for leanpass-0.1.11-py3-none-any.whl

Total release size: 25.9 kB

Release files / leanpass-0.1.11.tar.gz

Download URL leanpass-0.1.11.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
92682ffefe9176513a47ed1a323f6bf300ded0b58c8b15d0cf09bdeaa2caf5ba
BLAKE2b-256 checksum
How to use checksums
b90ca3bd95941ee2b8a8e33290bddd3f218226f79801f563f4e6e9e560d10975
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Release files / leanpass-0.1.11-py3-none-any.whl

Download URL leanpass-0.1.11-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1a0551a8c63c4427c778249d1f13e64c267325178ce71bd7d578374678854133
BLAKE2b-256 checksum
How to use checksums
1792103eeb81c8b89caa6494093e4ba320242fe03b2c07857631bdaf6d52d701
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.11.16

Security for leanpass 0.1.11

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page