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

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.12
File Size Uploaded Provenance Actions
leanpass-0.1.12.tar.gz 16.3 kB Without provenance Details for leanpass-0.1.12.tar.gz

Built distribution (wheel)

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

Total release size: 27.4 kB

Release files / leanpass-0.1.12.tar.gz

Download URL leanpass-0.1.12.tar.gz
Size 16.3 kB
Tags Source
SHA-256 checksum
How to use checksums
46b959b8db7e066258243f959a8aa135240d4092ce229cb025c56998fb7a33fe
BLAKE2b-256 checksum
How to use checksums
e5f44f9b43358a6eb75192e36d85cbde5410731ade8405b64a2a6c4de80bbdeb
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.12-py3-none-any.whl

Download URL leanpass-0.1.12-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2b1db15e2d64159ba07742b00b0b33e288369dc9863746422362a147fc0077e5
BLAKE2b-256 checksum
How to use checksums
71b990705f7217e0c44ed4cbb1fe5462be29e5685f104ef6d75d2c73ae4b1d66
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.12

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