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.0.tar.gz (45.9 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.0-py3-none-any.whl (32.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: seli-0.1.0.tar.gz
  • Upload date:
  • Size: 45.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.2

File hashes

Hashes for seli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 20f22ccdfd0fcc92479467c0cc94c0f4b3a646c152850048e8de35a811276880
MD5 9d6b267c1ad707088e5322d4e7f42b5e
BLAKE2b-256 76419b2c00ff249857d0dd14798c4e319bc7cddebf977eb5fa1ba464eea65541

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for seli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c719f934f1e6a59d2353ad2dea300309bb004b0e510f9323333508414c3c16e
MD5 29737e7c661cc1a88b904ded6213e879
BLAKE2b-256 b1975dc1fd827ff3550dc95d4945ea103915ca0ba5fc7489373465eeeeb94759

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