PyTorch implementation of Scalable-Softmax for attention mechanisms
Project description
ScalableSoftmax
An unofficial PyTorch implementation of Scalable-Softmax (Ssmax) from the paper "Scalable-Softmax Is Superior for Attention" (Nakanishi, 2025).
Overview
ScalableSoftmax is a drop-in replacement for standard Softmax that helps prevent attention fading in transformers by incorporating input size scaling. This helps maintain focused attention distributions even with large input sizes.
Installation
pip install scalable-softmax
Usage
import torch
from scalable_softmax import ScalableSoftmax
# Initialize with default parameters
ssmax = ScalableSoftmax()
# Or customize parameters
ssmax = ScalableSoftmax(
s=0.43, # scaling parameter
learn_scaling=True, # make scaling parameter learnable
bias=False # whether to use bias term
)
# Apply to input tensor
x = torch.randn(batch_size, sequence_length)
output = ssmax(x)
Features
- Drop-in replacement for standard softmax
- Learnable scaling parameter
- Optional bias term
- Maintains focused attention with large inputs
Citation
@article{nakanishi2025scalable,
title={Scalable-Softmax Is Superior for Attention},
author={Nakanishi, Ken M.},
journal={arXiv preprint arXiv:2501.19399},
year={2025}
}
License
MIT License
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file scalable_softmax-0.1.5.tar.gz.
File metadata
- Download URL: scalable_softmax-0.1.5.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
efda67c36891b8224103593aa9afca490d9e7cd8d215ee79360b7986363a70e3
|
|
| MD5 |
5a62936af9892607c25f400ca6f78c01
|
|
| BLAKE2b-256 |
00a93fe9f5b877f631c6362cfb21a2d9b2681caacf6b4bdd931a5058b7539ddb
|
File details
Details for the file scalable_softmax-0.1.5-py3-none-any.whl.
File metadata
- Download URL: scalable_softmax-0.1.5-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.22
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0fd4a87e1e8b2b28e7089fdab41e1367322b483d446678b730045fb7c008e2e6
|
|
| MD5 |
ffd64cd2f0fda851e92e215f18bb55a4
|
|
| BLAKE2b-256 |
0a540b4c3f0dc543b9a8e7e232a419d066bd1ceddd88456b35ce21358830fda2
|