Sparse Attention using Number Theory
// momentum
// why it's here
- Active: last commit today
- Built almost entirely by one person
- Health 92/100 with only 6 stars
// how to help
// readme
PrimeAttention.jl
A sparse, number-theoretic attention mechanism library for Lux.
Julia 1.11 required, 1.12 or higher recommended.
Overview
PrimeAttention.jl provides sparse attention layers that leverage number-theoretic sequences to define connectivity patterns. By using mathematical sequences instead of dense matrices or random sparsity, these layers achieve long-range dependencies with significantly lower computational complexity than standard $O(N^2)$ Transformers.
Inspired by architectures like BigBird, this package implements a hybrid mechanism that combines three strategies:
- Global Tokens: For sequence-wide context summaries.
- Sliding Window: For local syntax and immediate context.
- Theoretic Intervals: Sparse long-range connections based on Primes, Squares, or the Mian-Chowla sequence.
Usage
The package provides factory functions that return a SparseIndexAttention layer. Because this library is built on Lux.jl, it utilizes explicit parameter and state management.
Here is a simple example: