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.8.tar.gz (15.8 MB 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.8-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: trifast-0.1.8.tar.gz
  • Upload date:
  • Size: 15.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.21

File hashes

Hashes for trifast-0.1.8.tar.gz
Algorithm Hash digest
SHA256 2eb1e8d3fbfd3e44aad3bccb3871275b3e2ce9d31ff5448b30cff29fec66416a
MD5 2d4f3daa50c5ae8b2c64724e2a9262cb
BLAKE2b-256 2160f5e430d0b741884083cd0e76017accb685f98b8510daccb23c4a2fc9ece0

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for trifast-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 f04bb28013a624b8d4231332cc61afc16274084b69d8995d6bd065860b4e9519
MD5 b9d1f6ec937e59b647cd8eaace8ce9e4
BLAKE2b-256 d52fe5aefc2849e76c16d54b2164979a8d020440dc3c569d3f4f9d0f07dc0f81

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