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.13

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.13
File Size Uploaded Provenance Actions
leanpass-0.1.13.tar.gz 16.5 kB Without provenance Details for leanpass-0.1.13.tar.gz

Built distribution (wheel)

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

Total release size: 27.7 kB

Release files / leanpass-0.1.13.tar.gz

Download URL leanpass-0.1.13.tar.gz
Size 16.5 kB
Tags Source
SHA-256 checksum
How to use checksums
68e87f417a3697fb3093e344f3610035465147f22a29e8913deb0b76324f7743
BLAKE2b-256 checksum
How to use checksums
419ba07fb489ab1662b2611834e872b8302335c97761f360552247647e2dcbd6
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.13-py3-none-any.whl

Download URL leanpass-0.1.13-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e631b7db5fe8ff25ea785f9b8e78573fdecc1158f8f212200c42097e934e4231
BLAKE2b-256 checksum
How to use checksums
cb894938eebd6bdbf98acb2353831acb9b94bea2611d826070f65469c56ee714
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.13

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