Skip to main content

A lightweight, transparent alternative to PyTorch/TensorFlow built on NumPy.

Project description

LeanPass

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

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.softmax()
  • Tensor.backward()

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.mse_loss(predictions, targets) computes mean squared error.

Optimizers

from leanpass import optim

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

Available optimizers:

  • optim.SGD(parameters, lr=...) performs simple gradient descent.
  • optim.Adam(parameters, lr=...) performs Adam optimization with bias correction.

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.

Project details


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.1.tar.gz (9.4 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.1-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: leanpass-0.1.1.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for leanpass-0.1.1.tar.gz
Algorithm Hash digest
SHA256 73cdc1b0ad9b9bb5aaa56fccb222331df2ffaae9ec3c329c778e96fbc3ea9f3d
MD5 654531bbcf8d26b0d631fcc70b21088f
BLAKE2b-256 659d5693a3f700d16038f1b06f901482962b0c469c4aafd9bb14d42579272e93

See more details on using hashes here.

File details

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

File metadata

  • Download URL: leanpass-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.15

File hashes

Hashes for leanpass-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d6b17b21756e0db5cc662c68b7d92568b04179e34cb440d24bc049f733d94c99
MD5 c0221b092b4fe191b073662200f37b4e
BLAKE2b-256 6bc5fd6d4335fe79394fa9d958533abb9b2659ff507cf12a930763c3a5e14a97

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page