Maintained. Last release 11 months ago. Weaker on release cadence.
pip install accelerated-scanREADME as published on PyPI with version 0.3.1.
Accelerated Scan
This package implements the fastest first-order parallel associative scan on the GPU for forward and backward.
The scan efficiently solves first-order recurrences of the form x[t] = gate[t] * x[t-1] + token[t], common in state space models and linear RNNs.
The accelerated_scan.warp C++ CUDA kernel uses a chunked processing algorithm that leverages the fastest GPU communication primitives available
on each level of hierarchy: warp shuffles within warps of 32 threads and shared memory (SRAM) between warps within a thread block. One sequence per channel dimension is confined to one thread block.
The derivation of Chunked Scan has been used to extend tree-level Blelloch algorithm to block.
A similar implementation is available in accelerated_scan.scalar using a Triton's tl.associative_scan primitive. It requires at least Triton 2.2 for its enable_fp_fusion flag.
Quick Start:
pip install accelerated-scan
import torch
from accelerated_scan.scalar import scan # uses tl.associative_scan in chunks
#from accelerated_scan.warp import scan # a pure c++ kernel, faster than cub
#from accelerated_scan.ref import scan # reference torch implementation
batch_size, dim, seqlen = 1, 512, 131072
forget = 0.999 + 0.001 * torch.rand(batch_size, dim, seqlen, device="cuda")
inputs = torch.rand(batch_size, dim, seqlen, device="cuda")
out = scan(forget, inputs)
To ensure numerical equivalence, a reference implementation for trees is provided in Torch. It can be sped up using .

