Skip to main content

High-performance sigmoid attention kernels using Triton

Project description

Triton Sigmoid Attention

Python 3.11+ PyTorch 2.6+ License: MIT Code style: black

Fused sigmoid attention kernels for NVIDIA GPUs built with Triton.

Overview

Two implementations:

  • Dense - Same-length sequences (fastest)
  • Padded - Variable-length with padding masks

Features torch.compile support and causal masking. Requires Ampere architecture or newer.

Installation

pip install triton-sigmoid
Development install from source
git clone https://github.com/MSDLLCpapers/triton-sigmoid.git
cd triton-sigmoid
uv sync --extra dev
source .venv/bin/activate

Quick Start

Dense Attention (Same-Length Sequences)

import torch
from triton_sigmoid import sigmoid_attention

batch, seq_len, n_heads, head_dim = 2, 1024, 8, 64
q = torch.randn(batch, seq_len, n_heads, head_dim, device='cuda', dtype=torch.float16)
k = torch.randn(batch, seq_len, n_heads, head_dim, device='cuda', dtype=torch.float16)
v = torch.randn(batch, seq_len, n_heads, head_dim, device='cuda', dtype=torch.float16)

output = sigmoid_attention(q, k, v, is_causal=False)
output_causal = sigmoid_attention(q, k, v, is_causal=True)

Padded Attention (Variable-Length Sequences)

import torch
from triton_sigmoid import sigmoid_attention_padded

batch, seq_len, n_heads, head_dim = 2, 1024, 8, 64
q = torch.randn(batch, seq_len, n_heads, head_dim, device='cuda', dtype=torch.float16)
k = torch.randn(batch, seq_len, n_heads, head_dim, device='cuda', dtype=torch.float16)
v = torch.randn(batch, seq_len, n_heads, head_dim, device='cuda', dtype=torch.float16)

seq_lens_k = torch.tensor([800, 950], device='cuda', dtype=torch.int32)
seq_lens_q = torch.tensor([800, 950], device='cuda', dtype=torch.int32)

output = sigmoid_attention_padded(q, k, v, seq_lens_k=seq_lens_k, seq_lens_q=seq_lens_q)

compiled_fn = torch.compile(sigmoid_attention_padded)
output = compiled_fn(q, k, v, seq_lens_k=seq_lens_k, seq_lens_q=seq_lens_q, is_causal=True)

Performance

TFLOPS Comparison

See benchmarks/README.md for details.

Documentation

License

MIT License - see LICENSE file for details.

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Citation

If you use this work in your research, please cite our paper:

@misc{sadashivaiah2026bettermodelsfastertraining,
      title={Better Models, Faster Training: Sigmoid Attention for single-cell Foundation Models}, 
      author={Vijay Sadashivaiah and Georgios Dasoulas and Judith Mueller and Soumya Ghosh},
      year={2026},
      eprint={2604.27124},
      archivePrefix={arXiv},
      primaryClass={cs.LG},
      url={https://arxiv.org/abs/2604.27124}, 
}

Acknowledgments

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

triton_sigmoid-0.1.0.tar.gz (29.0 kB view details)

Uploaded Source

Built Distribution

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

triton_sigmoid-0.1.0-py3-none-any.whl (21.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: triton_sigmoid-0.1.0.tar.gz
  • Upload date:
  • Size: 29.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for triton_sigmoid-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b7c80e5c5cfd79532a6839b0466ccf9ceb77208b573e719db1a7d522b3e484fd
MD5 3d958dc3eedd174e6918b8c633b78754
BLAKE2b-256 49033e5f6a8b08326825a3686b55aae9c222db46c88087e46b96ee2697f8c0e5

See more details on using hashes here.

Provenance

The following attestation bundles were made for triton_sigmoid-0.1.0.tar.gz:

Publisher: publish.yml on MSDLLCpapers/triton-sigmoid

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

File details

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

File metadata

  • Download URL: triton_sigmoid-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 21.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for triton_sigmoid-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b624d76c5707a3aa3a1b9345a0fefba5a30d70b61683f4c5077e02949a0739cf
MD5 097b44e69ca6940ce107418ad57205d3
BLAKE2b-256 bab885c838e7f33b4053a0a5f54e29d0485d163c48b2c2d7091e6fe6233642dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for triton_sigmoid-0.1.0-py3-none-any.whl:

Publisher: publish.yml on MSDLLCpapers/triton-sigmoid

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