Skip to main content

Automatic routing between attention backends (dense, flash, sparse)

Project description

autoattn

Automatic routing between attention backends for LLMs/VLMs.

Install

pip install -e .

Usage

import torch
from autoattn import AutoAttention

attn = AutoAttention(d_model=256, num_heads=8, causal=True)

q = torch.randn(2, 128, 256)
k = torch.randn(2, 128, 256)
v = torch.randn(2, 128, 256)

out = attn(q, k, v)  # Automatically picks best backend

Backends

Backend When Used Memory Exact?
dense CPU, fallback O(N²)
flash GPU, seq ≤ 2048 O(N)
local GPU, seq > 4096, memory mode O(N·W)

Modes

# Auto (default) - picks based on device/seq length
AutoAttention(d_model=256, num_heads=8, mode="auto")

# Performance - prefer flash on GPU
AutoAttention(d_model=256, num_heads=8, mode="performance")

# Memory - prefer local/sparse
AutoAttention(d_model=256, num_heads=8, mode="memory")

Requirements

  • Python ≥ 3.9
  • PyTorch ≥ 2.0

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

autoattn-0.1.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

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

autoattn-0.1.0-py3-none-any.whl (10.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for autoattn-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c472d05d404595b4258bae1bd3373825122b19a45ad508a063db9a0b8dd52377
MD5 cb142dfd79e0a76a49c1f843ab3ef723
BLAKE2b-256 4be0712dbeecbb73a7dae9fb61972c30b0f4ce388220c9851a51a9d65213cd88

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on achintya-p/auto_attn

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

File details

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

File metadata

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

File hashes

Hashes for autoattn-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 05d4ea04136cae890734d90b7d78345afd1b917e8066d019aeaa9da347490c01
MD5 e01ae97d92aff03d81a2349670232fe6
BLAKE2b-256 9c6955b7ba7b1677803c1fedb557f00857f2921a86a45e61f86a0498ece42c1b

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on achintya-p/auto_attn

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