Skip to main content

A Python package called seli

Project description

Seli

Minimizing the time from idea to implementation with flexible neural networks in seli.

Python Tests

Features

  • Mutable modules for quick and dirty modifications via Module
  • Serialization of modules via @saveable, save, and load
  • Systematically modifying modules by traversing nested modules
  • Safely handling shared/cyclical references and static arguments through seli.jit
  • Commonly used NN layers and optimizers are included
  • As a small codebase, it is relatively easy to understand and extend

Quick Example

Define new layers by subclassing seli.Module. All modules are PyTrees.

import seli

# add a name to make the module saveable
class Linear(sl.Module, name="example:Linear");
    def __init__(self, dim: int)
        self.dim = dim

        # parameters can be directly initialized
        # or an initialization method can be passed
        self.weight = seli.Param(init=seli.init.Normal("Xavier"))

    def __call__(self, x):
        # the weight gets initialized on the first call
        # by providing the shape, the value is stored
        return x @ self.weight((x.shape[-1], self.dim))


# set the rngs for all submodules at once
# no code for passing rngs around is needed
model = Linear(10).set_rngs(42)
y = model(jnp.ones(8))

A training step can be written as follows, it requires python 3.11 or newer.

optimizer = seli.opt.Adam(1e-3)
loss = seli.opt.MeanSquaredError()

x = jnp.ones(32, 8)
y = jnp.ones(32, 10)

optimizer, model, loss_value = optimizer.minimize(loss, model, y, x)

Models can be serialized and loaded. This process is safe and does not use pickling.

seli.save(model, "model.npz")

# load the model
seli = seli.load("model.npz")
assert isinstance(model, Linear)

Installation

You can install from PiPy using pip

pip install seli

See Also

  • Jax Docs: Jax is a library for numerical computing that is designed to be composable and fast.
  • Equinox library: FlareJax is heavily inspired by this awesome library.
  • torch.nn.Module: Many of the principles of mutability are inspired by PyTorch's torch.nn.Module.
  • NNX Docs: NNX is a library for neural networks in flax that also supports mutability.
  • Always feel free to reach out to me via email.

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

seli-0.1.1.tar.gz (45.4 kB view details)

Uploaded Source

Built Distribution

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

seli-0.1.1-py3-none-any.whl (32.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: seli-0.1.1.tar.gz
  • Upload date:
  • Size: 45.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for seli-0.1.1.tar.gz
Algorithm Hash digest
SHA256 c96db942631a767f56dd8ee655e426e15cfe967d1d00e9379928d49f08236aa1
MD5 d2fecfc7ded4ba7817f9e77b3b73c061
BLAKE2b-256 77c5a3a6deb16fd38c5cf2b621eb4c01559c10751bf755faea5d3a6e8cf37113

See more details on using hashes here.

Provenance

The following attestation bundles were made for seli-0.1.1.tar.gz:

Publisher: publish.yml on pwolle/seli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: seli-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 32.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for seli-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 68c6d82af9d1db06b20fe427466df9c5aebe4535d3b3792197f5d960e99d91de
MD5 52cc16b073b185b6bcdef9b635a412c2
BLAKE2b-256 d32d86fd62f3453022a79976396cd96862d82a5dedaaf6cdae88aa35e035c2a0

See more details on using hashes here.

Provenance

The following attestation bundles were made for seli-0.1.1-py3-none-any.whl:

Publisher: publish.yml on pwolle/seli

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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