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.4.tar.gz (7.0 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.4-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for trifast-0.1.4.tar.gz
Algorithm Hash digest
SHA256 32ce49d99f4ec29baf91065bab8932c362b6368998f84e4f03a2f91cefe9d0bf
MD5 a1d8cb2b7fb6ad41abe3ff58849e8826
BLAKE2b-256 39c01c0b026ae8dc60bf3e29a84e415efeadef2387c0f601001f2ec53a889062

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for trifast-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 f7763a613aeee166780fb8d4206a0329fafd31c63d7f70bbad87d535693647a3
MD5 2a460e5651032515b66c738676d7352b
BLAKE2b-256 acb7fa55b23713bcf3568b825a0241351e5dad702babd18c965bb912265047c0

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