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/

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

leanpass-0.1.8.tar.gz (14.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

leanpass-0.1.8-py3-none-any.whl (9.9 kB view details)

Uploaded Python 3

File details

Details for the file leanpass-0.1.8.tar.gz.

File metadata

  • Download URL: leanpass-0.1.8.tar.gz
  • Upload date:
  • Size: 14.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.16

File hashes

Hashes for leanpass-0.1.8.tar.gz
Algorithm Hash digest
SHA256 ec922b7bfa6d428e1b2f098a48e405b2b7a5843447c272e4573a29682de9e8fa
MD5 3b16821ea8397775bc68c941596c0419
BLAKE2b-256 85c9f13c5a7cd6c0fa88fdf02b194ee430197ce1022bf6fa26016b986b5f5636

See more details on using hashes here.

File details

Details for the file leanpass-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: leanpass-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 9.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.16

File hashes

Hashes for leanpass-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 3bf09342d4a0969b77d53694f9a437ee1ff160621d077178c91d0969e56968a7
MD5 1f89a60e79a9d1d54e76d52538ea42fb
BLAKE2b-256 924cf3a1c5e6a295f739adefc4242103c3ef410f267f1d3acaa0c0f26661d5ea

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.10

2 files

0.1.9

2 files

This release

0.1.8 This release

2 files

0.1.7

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

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