Skip to main content

An implementation of softmax linear unit (solu) in PyTorch

Project description

SoLU - Softmax Linear Unit

This repository packages an implementation of Sofmax Linear Unit, as proposed in Softmax Linear Units.

Module Structure

SoLU -> SoLU, SoLULayer

Performance Penalty Mitigation

The original paper talks about a performance penalty with softmax linear unit which can be mitigated with an additional Layer Norm. This mitigation has been applied in the SoLULayer module in this package. The activation function itself is in the SoLU module.

Example Usage

Installation

pip install softmax-linear-unit

Code import

[!NOTE] SoLU and SoLULayer are torch.nn modules and hence can be used in any pytorch model definition.

import torch
from SoLU import SoLULayer, SoLU


@torch.no_grad()
def main():
    # batch_size=2, seq_len=5, hidden_dim=4
    x = torch.randn(2, 5, 4)

    # Initialize the layer (SoLU + LayerNorm)
    solu_block = SoLULayer(hidden_size=4)

    # Forward Pass
    output = solu_block(x)
    print(output)
    print(output.size())


if __name__ == "__main__":
    main()

You can also check main.py

Local Dev

Env

# make sure to have uv installed
# also python 3.12.11

uv sync
source .venv/bin/activate

Ruff and Pre-Commit

By default, pre-commit will run ruff formatting with the --fix flag.

[!NOTE] The pre-commit configuration can be found in the .pre-commit-config.yaml file.

pre-commit install

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

softmax_linear_unit-1.0.1.tar.gz (53.8 kB view details)

Uploaded Source

Built Distribution

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

softmax_linear_unit-1.0.1-py3-none-any.whl (26.9 kB view details)

Uploaded Python 3

File details

Details for the file softmax_linear_unit-1.0.1.tar.gz.

File metadata

  • Download URL: softmax_linear_unit-1.0.1.tar.gz
  • Upload date:
  • Size: 53.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for softmax_linear_unit-1.0.1.tar.gz
Algorithm Hash digest
SHA256 e5ae809f4ce9bd9c422e4da71a32683e13557467872ee81fbbce10665f631401
MD5 becb9d488e2500caff477b0678929220
BLAKE2b-256 0b5c9df0d75a8ccbef1bbce80c9fc6b9b6053e147574bebd8097fca4fbd3d128

See more details on using hashes here.

File details

Details for the file softmax_linear_unit-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: softmax_linear_unit-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 26.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.26 {"installer":{"name":"uv","version":"0.9.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Fedora Linux","version":"43","id":"","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for softmax_linear_unit-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ac458b8169bb4789de69b4ab68b43a772cc2963354de0b9bcd2d22c7d5108caa
MD5 ad3e3997d25f3b0a13e11758673d3f80
BLAKE2b-256 b2c1e12a1f8ed20cbe4ab7b35e0f6fce72faf193f6110c6e9671f6112b0cf1d0

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