flash-linear-attention 0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. flash-linear-attention-0.1/LICENSE +21 -0
  2. flash-linear-attention-0.1/PKG-INFO +508 -0
  3. flash-linear-attention-0.1/README.md +488 -0
  4. flash-linear-attention-0.1/fla/__init__.py +104 -0
  5. flash-linear-attention-0.1/fla/layers/__init__.py +40 -0
  6. flash-linear-attention-0.1/fla/layers/abc.py +211 -0
  7. flash-linear-attention-0.1/fla/layers/attn.py +193 -0
  8. flash-linear-attention-0.1/fla/layers/based.py +95 -0
  9. flash-linear-attention-0.1/fla/layers/bitattn.py +188 -0
  10. flash-linear-attention-0.1/fla/layers/delta_net.py +290 -0
  11. flash-linear-attention-0.1/fla/layers/gated_deltanet.py +298 -0
  12. flash-linear-attention-0.1/fla/layers/gla.py +285 -0
  13. flash-linear-attention-0.1/fla/layers/gsa.py +226 -0
  14. flash-linear-attention-0.1/fla/layers/hgrn.py +153 -0
  15. flash-linear-attention-0.1/fla/layers/hgrn2.py +212 -0
  16. flash-linear-attention-0.1/fla/layers/lightnet.py +202 -0
  17. flash-linear-attention-0.1/fla/layers/linear_attn.py +159 -0
  18. flash-linear-attention-0.1/fla/layers/multiscale_retention.py +294 -0
  19. flash-linear-attention-0.1/fla/layers/nsa.py +138 -0
  20. flash-linear-attention-0.1/fla/layers/rebased.py +133 -0
  21. flash-linear-attention-0.1/fla/layers/rwkv6.py +307 -0
  22. flash-linear-attention-0.1/fla/layers/rwkv7.py +220 -0
  23. flash-linear-attention-0.1/fla/layers/simple_gla.py +254 -0
  24. flash-linear-attention-0.1/fla/models/__init__.py +41 -0
  25. flash-linear-attention-0.1/fla/models/abc/__init__.py +13 -0
  26. flash-linear-attention-0.1/fla/models/abc/configuration_abc.py +89 -0
  27. flash-linear-attention-0.1/fla/models/abc/modeling_abc.py +408 -0
  28. flash-linear-attention-0.1/fla/models/bitnet/__init__.py +13 -0
  29. flash-linear-attention-0.1/fla/models/bitnet/configuration_bitnet.py +67 -0
  30. flash-linear-attention-0.1/fla/models/bitnet/modeling_bitnet.py +437 -0
  31. flash-linear-attention-0.1/fla/models/delta_net/__init__.py +12 -0
  32. flash-linear-attention-0.1/fla/models/delta_net/configuration_delta_net.py +91 -0
  33. flash-linear-attention-0.1/fla/models/delta_net/modeling_delta_net.py +415 -0
  34. flash-linear-attention-0.1/fla/models/gated_deltanet/__init__.py +12 -0
  35. flash-linear-attention-0.1/fla/models/gated_deltanet/configuration_gated_deltanet.py +83 -0
  36. flash-linear-attention-0.1/fla/models/gated_deltanet/modeling_gated_deltanet.py +412 -0
  37. flash-linear-attention-0.1/fla/models/gla/__init__.py +13 -0
  38. flash-linear-attention-0.1/fla/models/gla/configuration_gla.py +95 -0
  39. flash-linear-attention-0.1/fla/models/gla/modeling_gla.py +417 -0
  40. flash-linear-attention-0.1/fla/models/gsa/__init__.py +13 -0
  41. flash-linear-attention-0.1/fla/models/gsa/configuration_gsa.py +97 -0
  42. flash-linear-attention-0.1/fla/models/gsa/modeling_gsa.py +420 -0
  43. flash-linear-attention-0.1/fla/models/hgrn/__init__.py +13 -0
  44. flash-linear-attention-0.1/fla/models/hgrn/configuration_hgrn.py +81 -0
  45. flash-linear-attention-0.1/fla/models/hgrn/modeling_hgrn.py +420 -0
  46. flash-linear-attention-0.1/fla/models/hgrn2/__init__.py +13 -0
  47. flash-linear-attention-0.1/fla/models/hgrn2/configuration_hgrn2.py +91 -0
  48. flash-linear-attention-0.1/fla/models/hgrn2/modeling_hgrn2.py +421 -0
  49. flash-linear-attention-0.1/fla/models/lightnet/__init__.py +13 -0
  50. flash-linear-attention-0.1/fla/models/lightnet/configuration_lightnet.py +83 -0
  51. flash-linear-attention-0.1/fla/models/lightnet/modeling_lightnet.py +410 -0
  52. flash-linear-attention-0.1/fla/models/linear_attn/__init__.py +12 -0
  53. flash-linear-attention-0.1/fla/models/linear_attn/configuration_linear_attn.py +90 -0
  54. flash-linear-attention-0.1/fla/models/linear_attn/modeling_linear_attn.py +416 -0
  55. flash-linear-attention-0.1/fla/models/mamba/__init__.py +13 -0
  56. flash-linear-attention-0.1/fla/models/mamba/configuration_mamba.py +166 -0
  57. flash-linear-attention-0.1/fla/models/mamba/modeling_mamba.py +843 -0
  58. flash-linear-attention-0.1/fla/models/mamba2/__init__.py +13 -0
  59. flash-linear-attention-0.1/fla/models/mamba2/configuration_mamba2.py +170 -0
  60. flash-linear-attention-0.1/fla/models/mamba2/modeling_mamba2.py +1093 -0
  61. flash-linear-attention-0.1/fla/models/nsa/__init__.py +15 -0
  62. flash-linear-attention-0.1/fla/models/nsa/configuration_nsa.py +75 -0
  63. flash-linear-attention-0.1/fla/models/nsa/modeling_nsa.py +399 -0
  64. flash-linear-attention-0.1/fla/models/retnet/__init__.py +13 -0
  65. flash-linear-attention-0.1/fla/models/retnet/configuration_retnet.py +92 -0
  66. flash-linear-attention-0.1/fla/models/retnet/modeling_retnet.py +425 -0
  67. flash-linear-attention-0.1/fla/models/rwkv6/__init__.py +13 -0
  68. flash-linear-attention-0.1/fla/models/rwkv6/configuration_rwkv6.py +82 -0
  69. flash-linear-attention-0.1/fla/models/rwkv6/modeling_rwkv6.py +480 -0
  70. flash-linear-attention-0.1/fla/models/rwkv7/__init__.py +13 -0
  71. flash-linear-attention-0.1/fla/models/rwkv7/configuration_rwkv7.py +105 -0
  72. flash-linear-attention-0.1/fla/models/rwkv7/modeling_rwkv7.py +491 -0
  73. flash-linear-attention-0.1/fla/models/samba/__init__.py +13 -0
  74. flash-linear-attention-0.1/fla/models/samba/configuration_samba.py +92 -0
  75. flash-linear-attention-0.1/fla/models/samba/modeling_samba.py +413 -0
  76. flash-linear-attention-0.1/fla/models/transformer/__init__.py +13 -0
  77. flash-linear-attention-0.1/fla/models/transformer/configuration_transformer.py +69 -0
  78. flash-linear-attention-0.1/fla/models/transformer/modeling_transformer.py +404 -0
  79. flash-linear-attention-0.1/fla/models/utils.py +147 -0
  80. flash-linear-attention-0.1/fla/modules/__init__.py +26 -0
  81. flash-linear-attention-0.1/fla/modules/activations.py +470 -0
  82. flash-linear-attention-0.1/fla/modules/convolution.py +363 -0
  83. flash-linear-attention-0.1/fla/modules/feature_map.py +300 -0
  84. flash-linear-attention-0.1/fla/modules/fused_bitlinear.py +638 -0
  85. flash-linear-attention-0.1/fla/modules/fused_cross_entropy.py +418 -0
  86. flash-linear-attention-0.1/fla/modules/fused_kl_div.py +321 -0
  87. flash-linear-attention-0.1/fla/modules/fused_linear_cross_entropy.py +568 -0
  88. flash-linear-attention-0.1/fla/modules/fused_norm_gate.py +817 -0
  89. flash-linear-attention-0.1/fla/modules/grpo.py +395 -0
  90. flash-linear-attention-0.1/fla/modules/l2norm.py +201 -0
  91. flash-linear-attention-0.1/fla/modules/layernorm.py +1088 -0
  92. flash-linear-attention-0.1/fla/modules/layernorm_gated.py +528 -0
  93. flash-linear-attention-0.1/fla/modules/mlp.py +126 -0
  94. flash-linear-attention-0.1/fla/modules/parallel.py +36 -0
  95. flash-linear-attention-0.1/fla/modules/rotary.py +512 -0
  96. flash-linear-attention-0.1/fla/ops/__init__.py +41 -0
  97. flash-linear-attention-0.1/fla/ops/abc/__init__.py +7 -0
  98. flash-linear-attention-0.1/fla/ops/abc/chunk.py +1115 -0
  99. flash-linear-attention-0.1/fla/ops/abc/naive.py +96 -0
  100. flash-linear-attention-0.1/fla/ops/based/__init__.py +9 -0
  101. flash-linear-attention-0.1/fla/ops/based/fused_chunk.py +374 -0
  102. flash-linear-attention-0.1/fla/ops/based/naive.py +72 -0
  103. flash-linear-attention-0.1/fla/ops/based/parallel.py +410 -0
  104. flash-linear-attention-0.1/fla/ops/common/__init__.py +1 -0
  105. flash-linear-attention-0.1/fla/ops/common/chunk_delta_h.py +391 -0
  106. flash-linear-attention-0.1/fla/ops/common/chunk_h.py +418 -0
  107. flash-linear-attention-0.1/fla/ops/common/chunk_h_parallel.py +648 -0
  108. flash-linear-attention-0.1/fla/ops/common/chunk_h_split.py +675 -0
  109. flash-linear-attention-0.1/fla/ops/common/chunk_o.py +649 -0
  110. flash-linear-attention-0.1/fla/ops/common/fused_recurrent.py +574 -0
  111. flash-linear-attention-0.1/fla/ops/common/utils.py +69 -0
  112. flash-linear-attention-0.1/fla/ops/delta_rule/__init__.py +11 -0
  113. flash-linear-attention-0.1/fla/ops/delta_rule/chunk.py +356 -0
  114. flash-linear-attention-0.1/fla/ops/delta_rule/fused_chunk.py +6 -0
  115. flash-linear-attention-0.1/fla/ops/delta_rule/fused_recurrent.py +593 -0
  116. flash-linear-attention-0.1/fla/ops/delta_rule/naive.py +120 -0
  117. flash-linear-attention-0.1/fla/ops/delta_rule/parallel.py +394 -0
  118. flash-linear-attention-0.1/fla/ops/delta_rule/wy_fast.py +504 -0
  119. flash-linear-attention-0.1/fla/ops/gated_delta_rule/__init__.py +7 -0
  120. flash-linear-attention-0.1/fla/ops/gated_delta_rule/chunk.py +374 -0
  121. flash-linear-attention-0.1/fla/ops/gated_delta_rule/fused_recurrent.py +319 -0
  122. flash-linear-attention-0.1/fla/ops/gated_delta_rule/wy_fast.py +626 -0
  123. flash-linear-attention-0.1/fla/ops/generalized_delta_rule/__init__.py +9 -0
  124. flash-linear-attention-0.1/fla/ops/generalized_delta_rule/dplr/__init__.py +7 -0
  125. flash-linear-attention-0.1/fla/ops/generalized_delta_rule/dplr/chunk.py +385 -0
  126. flash-linear-attention-0.1/fla/ops/generalized_delta_rule/dplr/chunk_A_bwd.py +418 -0
  127. flash-linear-attention-0.1/fla/ops/generalized_delta_rule/dplr/chunk_A_fwd.py +314 -0
  128. flash-linear-attention-0.1/fla/ops/generalized_delta_rule/dplr/chunk_h_bwd.py +197 -0
  129. flash-linear-attention-0.1/fla/ops/generalized_delta_rule/dplr/chunk_h_fwd.py +198 -0
  130. flash-linear-attention-0.1/fla/ops/generalized_delta_rule/dplr/chunk_o_bwd.py +482 -0
  131. flash-linear-attention-0.1/fla/ops/generalized_delta_rule/dplr/chunk_o_fwd.py +138 -0
  132. flash-linear-attention-0.1/fla/ops/generalized_delta_rule/dplr/fused_recurrent.py +292 -0
  133. flash-linear-attention-0.1/fla/ops/generalized_delta_rule/dplr/naive.py +158 -0
  134. flash-linear-attention-0.1/fla/ops/generalized_delta_rule/dplr/wy_fast_bwd.py +189 -0
  135. flash-linear-attention-0.1/fla/ops/generalized_delta_rule/dplr/wy_fast_fwd.py +319 -0
  136. flash-linear-attention-0.1/fla/ops/generalized_delta_rule/iplr/__init__.py +7 -0
  137. flash-linear-attention-0.1/fla/ops/generalized_delta_rule/iplr/chunk.py +525 -0
  138. flash-linear-attention-0.1/fla/ops/generalized_delta_rule/iplr/fused_recurrent.py +451 -0
  139. flash-linear-attention-0.1/fla/ops/generalized_delta_rule/iplr/naive.py +69 -0
  140. flash-linear-attention-0.1/fla/ops/generalized_delta_rule/iplr/wy_fast.py +345 -0
  141. flash-linear-attention-0.1/fla/ops/gla/__init__.py +11 -0
  142. flash-linear-attention-0.1/fla/ops/gla/chunk.py +1483 -0
  143. flash-linear-attention-0.1/fla/ops/gla/fused_chunk.py +631 -0
  144. flash-linear-attention-0.1/fla/ops/gla/fused_recurrent.py +113 -0
  145. flash-linear-attention-0.1/fla/ops/gla/naive.py +41 -0
  146. flash-linear-attention-0.1/fla/ops/gsa/__init__.py +9 -0
  147. flash-linear-attention-0.1/fla/ops/gsa/chunk.py +1264 -0
  148. flash-linear-attention-0.1/fla/ops/gsa/fused_recurrent.py +563 -0
  149. flash-linear-attention-0.1/fla/ops/gsa/naive.py +68 -0
  150. flash-linear-attention-0.1/fla/ops/hgrn/__init__.py +9 -0
  151. flash-linear-attention-0.1/fla/ops/hgrn/chunk.py +281 -0
  152. flash-linear-attention-0.1/fla/ops/hgrn/fused_recurrent.py +307 -0
  153. flash-linear-attention-0.1/fla/ops/hgrn/naive.py +63 -0
  154. flash-linear-attention-0.1/fla/ops/lightning_attn/__init__.py +9 -0
  155. flash-linear-attention-0.1/fla/ops/lightning_attn/chunk.py +74 -0
  156. flash-linear-attention-0.1/fla/ops/lightning_attn/fused_recurrent.py +75 -0
  157. flash-linear-attention-0.1/fla/ops/linear_attn/__init__.py +11 -0
  158. flash-linear-attention-0.1/fla/ops/linear_attn/chunk.py +65 -0
  159. flash-linear-attention-0.1/fla/ops/linear_attn/fused_chunk.py +318 -0
  160. flash-linear-attention-0.1/fla/ops/linear_attn/fused_recurrent.py +251 -0
  161. flash-linear-attention-0.1/fla/ops/linear_attn/naive.py +36 -0
  162. flash-linear-attention-0.1/fla/ops/linear_attn/utils.py +10 -0
  163. flash-linear-attention-0.1/fla/ops/nsa/__init__.py +9 -0
  164. flash-linear-attention-0.1/fla/ops/nsa/naive.py +94 -0
  165. flash-linear-attention-0.1/fla/ops/nsa/parallel.py +1434 -0
  166. flash-linear-attention-0.1/fla/ops/nsa/utils.py +90 -0
  167. flash-linear-attention-0.1/fla/ops/rebased/__init__.py +7 -0
  168. flash-linear-attention-0.1/fla/ops/rebased/naive.py +27 -0
  169. flash-linear-attention-0.1/fla/ops/rebased/parallel.py +466 -0
  170. flash-linear-attention-0.1/fla/ops/retention/__init__.py +13 -0
  171. flash-linear-attention-0.1/fla/ops/retention/chunk.py +72 -0
  172. flash-linear-attention-0.1/fla/ops/retention/fused_chunk.py +365 -0
  173. flash-linear-attention-0.1/fla/ops/retention/fused_recurrent.py +42 -0
  174. flash-linear-attention-0.1/fla/ops/retention/naive.py +15 -0
  175. flash-linear-attention-0.1/fla/ops/retention/parallel.py +64 -0
  176. flash-linear-attention-0.1/fla/ops/rwkv4/__init__.py +7 -0
  177. flash-linear-attention-0.1/fla/ops/rwkv4/fused_recurrent.py +474 -0
  178. flash-linear-attention-0.1/fla/ops/rwkv6/__init__.py +9 -0
  179. flash-linear-attention-0.1/fla/ops/rwkv6/chunk.py +1464 -0
  180. flash-linear-attention-0.1/fla/ops/rwkv6/chunk_naive.py +43 -0
  181. flash-linear-attention-0.1/fla/ops/rwkv6/fused_recurrent.py +708 -0
  182. flash-linear-attention-0.1/fla/ops/rwkv6/recurrent_naive.py +103 -0
  183. flash-linear-attention-0.1/fla/ops/rwkv7/__init__.py +9 -0
  184. flash-linear-attention-0.1/fla/ops/rwkv7/chunk.py +64 -0
  185. flash-linear-attention-0.1/fla/ops/rwkv7/fused_recurrent.py +62 -0
  186. flash-linear-attention-0.1/fla/ops/simple_gla/__init__.py +11 -0
  187. flash-linear-attention-0.1/fla/ops/simple_gla/chunk.py +301 -0
  188. flash-linear-attention-0.1/fla/ops/simple_gla/fused_recurrent.py +109 -0
  189. flash-linear-attention-0.1/fla/ops/simple_gla/naive.py +54 -0
  190. flash-linear-attention-0.1/fla/ops/simple_gla/parallel.py +716 -0
  191. flash-linear-attention-0.1/fla/ops/titans/__init__.py +7 -0
  192. flash-linear-attention-0.1/fla/ops/titans/log_impl.py +153 -0
  193. flash-linear-attention-0.1/fla/ops/titans/naive.py +375 -0
  194. flash-linear-attention-0.1/fla/ops/ttt/__init__.py +9 -0
  195. flash-linear-attention-0.1/fla/ops/ttt/chunk.py +1554 -0
  196. flash-linear-attention-0.1/fla/ops/ttt/fused_chunk.py +896 -0
  197. flash-linear-attention-0.1/fla/ops/ttt/naive.py +126 -0
  198. flash-linear-attention-0.1/fla/ops/utils/__init__.py +45 -0
  199. flash-linear-attention-0.1/fla/ops/utils/asm.py +17 -0
  200. flash-linear-attention-0.1/fla/ops/utils/cumsum.py +398 -0
  201. flash-linear-attention-0.1/fla/ops/utils/exp.py +18 -0
  202. flash-linear-attention-0.1/fla/ops/utils/logcumsumexp.py +52 -0
  203. flash-linear-attention-0.1/fla/ops/utils/logsumexp.py +78 -0
  204. flash-linear-attention-0.1/fla/ops/utils/matmul.py +245 -0
  205. flash-linear-attention-0.1/fla/ops/utils/pooling.py +216 -0
  206. flash-linear-attention-0.1/fla/ops/utils/softmax.py +109 -0
  207. flash-linear-attention-0.1/fla/utils.py +207 -0
  208. flash-linear-attention-0.1/flash_linear_attention.egg-info/PKG-INFO +508 -0
  209. flash-linear-attention-0.1/flash_linear_attention.egg-info/SOURCES.txt +213 -0
  210. flash-linear-attention-0.1/flash_linear_attention.egg-info/dependency_links.txt +1 -0
  211. flash-linear-attention-0.1/flash_linear_attention.egg-info/requires.txt +9 -0
  212. flash-linear-attention-0.1/flash_linear_attention.egg-info/top_level.txt +1 -0
  213. flash-linear-attention-0.1/pyproject.toml +40 -0
  214. flash-linear-attention-0.1/setup.cfg +4 -0
  215. flash-linear-attention-0.1/setup.py +49 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-2025 Songlin Yang
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,508 @@
1
+ Metadata-Version: 2.1
2
+ Name: flash-linear-attention
3
+ Version: 0.1
4
+ Summary: Fast Triton-based implementations of causal linear attention
5
+ Home-page: https://github.com/fla-org/flash-linear-attention
6
+ Author: Songlin Yang, Yu Zhang
7
+ Author-email: yangsl66@mit.edu, yzhang.cs@outlook.com
8
+ License: MIT
9
+ Platform: UNKNOWN
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ Provides-Extra: conv1d
17
+ License-File: LICENSE
18
+
19
+ <div align="center">
20
+
21
+ # :boom: Flash Linear Attention
22
+
23
+ [![hf_model](https://img.shields.io/badge/-Models-gray.svg?logo=huggingface&style=flat-square)](https://huggingface.co/fla-hub) [![Discord](https://img.shields.io/badge/Discord-%235865F2.svg?&logo=discord&logoColor=white&style=flat-square)](https://discord.gg/vDaJTmKNcS)
24
+
25
+ </div>
26
+
27
+ This repo aims at providing a collection of efficient Triton-based implementations for state-of-the-art linear attention models. **Any pull requests are welcome!**
28
+
29
+ <div align="center">
30
+ <img width="400" alt="image" src="https://github.com/fla-org/flash-linear-attention/assets/18402347/02ff2e26-1495-4088-b701-e72cd65ac6cf">
31
+ </div>
32
+
33
+ * [News](#news)
34
+ * [Models](#models)
35
+ * [Installation](#installation)
36
+ * [Usage](#usage)
37
+ * [Token Mixing](#token-mixing)
38
+ * [Fused Modules](#fused-modules)
39
+ * [Generation](#generation)
40
+ * [Hybrid Models](#hybrid-models)
41
+ * [Training](#training)
42
+ * [Evaluation](#evaluation)
43
+ * [Benchmarks](#benchmarks)
44
+ * [Citation](#citation)
45
+ * [Star History](#star-history)
46
+
47
+ ## News
48
+
49
+ - **$\texttt{[2025-03]}$:** We have changed the default `initializer_range` to the magic :whale: 0.006, leading to great improvements across all models.
50
+ - **$\texttt{[2025-02]}$:** :whale: Add NSA implementations to `fla`. See kernels [here](fla/ops/nsa).
51
+ - **$\texttt{[2025-01]}$:** :fire: We are migrating to `torchtitan`-based training framework. Check out the [flame](https://github.com/fla-org/flame) repo for more details.
52
+ - **$\texttt{[2025-01]}$:** :tada: Add RWKV7 implementations (both kernels and models) to `fla`.
53
+ - **$\texttt{[2024-12]}$:** Integrated `flash-bidirectional-attention` to `fla-org` ([repo](https://github.com/fla-org/flash-bidirectional-linear-attention))
54
+ - **$\texttt{[2024-12]}$:** :tada: Add Gated DeltaNet implementation to `fla` ([paper](https://arxiv.org/abs/2412.06464)).
55
+ - **$\texttt{[2024-12]}$:** :rocket: `fla` now officially supports kernels with variable-length inputs.
56
+ - **$\texttt{[2024-11]}$:** The inputs are now switched from head-first to seq-first format.
57
+ - **$\texttt{[2024-11]}$:** :boom: `fla` now provides a flexible way for training hybrid models.
58
+ - **$\texttt{[2024-10]}$:** :fire: Announcing `flame`, a minimal and scalable framework for training `fla` models. Check out the details [here](training/README.md).
59
+ - **$\texttt{[2024-09]}$:** `fla` now includes a fused linear and cross-entropy layer, significantly reducing memory usage during training.
60
+ - **$\texttt{[2024-09]}$:** :tada: Add GSA implementation to `fla` ([paper](https://arxiv.org/abs/2409.07146)).
61
+ - **$\texttt{[2024-05]}$:** :tada: Add DeltaNet implementation to `fla` ([paper](https://arxiv.org/abs/2102.11174)).
62
+ - **$\texttt{[2024-05]}$:** :boom: `fla` v0.1: a variety of subquadratic kernels/layers/models integrated (RetNet/GLA/Mamba/HGRN/HGRN2/RWKV6, etc., see [Models](#models)).
63
+ - **$\texttt{[2023-12]}$:** :boom: Launched `fla`, offering a collection of implementations for state-of-the-art linear attention models.
64
+
65
+ ## Models
66
+
67
+ Roughly sorted according to the timeline supported in `fla`. The recommended training mode is `chunk` when available.
68
+
69
+ | Year | Venue | Model | Title | Paper | Code | `fla` impl |
70
+ | :--- | :------ | :------------- | :-------------------------------------------------------------------------------------------------------- | :------------------------------------------------: | :---------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------: |
71
+ | 2023 | | RetNet | Retentive network: a successor to transformer for large language models | [link](https://arxiv.org/abs/2307.08621) | [official](https://github.com/microsoft/torchscale/tree/main) | [code](https://github.com/fla-org/flash-linear-attention/blob/main/fla/layers/multiscale_retention.py) |
72
+ | 2024 | ICML | GLA | Gated Linear Attention Transformers with Hardware-Efficient Training | [link](https://arxiv.org/abs/2312.06635) | [official](https://github.com/berlino/gated_linear_attention) | [code](https://github.com/fla-org/flash-linear-attention/blob/main/fla/layers/gla.py) |
73
+ | 2024 | ICML | Based | Simple linear attention language models balance the recall-throughput tradeoff | [link](https://arxiv.org/abs/2402.18668) | [official](https://github.com/HazyResearch/based) | [code](https://github.com/fla-org/flash-linear-attention/blob/main/fla/layers/based.py) |
74
+ | 2024 | ACL | Rebased | Linear Transformers with Learnable Kernel Functions are Better In-Context Models | [link](https://arxiv.org/abs/2402.10644) | [official](https://github.com/corl-team/rebased/) | [code](https://github.com/fla-org/flash-linear-attention/blob/main/fla/layers/rebased.py) |
75
+ | 2024 | NeurIPS | DeltaNet | Parallelizing Linear Transformers with Delta Rule over Sequence Length | [link](https://arxiv.org/abs/2406.06484) | [official](https://github.com/fla-org/flash-linear-attention/blob/main/fla/layers/delta_net.py) | [code](https://github.com/fla-org/flash-linear-attention/blob/main/fla/layers/delta_net.py) |
76
+ | 2022 | ACL | ABC | Attention with Bounded-memory Control | [link](https://arxiv.org/abs/2110.02488) | | [code](https://github.com/fla-org/flash-linear-attention/blob/main/fla/layers/abc.py) |
77
+ | 2023 | NeurIPS | HGRN | Hierarchically Gated Recurrent Neural Network for Sequence Modeling | [link](https://openreview.net/forum?id=P1TCHxJwLB) | [official](https://github.com/OpenNLPLab/HGRN) | [code](https://github.com/fla-org/flash-linear-attention/blob/main/fla/layers/hgrn.py) |
78
+ | 2024 | COLM | HGRN2 | HGRN2: Gated Linear RNNs with State Expansion | [link](https://arxiv.org/abs/2404.07904) | [official](https://github.com/OpenNLPLab/HGRN2) | [code](https://github.com/fla-org/flash-linear-attention/blob/main/fla/layers/hgrn2.py) |
79
+ | 2024 | COLM | RWKV6 | Eagle and Finch: RWKV with Matrix-Valued States and Dynamic Recurrence | [link](https://arxiv.org/abs/2404.05892) | [official](https://github.com/RWKV/RWKV-LM) | [code](https://github.com/fla-org/flash-linear-attention/blob/main/fla/layers/rwkv6.py) |
80
+ | 2024 | | LightNet | You Only Scan Once: Efficient Multi-dimension Sequential Modeling with LightNet | [link](https://arxiv.org/abs/2405.21022) | [official](https://github.com/OpenNLPLab/LightNet) | [code](https://github.com/fla-org/flash-linear-attention/blob/main/fla/layers/lightnet.py) |
81
+ | 2025 | ICLR | Samba | Samba: Simple Hybrid State Space Models for Efficient Unlimited Context Language Modeling | [link](https://arxiv.org/abs/2406.07522) | [official](https://github.com/microsoft/Samba) | [code](https://github.com/fla-org/flash-linear-attention/blob/main/fla/models/samba) |
82
+ | 2024 | ICML | Mamba2 | Transformers are SSMs: Generalized Models and Efficient Algorithms Through Structured State Space Duality | [link](https://arxiv.org/abs/2405.21060) | [official](https://github.com/state-spaces/mamba) | [code](https://github.com/fla-org/flash-linear-attention/blob/main/fla/models/mamba2) |
83
+ | 2024 | NeurIPS | GSA | Gated Slot Attention for Efficient Linear-Time Sequence Modeling | [link](https://arxiv.org/abs/2409.07146) | [official](https://github.com/fla-org/flash-linear-attention/tree/main/fla/models/gsa) | [code](https://github.com/fla-org/flash-linear-attention/tree/main/fla/models/gsa) |
84
+ | 2025 | ICLR | Gated DeltaNet | Gated Delta Networks: Improving Mamba2 with Delta Rule | [link](https://arxiv.org/abs/2412.06464) | [official](https://github.com/NVlabs/GatedDeltaNet) | [code](https://github.com/fla-org/flash-linear-attention/tree/main/fla/ops/gated_delta_rule) |
85
+ | 2025 | | RWKV7 | | | [official](https://github.com/BlinkDL/RWKV-LM/tree/main/RWKV-v7) | [code](https://github.com/fla-org/flash-linear-attention/tree/main/fla/ops/rwkv7) |
86
+ | 2025 | | NSA | Native Sparse Attention: Hardware-Aligned and Natively Trainable Sparse Attention | [link](https://arxiv.org/abs/2502.11089) | | [code](https://github.com/fla-org/flash-linear-attention/tree/main/fla/ops/nsa) |
87
+
88
+ ## Installation
89
+
90
+ The following requirements should be satisfied
91
+ - [PyTorch](https://pytorch.org/) >= 2.5
92
+ - [Triton](https://github.com/openai/triton) >=3.0 (or nightly version, see [FAQs](FAQs.md))
93
+ - [einops](https://einops.rocks/)
94
+ - [transformers](https://github.com/huggingface/transformers) >=4.45.0
95
+ - [datasets](https://github.com/huggingface/datasets) >=3.3.0
96
+ - [causal-conv1d](https://github.com/Dao-AILab/causal-conv1d) >=1.4.0
97
+
98
+ You can install `fla` with pip:
99
+ ```sh
100
+ pip install flash-linear-attention
101
+ ```
102
+ As `fla` is actively developed now, for the latest features and updates, an alternative way is to install the package from source
103
+ ```sh
104
+ # uninstall `fla` first to ensure a successful upgrade
105
+ pip uninstall flash-linear-attention && pip install -U git+https://github.com/fla-org/flash-linear-attention
106
+ ```
107
+ or manage `fla` with submodules
108
+ ```sh
109
+ git submodule add https://github.com/fla-org/flash-linear-attention.git 3rdparty/flash-linear-attention
110
+ ln -s 3rdparty/flash-linear-attention/fla fla
111
+ ```
112
+
113
+ ## Usage
114
+
115
+ ### Token Mixing
116
+
117
+ We provide ``token mixing'' linear attention layers in `fla.layers` for you to use.
118
+ You can replace the standard multihead attention layer in your model with other linear attention layers.
119
+ Example usage is as follows:
120
+ ```py
121
+ >>> import torch
122
+ >>> from fla.layers import MultiScaleRetention
123
+ >>> batch_size, num_heads, seq_len, hidden_size = 32, 4, 2048, 1024
124
+ >>> device, dtype = 'cuda:0', torch.bfloat16
125
+ >>> retnet = MultiScaleRetention(hidden_size=hidden_size, num_heads=num_heads).to(device=device, dtype=dtype)
126
+ >>> retnet
127
+ MultiScaleRetention(
128
+ (q_proj): Linear(in_features=1024, out_features=1024, bias=False)
129
+ (k_proj): Linear(in_features=1024, out_features=1024, bias=False)
130
+ (v_proj): Linear(in_features=1024, out_features=2048, bias=False)
131
+ (g_proj): Linear(in_features=1024, out_features=2048, bias=False)
132
+ (o_proj): Linear(in_features=2048, out_features=1024, bias=False)
133
+ (g_norm_swish_gate): FusedRMSNormSwishGate(512, eps=1e-05)
134
+ (rotary): RotaryEmbedding()
135
+ )
136
+ >>> x = torch.randn(batch_size, seq_len, hidden_size).to(device=device, dtype=dtype)
137
+ >>> y, *_ = retnet(x)
138
+ >>> y.shape
139
+ torch.Size([32, 2048, 1024])
140
+ ```
141
+
142
+ We provide the implementations of models that are compatible with 🤗 Transformers library.
143
+ Here's an example of how to initialize a GLA model from the default configs in `fla`:
144
+
145
+ ```py
146
+ >>> from fla.models import GLAConfig
147
+ >>> from transformers import AutoModelForCausalLM
148
+ >>> config = GLAConfig()
149
+ >>> config
150
+ GLAConfig {
151
+ "attn": null,
152
+ "attn_mode": "chunk",
153
+ "bos_token_id": 1,
154
+ "clamp_min": null,
155
+ "conv_size": 4,
156
+ "elementwise_affine": true,
157
+ "eos_token_id": 2,
158
+ "expand_k": 0.5,
159
+ "expand_v": 1,
160
+ "feature_map": null,
161
+ "fuse_cross_entropy": true,
162
+ "fuse_norm": true,
163
+ "fuse_swiglu": true,
164
+ "hidden_act": "swish",
165
+ "hidden_ratio": 4,
166
+ "hidden_size": 2048,
167
+ "initializer_range": 0.02,
168
+ "intermediate_size": null,
169
+ "max_position_embeddings": 2048,
170
+ "model_type": "gla",
171
+ "norm_eps": 1e-06,
172
+ "num_heads": 4,
173
+ "num_hidden_layers": 24,
174
+ "num_kv_heads": null,
175
+ "tie_word_embeddings": false,
176
+ "transformers_version": "4.48.2",
177
+ "use_cache": true,
178
+ "use_gk": true,
179
+ "use_gv": false,
180
+ "use_output_gate": true,
181
+ "use_short_conv": false,
182
+ "vocab_size": 32000
183
+ }
184
+
185
+ >>> AutoModelForCausalLM.from_config(config)
186
+ GLAForCausalLM(
187
+ (model): GLAModel(
188
+ (embeddings): Embedding(32000, 2048)
189
+ (layers): ModuleList(
190
+ (0-23): 24 x GLABlock(
191
+ (attn_norm): RMSNorm(2048, eps=1e-06)
192
+ (attn): GatedLinearAttention(
193
+ (q_proj): Linear(in_features=2048, out_features=1024, bias=False)
194
+ (k_proj): Linear(in_features=2048, out_features=1024, bias=False)
195
+ (v_proj): Linear(in_features=2048, out_features=2048, bias=False)
196
+ (g_proj): Linear(in_features=2048, out_features=2048, bias=False)
197
+ (gk_proj): Sequential(
198
+ (0): Linear(in_features=2048, out_features=16, bias=False)
199
+ (1): Linear(in_features=16, out_features=1024, bias=True)
200
+ )
201
+ (o_proj): Linear(in_features=2048, out_features=2048, bias=False)
202
+ (g_norm_swish_gate): FusedRMSNormSwishGate(512, eps=1e-06)
203
+ )
204
+ (mlp_norm): RMSNorm(2048, eps=1e-06)
205
+ (mlp): GatedMLP(
206
+ (gate_proj): Linear(in_features=2048, out_features=5632, bias=False)
207
+ (up_proj): Linear(in_features=2048, out_features=5632, bias=False)
208
+ (down_proj): Linear(in_features=5632, out_features=2048, bias=False)
209
+ )
210
+ )
211
+ )
212
+ (norm): RMSNorm(2048, eps=1e-06)
213
+ )
214
+ (lm_head): Linear(in_features=2048, out_features=32000, bias=False)
215
+ )
216
+ ```
217
+
218
+ ### Fused Modules
219
+
220
+ We offer a collection of fused modules in `fla.modules` to facilitate faster training:
221
+
222
+ * [`Rotary Embedding`](fla/modules/rotary.py): rotary positional embeddings as adopted by the Llama architecture, a.k.a., Transformer++.
223
+ * [`Norm Layers`](fla/modules/layernorm.py):
224
+ * `RMSNorm`, `LayerNorm` and `GroupNorm`
225
+ * `RMSNormLinear`, `LayerNormLinear` and `GroupNormLinear` to reduce memory usage of intermediate tensors for improved memory efficiency.
226
+ * [`Norm Layers with Gating`](fla/modules/fused_norm_gate.py): combine norm layers with element-wise gating, as used by RetNet/GLA.
227
+ * [`Cross Entropy`](fla/modules/fused_cross_entropy.py): faster Triton implementation of cross entropy loss.
228
+ * [`Linear Cross Entropy`](fla/modules/fused_linear_cross_entropy.py): fused linear layer and cross entropy loss to avoid the materialization of large logits tensors. Also refer to implementations by [mgmalek](https://github.com/mgmalek/efficient_cross_entropy) and [Liger-Kernel](https://github.com/linkedin/Liger-Kernel/blob/main/src/liger_kernel/ops/fused_linear_cross_entropy.py).
229
+ * [`Linear KL Divergence`](fla/modules/fused_kl_div.py): fused linear layer and KL divergence loss in a similar vein as CE loss.
230
+
231
+ ### Generation
232
+
233
+ Upon successfully pretraining a model, it becomes accessible for generating text using the 🤗 text generation APIs.
234
+ In the following, we give a generation example:
235
+ ```py
236
+ >>> import fla
237
+ >>> from transformers import AutoModelForCausalLM, AutoTokenizer
238
+ >>> name = 'fla-hub/gla-1.3B-100B'
239
+ >>> tokenizer = AutoTokenizer.from_pretrained(name)
240
+ >>> model = AutoModelForCausalLM.from_pretrained(name).cuda()
241
+ >>> input_prompt = "Power goes with permanence. Impermanence is impotence. And rotation is castration."
242
+ >>> input_ids = tokenizer(input_prompt, return_tensors="pt").input_ids.cuda()
243
+ >>> outputs = model.generate(input_ids, max_length=64)
244
+ >>> tokenizer.batch_decode(outputs, skip_special_tokens=True)[0]
245
+ ```
246
+
247
+ We also provide a simple script [here](benchmarks/benchmark_generation.py) for benchmarking the generation speed.
248
+ Simply run it by:
249
+ ```sh
250
+ $ python -m benchmarks.benchmark_generation \
251
+ --path 'fla-hub/gla-1.3B-100B' \
252
+ --repetition_penalty 2. \
253
+ --prompt="Hello everyone, I'm Songlin Yang"
254
+
255
+ Prompt:
256
+ Hello everyone, I'm Songlin Yang
257
+ Generated:
258
+ Hello everyone, I'm Songlin Yang.
259
+ I am a 20 year old girl from China who is currently studying in the United States of America for my Master degree and also working as an English teacher at school here on campus since last summer (1st semester). My main goal to be able do well with this course so that we can have
260
+
261
+ Prompt length: 10, generation length: 64
262
+ Total prompt processing + decoding time: 4593ms
263
+ ```
264
+
265
+ All of the pretrained models currently available can be found in [`fla-hub`](https://huggingface.co/fla-hub).
266
+ ```py
267
+ >>> from huggingface_hub import list_models
268
+ >>> for model in list_models(author='fla-hub'): print(model.id)
269
+ ```
270
+
271
+ ### Hybrid Models
272
+
273
+ `fla` provides a flexible method to incorporate standard attention layers into existing linear attention models.
274
+ This is easily achieved by specifying the `attn` argument in the model configuration.
275
+
276
+ For example, to create a 2-layer Samba model with interleaved Mamba and local attention layers, using a sliding window size of 2048:
277
+
278
+ ```py
279
+ >>> from fla.models import SambaConfig
280
+ >>> from transformers import AutoModelForCausalLM
281
+ >>> config = SambaConfig(num_hidden_layers=2)
282
+ >>> config.attn = {
283
+ 'layers': [1],
284
+ 'num_heads': 18,
285
+ 'num_kv_heads': 18,
286
+ 'window_size': 2048
287
+ }
288
+ >>> config
289
+ SambaConfig {
290
+ "attn": {
291
+ "layers": [
292
+ 1
293
+ ],
294
+ "num_heads": 18,
295
+ "num_kv_heads": 18,
296
+ "window_size": 2048
297
+ },
298
+ "bos_token_id": 1,
299
+ "conv_kernel": 4,
300
+ "eos_token_id": 2,
301
+ "expand": 2,
302
+ "fuse_cross_entropy": true,
303
+ "fuse_norm": true,
304
+ "hidden_act": "silu",
305
+ "hidden_ratio": 4,
306
+ "hidden_size": 2304,
307
+ "initializer_range": 0.02,
308
+ "intermediate_size": 4608,
309
+ "max_position_embeddings": 2048,
310
+ "model_type": "samba",
311
+ "norm_eps": 1e-05,
312
+ "num_hidden_layers": 2,
313
+ "pad_token_id": 0,
314
+ "rescale_prenorm_residual": false,
315
+ "residual_in_fp32": false,
316
+ "state_size": 16,
317
+ "tie_word_embeddings": false,
318
+ "time_step_floor": 0.0001,
319
+ "time_step_init_scheme": "random",
320
+ "time_step_max": 0.1,
321
+ "time_step_min": 0.001,
322
+ "time_step_rank": 144,
323
+ "time_step_scale": 1.0,
324
+ "transformers_version": "4.45.0",
325
+ "use_bias": false,
326
+ "use_cache": true,
327
+ "use_conv_bias": true,
328
+ "vocab_size": 32000
329
+ }
330
+
331
+ >>> AutoModelForCausalLM.from_config(config)
332
+ SambaForCausalLM(
333
+ (backbone): SambaModel(
334
+ (embeddings): Embedding(32000, 2304)
335
+ (layers): ModuleList(
336
+ (0): SambaBlock(
337
+ (mixer_norm): RMSNorm(2304, eps=1e-05)
338
+ (mixer): MambaMixer(
339
+ (conv1d): Conv1d(4608, 4608, kernel_size=(4,), stride=(1,), padding=(3,), groups=4608)
340
+ (act): SiLU()
341
+ (in_proj): Linear(in_features=2304, out_features=9216, bias=False)
342
+ (x_proj): Linear(in_features=4608, out_features=176, bias=False)
343
+ (dt_proj): Linear(in_features=144, out_features=4608, bias=True)
344
+ (out_proj): Linear(in_features=4608, out_features=2304, bias=False)
345
+ )
346
+ (mlp_norm): RMSNorm(2304, eps=1e-05)
347
+ (mlp): SambaMLP(
348
+ (gate_proj): Linear(in_features=2304, out_features=12288, bias=False)
349
+ (down_proj): Linear(in_features=6144, out_features=2304, bias=False)
350
+ (act_fn): SiLU()
351
+ )
352
+ )
353
+ (1): SambaBlock(
354
+ (mixer_norm): RMSNorm(2304, eps=1e-05)
355
+ (mixer): Attention(
356
+ (q_proj): Linear(in_features=2304, out_features=2304, bias=False)
357
+ (k_proj): Linear(in_features=2304, out_features=2304, bias=False)
358
+ (v_proj): Linear(in_features=2304, out_features=2304, bias=False)
359
+ (o_proj): Linear(in_features=2304, out_features=2304, bias=False)
360
+ (rotary): RotaryEmbedding()
361
+ )
362
+ (mlp_norm): RMSNorm(2304, eps=1e-05)
363
+ (mlp): SambaMLP(
364
+ (gate_proj): Linear(in_features=2304, out_features=12288, bias=False)
365
+ (down_proj): Linear(in_features=6144, out_features=2304, bias=False)
366
+ (act_fn): SiLU()
367
+ )
368
+ )
369
+ )
370
+ (norm_f): RMSNorm(2304, eps=1e-05)
371
+ )
372
+ (lm_head): Linear(in_features=2304, out_features=32000, bias=False)
373
+ )
374
+ ```
375
+
376
+ During inference, you **DO NOT** need to revise anything for generation!
377
+ The model will produce output as-is, without any need for additional configurations or modifications.
378
+
379
+ ## Training
380
+
381
+ We provide a minimal framework called [:fire: `flame`](https://github.com/fla-org/flame) built on top of `torchtitan`, for efficient training of `fla` models.
382
+
383
+ Checkout [the GLA example](https://github.com/fla-org/flash-linear-attention/blob/main/examples/training.md) for more details.
384
+
385
+ ## Evaluation
386
+
387
+ The [lm-evaluation-harness](https://github.com/EleutherAI/lm-evaluation-harness) library allows you to easily perform (zero-shot) model evaluations.
388
+ Follow the steps below to use this library:
389
+
390
+ 1. Install `lm_eval` following [their instructions](https://github.com/EleutherAI/lm-evaluation-harness/blob/main/README.md).
391
+
392
+ 2. Run evaluation with:
393
+ ```sh
394
+ $ PATH='fla-hub/gla-1.3B-100B'
395
+ $ python -m evals.harness --model hf \
396
+ --model_args pretrained=$PATH,dtype=bfloat16 \
397
+ --tasks wikitext,lambada_openai,piqa,hellaswag,winogrande,arc_easy,arc_challenge,boolq,sciq,copa,openbookqa \
398
+ --batch_size 64 \
399
+ --num_fewshot 0 \
400
+ --device cuda \
401
+ --show_config
402
+ ```
403
+
404
+ We've made `fla` compatible with hf-style evaluations, you can call [evals.harness](evals/harness.py) to finish the evaluations.
405
+ Running the command above will provide the task results reported in the GLA paper.
406
+
407
+ 3. Multi-GPU Evaluation with Hugging Face accelerate 🚀
408
+
409
+ To perform data-parallel evaluation (where each GPU loads a separate full copy of the model), we leverage the accelerate launcher as follows:
410
+ ```sh
411
+ $ PATH='fla-hub/gla-1.3B-100B'
412
+ $ accelerate launch -m evals.harness --model hf \
413
+ --model_args pretrained=$PATH,dtype=bfloat16 \
414
+ --tasks wikitext,lambada_openai,piqa,hellaswag,winogrande,arc_easy,arc_challenge,boolq,sciq,copa,openbookqa \
415
+ --batch_size 64 \
416
+ --num_fewshot 0 \
417
+ --device cuda \
418
+ --show_config
419
+ ```
420
+
421
+ If a GPU can't load a full copy of the model, please refer to [this link](https://github.com/EleutherAI/lm-evaluation-harness?tab=readme-ov-file#multi-gpu-evaluation-with-hugging-face-accelerate) for FSDP settings.
422
+
423
+ > [!Tip]
424
+ > If you are using `lm-evaluation-harness` as an external library and can't find (almost) any tasks available, before calling `lm_eval.evaluate()` or `lm_eval.simple_evaluate()`, simply run the following to load the library's stock tasks!
425
+ ```py
426
+ >>> from lm_eval.tasks import TaskManager; TaskManager().initialize_tasks()
427
+ ```
428
+
429
+ ## Benchmarks
430
+
431
+ We compared our Triton-based RetNet implementation with CUDA-based FlashAttention2, using a batch size of 8, 32 heads, and a head dimension of 128, across different sequence lengths.
432
+ These tests were conducted on a single H100 80GB GPU, as illustrated in the following graph
433
+ ```py
434
+ # you might have to first install `fla` to enable its import via `pip install -e .`
435
+ $ python benchmark_retention.py
436
+ Performance:
437
+ T chunk_fwd parallel_fwd flash_fwd chunk_fwdbwd parallel_fwdbwd flash_fwdbwd
438
+ 0 128.0 0.264032 0.243536 0.083488 1.301856 1.166784 0.320704
439
+ 1 256.0 0.273472 0.252848 0.094304 1.345872 1.300608 0.807936
440
+ 2 512.0 0.303600 0.278896 0.098112 1.503168 1.433184 0.857216
441
+ 3 1024.0 0.357248 0.367360 0.156528 1.773552 2.303424 1.160864
442
+ 4 2048.0 0.454624 0.605616 0.340928 2.283728 4.483360 1.955936
443
+ 5 4096.0 0.638960 1.378016 1.004992 3.374720 12.271215 4.813776
444
+ 6 8192.0 1.012352 4.201344 3.625008 5.581808 40.833618 15.023697
445
+ 7 16384.0 1.748512 14.489664 13.710080 10.191552 153.093765 54.336864
446
+ ```
447
+
448
+ <div align="center">
449
+ <img width="500" alt="image" src="https://github.com/user-attachments/assets/c2607015-63af-43d1-90d1-ad5fe1670a03">
450
+ </div>
451
+
452
+
453
+ ## Citation
454
+ If you find this repository helpful, please cite our work:
455
+ ```bib
456
+ @software{yang2024fla,
457
+ title = {FLA: A Triton-Based Library for Hardware-Efficient Implementations of Linear Attention Mechanism},
458
+ author = {Yang, Songlin and Zhang, Yu},
459
+ url = {https://github.com/fla-org/flash-linear-attention},
460
+ month = jan,
461
+ year = {2024}
462
+ }
463
+
464
+ @inproceedings{yang2024gdn,
465
+ title = {Gated Delta Networks: Improving Mamba2 with Delta Rule},
466
+ author = {Songlin Yang and Jan Kautz and Ali Hatamizadeh},
467
+ booktitle = {Proceedings of ICLR},
468
+ year = {2025}
469
+ }
470
+
471
+ @inproceedings{yang2024deltanet,
472
+ title = {Parallelizing Linear Transformers with the Delta Rule over Sequence Length},
473
+ author = {Yang, Songlin and Wang, Bailin and Zhang, Yu and Shen, Yikang and Kim, Yoon},
474
+ booktitle = {Proceedings of NeurIPS},
475
+ year = {2024}
476
+ }
477
+
478
+ @inproceedings{zhang2024gsa,
479
+ title = {Gated Slot Attention for Efficient Linear-Time Sequence Modeling},
480
+ author = {Zhang, Yu and Yang, Songlin and Zhu, Ruijie and Zhang, Yue and Cui, Leyang and Wang, Yiqiao and Wang, Bolun and Shi, Freda and Wang, Bailin and Bi, Wei and Zhou, Peng and Fu, Guohong},
481
+ booktitle = {Proceedings of NeurIPS},
482
+ year = {2024}
483
+ }
484
+
485
+ @inproceedings{qin2024hgrn2,
486
+ title = {Gated Slot Attention for Efficient Linear-Time Sequence Modeling},
487
+ author = {Qin, Zhen and Yang, Songlin and Sun, Weixuan and Shen, Xuyang and Li, Dong and Sun, Weigao and Zhong, Yiran},
488
+ booktitle = {Proceedings of COLM},
489
+ year = {2024}
490
+ }
491
+
492
+ @inproceedings{yang2024gla,
493
+ title = {Gated Linear Attention Transformers with Hardware-Efficient Training},
494
+ author = {Yang, Songlin and Wang, Bailin and Shen, Yikang and Panda, Rameswar and Kim, Yoon},
495
+ booktitle = {Proceedings of ICML},
496
+ year = {2024}
497
+ }
498
+ ```
499
+
500
+
501
+ ## Star History
502
+
503
+ [![Stargazers repo roster for @fla-org/flash-linear-attention](https://bytecrank.com/nastyox/reporoster/php/stargazersSVG.php?user=fla-org&repo=flash-linear-attention)](https://github.com/fla-org/flash-linear-attention/stargazers)
504
+
505
+
506
+ [![Star History Chart](https://api.star-history.com/svg?repos=fla-org/flash-linear-attention&type=Date)](https://star-history.com/#fla-org/flash-linear-attention&Date)
507
+
508
+