Skip to main content

Fast kernel for triangle self attetion.

Project description

Fused Triangle Self Attention kernel, written in triton. Basically flash attention, but for triangle self attention. Implementation heavily inspired by FlagAttention and the triton fused attention tutorial.

  • n^2 memory complexity (vs n^3 for pure pytorch).
  • Faster (~2x) backward pass than next fastest implementation I could find (DS4S evoformer kernel).
  • Faster (~4x) forward pass than next fastest implementation I could find (DS4S evoformer kernel).
  • As far as I can tell, faster than naieve implementation.

Plots

All done on a 3090 in bfloat16.

Forward

TSA forward runtime TSA forward memory

Backward TSA backward runtime TSA backward memory

Todos:

  • [] Try to train a model with it.
  • [] Can we perform and of dq/db/dkv transposed?
  • [] Rewrite autotuner

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

trifast-0.1.5.tar.gz (18.7 kB view details)

Uploaded Source

Built Distribution

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

trifast-0.1.5-py3-none-any.whl (1.5 kB view details)

Uploaded Python 3

File details

Details for the file trifast-0.1.5.tar.gz.

File metadata

  • Download URL: trifast-0.1.5.tar.gz
  • Upload date:
  • Size: 18.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.2

File hashes

Hashes for trifast-0.1.5.tar.gz
Algorithm Hash digest
SHA256 564b96b3a7838edd21ba8d93997650bcb5eddfd7c110da4a289423d1f5ef290c
MD5 37ec758330e0648c3b8f8e93f21faaf0
BLAKE2b-256 6f4185a7ea0b30a8a6a0c898ed1420bde8febf6b4b14bc264ae3fda6aae5a633

See more details on using hashes here.

File details

Details for the file trifast-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: trifast-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 1.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.2

File hashes

Hashes for trifast-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 1b4a73ffcf8b8dd572eb5ea8561377c4dcde93ff898a8068d489e4ce847e4380
MD5 944905dd2b062f15d7a846c17a313f60
BLAKE2b-256 b3feaa26a41e9699dbd83e647eaaa21785994186ea65e20e90d51afb134a4a7a

See more details on using hashes here.

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