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.6.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.6-py3-none-any.whl (23.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for trifast-0.1.6.tar.gz
Algorithm Hash digest
SHA256 82bc78f008e3631499030ac9add404be7376442127185fd7e948b125990c190b
MD5 a8515c1cb45d7c1291c4ca0a7fc6ddec
BLAKE2b-256 efbe33cfd2602fb37d5f112cbb2426998cf604fee301d199bba11f0b00f7d1c4

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for trifast-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 79ea9340a1e6b6fb50acbdf49194c1cb8b91b1ba570cf82896fd4630e2a8bf7b
MD5 a5c72e9f063b7dd940e84f3747336329
BLAKE2b-256 5ab76fd58112ee19f707340dc2e0f3ba18cde6279e3cff143507af55a175c39d

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