Metadata-Version: 2.4
Name: softmax-linear-unit
Version: 1.2.0
Summary: An implementation of softmax linear unit (solu) in PyTorch
Project-URL: Homepage, https://github.com/rashomon-gh/solu
Project-URL: Repository, https://github.com/rashomon-gh/solu.git
Project-URL: Issues, https://github.com/rashomon-gh/solu/issues
License: MIT License
        
        Copyright (c) 2026 Shawon Ashraf
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Requires-Python: >=3.12
Description-Content-Type: text/markdown

# SoLU - Softmax Linear Unit

This repository packages an implementation of Sofmax Linear Unit, as proposed in [Softmax Linear Units](https://transformer-circuits.pub/2022/solu/index.html#section-3-2).

## 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

```bash
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.


```python
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

```bash
# 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.

```bash
pre-commit install
```

