Skip to main content

AdaSplash

PyPI version Hugging Face models License: BSD-3-Clause

AdaSplash is a Triton implementation of adaptive sparse attention based on entmax. It exposes the original AdaSplash kernels and the newer 🆕 AdaSplash-2 kernels through a backwards-compatible Python API.

  • AdaSplash-1: adaptive sparse flash attention with entmax and block masking.
  • 🆕 AdaSplash-2: faster differentiable sparse attention based on histogram initialization, hybrid threshold solving, and a v2 sparse causal attention path.

Papers:

Installation

Install from PyPI:

pip install adasplash

Or install the latest development version:

pip install git+https://github.com/deep-spin/adasplash.git

AdaSplash requires PyTorch and Triton. CUDA is required to run the Triton kernels, but package imports are lazy, so import adasplash works without an active CUDA driver.

What Is New In 🆕 AdaSplash-2?

AdaSplash-2 keeps the same sparse-entmax motivation as AdaSplash-1, but improves the core threshold and attention path:

  • Histogram initialization for faster entmax threshold estimates.
  • Hybrid solver updates that combine robust root-finding steps for the entmax threshold.
  • Sparse causal v2 attention exposed as adasplash_v2.
  • Grouped-query attention support through different query and key/value head counts.
  • Variable-length sequence support with padded rows zeroed in the output.
  • Convenience v2 entmax APIs for sparsemax, entmax-1.5, and generic entmax calls.

In adasplash>=0.2.0, bare adasplash(q, k, v) defaults to the AdaSplash-2 path when the call is supported. Explicit v1 entry points remain available for backwards compatibility.

Public API

All public functions can be imported from the top-level package:

from adasplash import (
    adasplash,
    adasplash_v1,
    adasplash_v2,
    adasplash_no_block_mask,
    triton_entmax,
    triton_entmax_v1,
    triton_entmax_v2,
    triton_sparsemax,
    triton_entmax15,
)
Function Purpose
adasplash Compatibility dispatcher. Uses v2 for supported causal alpha=1.5 calls and falls back to v1 for v1-only behavior.
adasplash_v2 Direct AdaSplash-2 causal sparse attention.
adasplash_v1 Direct original AdaSplash block-mask implementation.
adasplash_no_block_mask Original v1 no-block-mask implementation.
triton_entmax Default v2 entmax API.
triton_entmax_v2 Direct v2 entmax with histogram and hybrid solver support.
triton_entmax_v1 Original entmax implementation.
triton_sparsemax Convenience v2 sparsemax call, equivalent to entmax with alpha=2.0.
triton_entmax15 Convenience v2 entmax-1.5 call.

Sparse Attention Examples

Default Dispatcher

import torch
from adasplash import adasplash

q = torch.randn(1, 8, 128, 64, device="cuda")
k = torch.randn(1, 8, 128, 64, device="cuda")
v = torch.randn(1, 8, 128, 64, device="cuda")

out = adasplash(q, k, v)

For supported causal alpha=1.5 calls, adasplash routes to AdaSplash-2. Calls that request v1-only behavior, such as alpha != 1.5 or is_causal=False, route to the v1 implementation.

# Uses AdaSplash-2.
out_v2_default = adasplash(q, k, v, is_causal=True)

# Uses the v1 compatibility path.
out_v1_alpha = adasplash(q, k, v, alpha=1.333)
out_v1_noncausal = adasplash(q, k, v, is_causal=False)

Explicit V1 And V2 Calls

from adasplash import adasplash_v1, adasplash_v2

out_v1 = adasplash_v1(q, k, v, alpha=1.5, is_causal=True, niter=10)
out_v2 = adasplash_v2(q, k, v, niter=1)

Variable-Length Sequences

from adasplash import adasplash

varlen = torch.tensor([96], device="cuda", dtype=torch.int32)
out = adasplash(q, k, v, varlen=varlen)

Rows beyond each valid sequence length are zeroed in the output.

Grouped-Query Attention With AdaSplash-2

from adasplash import adasplash_v2

q = torch.randn(1, 8, 256, 64, device="cuda")
k = torch.randn(1, 2, 256, 64, device="cuda")
v = torch.randn(1, 2, 256, 64, device="cuda")

out = adasplash_v2(q, k, v)

adasplash_v2 supports grouped-query attention when the number of query heads is divisible by the number of key/value heads.

Triton Entmax Examples

import torch
from adasplash import triton_entmax, triton_entmax_v1, triton_sparsemax, triton_entmax15

x = torch.randn(128, 256, device="cuda")

y = triton_entmax(x, alpha=1.5, n_iter=2, use_histogram=True)
y_v1 = triton_entmax_v1(x, alpha=1.5, n_iter=10, fast_math=True)
y_sparsemax = triton_sparsemax(x)
y_entmax15 = triton_entmax15(x)

triton_entmax points to the v2 implementation in 0.2.0. Strict v1 users should call triton_entmax_v1.

For generic alpha values other than 1.5 and 2.0, v2 disables histogram initialization internally and uses more refinement iterations for correctness.

Attention Examples

The examples/attention.py file contains two small helpers that show the difference between the fused AdaSplash kernel and a dense reference-style implementation.

Flash Entmax Attention

from examples.attention import flash_entmax_attention

out = flash_entmax_attention(q, k, v, is_causal=True)

flash_entmax_attention is a thin example wrapper around adasplash, the actual fused flash entmax attention path.

Slow Dense Entmax Attention

from examples.attention import slow_entmax_attention

out = slow_entmax_attention(q, k, v, is_causal=True, padding="right")

slow_entmax_attention materializes dense attention scores and applies triton_entmax. It is useful for examples and small correctness checks, but it is not the AdaSplash flash kernel and should not be used for long contexts.

Backwards Compatibility

AdaSplash 0.2.0 changes the default direction of the top-level APIs:

  • adasplash(q, k, v) uses AdaSplash-2 when the call is supported.
  • triton_entmax(x) uses the v2 entmax implementation.
  • Explicit v1 names are preserved: adasplash_v1, adasplash_no_block_mask, and triton_entmax_v1.

If you need strict AdaSplash-1 behavior, use the _v1 names directly.

Testing

Install development dependencies:

pip install -r requirements-dev.txt

No-GPU import and public API checks:

TRITON_INTERPRET=1 pytest -q

Fast CUDA suite:

pytest -q -m "not slow and not stress"

Slow CUDA correctness suite:

pytest -q -m "slow"

Stress tests run dense reference checks for long contexts and may skip cases when the current GPU does not have enough memory or shared memory:

pytest -q -m "stress"

Benchmarks And Models

Efficiency AdaSplash-1

Benchmark AdaSplash-1

Efficiency AdaSplash-2

Benchmark AdaSplash-2

Sparse Models

Sparse models and related artifacts are hosted under the SARDINE Lab Hugging Face organization.

For single-vector retrieval experiments, see the Sparse ModernBERT repository.

Citation

If you use AdaSplash in your research, please cite the relevant paper.

AdaSplash-1:

@inproceedings{
goncalves2025adasplash,
title={AdaSplash: Adaptive Sparse Flash Attention},
author={Nuno Gon{\c{c}}alves and Marcos V Treviso and Andre Martins},
booktitle={Forty-second International Conference on Machine Learning},
year={2025},
url={https://openreview.net/forum?id=OWIPDWhUcO}
}

AdaSplash-2:

@inproceedings{
goncalves2026adasplash,
title={AdaSplash-2: Faster Differentiable Sparse Attention},
author={Nuno Gon{\c{c}}alves and Hugo Pitorro and Vlad Niculae and Edoardo Ponti and Lei Li and Andre Martins and Marcos V Treviso},
booktitle={Forty-third International Conference on Machine Learning},
year={2026},
url={https://openreview.net/forum?id=7qpvff2gWI}
}

License

AdaSplash is licensed under the BSD-3-Clause License. See the LICENSE file for details.

Acknowledgements

We would like to the SARDINE lab team for the helpful discussions. This work was supported by the project DECOLLAGE (ERC-2022-CoG 101088763), by the Portuguese Recovery and Resilience Plan through project C64500888200000055 (Center for Responsible AI), and by FCT/MECI through national funds and when applicable co-funded EU funds under UID/50008: Instituto de Telecomunicações. Vlad Niculae is supported by the Dutch Research Council (NWO) via VI.Veni.212.228. Edoardo M. Ponti is supported by the ERC Starting Grant AToM-FM (101222956).

Release files for adasplash 0.2.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for adasplash 0.2.2
File Size Uploaded
adasplash-0.2.2.tar.gz 40.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for adasplash 0.2.2
File Interpreter ABI Platform
adasplash-0.2.2-py3-none-any.whl Python 3 none any Details

Total release size: 77.1 kB

Release files / adasplash-0.2.2.tar.gz

Download URL adasplash-0.2.2.tar.gz
Size 40.2 kB
Tags Source
SHA-256 checksum
How to use checksums
bf06f609c383c7a4cab1f0db9599d425a2eaa104fade266d2d79128dd7d50fb2
BLAKE2b-256 checksum
How to use checksums
466d748e66a33642ae7c79d6f45be83cb255831d27bc615c1733e7abe926fe99
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Release files / adasplash-0.2.2-py3-none-any.whl

Download URL adasplash-0.2.2-py3-none-any.whl
Size 36.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
36a269bbfbf6ea164dfa4813f7e8f38ba135677030255a13b3b7659a13a46d27
BLAKE2b-256 checksum
How to use checksums
4476a2b1a9b1fd0ccfc453df38bf692bf8bdbc33377790dfde717f1ed010c247
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.2.2 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page