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

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.14
File Size Uploaded Provenance Actions
leanpass-0.1.14.tar.gz 16.6 kB Without provenance Details for leanpass-0.1.14.tar.gz

Built distribution (wheel)

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

Total release size: 27.7 kB

Release files / leanpass-0.1.14.tar.gz

Download URL leanpass-0.1.14.tar.gz
Size 16.6 kB
Tags Source
SHA-256 checksum
How to use checksums
efae40d63040dca546d527aa188c56cf9c5903162908853ce62aa40052276d2c
BLAKE2b-256 checksum
How to use checksums
6056e6814521145b749896d0e90f7e378262e415a16fa69c5a0cde5eff80bffb
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.14-py3-none-any.whl

Download URL leanpass-0.1.14-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ebebe88d0ce43c877371fad310960edf742fe3f6806f3f55031c11a52b2ca70
BLAKE2b-256 checksum
How to use checksums
d6b5cfa82248b16a19f9a3b20143da18f77f59a34d7155025a6407e9ad045c2c
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.14

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