flash-linear-attention 0.2.0__tar.gz → 0.2.2__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 (274) hide show
  1. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/PKG-INFO +47 -17
  2. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/README.md +46 -16
  3. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/__init__.py +12 -1
  4. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/__init__.py +9 -0
  5. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/attn.py +2 -1
  6. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/bitattn.py +2 -1
  7. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/delta_net.py +2 -1
  8. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/forgetting_attn.py +1 -1
  9. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/gated_deltanet.py +26 -11
  10. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/gated_deltaproduct.py +13 -18
  11. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/gsa.py +4 -1
  12. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/hgrn.py +4 -5
  13. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/hgrn2.py +4 -8
  14. flash_linear_attention-0.2.2/fla/layers/mamba.py +317 -0
  15. flash_linear_attention-0.2.2/fla/layers/mamba2.py +586 -0
  16. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/multiscale_retention.py +2 -1
  17. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/nsa.py +2 -1
  18. flash_linear_attention-0.2.2/fla/layers/path_attn.py +209 -0
  19. flash_linear_attention-0.2.2/fla/layers/rodimus.py +377 -0
  20. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/rwkv6.py +70 -21
  21. flash_linear_attention-0.2.2/fla/layers/rwkv7.py +327 -0
  22. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/simple_gla.py +0 -1
  23. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/utils.py +32 -34
  24. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/__init__.py +4 -0
  25. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/abc/__init__.py +3 -3
  26. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/abc/configuration_abc.py +1 -1
  27. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/abc/modeling_abc.py +1 -1
  28. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/bitnet/__init__.py +3 -3
  29. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/bitnet/configuration_bitnet.py +1 -1
  30. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/bitnet/modeling_bitnet.py +1 -1
  31. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/delta_net/__init__.py +3 -3
  32. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/delta_net/configuration_delta_net.py +1 -1
  33. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/delta_net/modeling_delta_net.py +1 -1
  34. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/forgetting_transformer/__init__.py +3 -3
  35. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/forgetting_transformer/configuration_forgetting_transformer.py +1 -1
  36. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/forgetting_transformer/modeling_forgetting_transformer.py +1 -1
  37. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/gated_deltanet/__init__.py +3 -3
  38. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/gated_deltanet/configuration_gated_deltanet.py +3 -1
  39. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/gated_deltanet/modeling_gated_deltanet.py +36 -2
  40. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/gated_deltaproduct/__init__.py +3 -3
  41. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/gated_deltaproduct/configuration_gated_deltaproduct.py +1 -1
  42. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/gated_deltaproduct/modeling_gated_deltaproduct.py +1 -1
  43. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/gla/__init__.py +3 -3
  44. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/gla/configuration_gla.py +1 -1
  45. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/gla/modeling_gla.py +1 -1
  46. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/gsa/__init__.py +3 -3
  47. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/gsa/configuration_gsa.py +1 -1
  48. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/gsa/modeling_gsa.py +1 -1
  49. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/hgrn/__init__.py +3 -3
  50. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/hgrn/configuration_hgrn.py +1 -1
  51. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/hgrn/modeling_hgrn.py +2 -2
  52. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/hgrn2/__init__.py +3 -3
  53. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/hgrn2/configuration_hgrn2.py +1 -1
  54. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/hgrn2/modeling_hgrn2.py +2 -2
  55. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/lightnet/__init__.py +3 -3
  56. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/lightnet/configuration_lightnet.py +1 -1
  57. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/lightnet/modeling_lightnet.py +1 -1
  58. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/linear_attn/__init__.py +3 -3
  59. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/linear_attn/configuration_linear_attn.py +1 -1
  60. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/linear_attn/modeling_linear_attn.py +1 -1
  61. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/mamba/__init__.py +3 -3
  62. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/mamba/configuration_mamba.py +5 -5
  63. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/mamba/modeling_mamba.py +16 -294
  64. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/mamba2/__init__.py +3 -3
  65. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/mamba2/configuration_mamba2.py +6 -9
  66. flash_linear_attention-0.2.2/fla/models/mamba2/modeling_mamba2.py +562 -0
  67. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/nsa/__init__.py +3 -3
  68. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/nsa/configuration_nsa.py +1 -1
  69. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/nsa/modeling_nsa.py +1 -1
  70. flash_linear_attention-0.2.2/fla/models/path_attn/__init__.py +13 -0
  71. flash_linear_attention-0.2.2/fla/models/path_attn/configuration_path_attention.py +65 -0
  72. flash_linear_attention-0.2.2/fla/models/path_attn/modeling_path_attention.py +406 -0
  73. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/retnet/__init__.py +3 -3
  74. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/retnet/configuration_retnet.py +1 -1
  75. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/retnet/modeling_retnet.py +1 -1
  76. flash_linear_attention-0.2.2/fla/models/rodimus/__init__.py +15 -0
  77. flash_linear_attention-0.2.2/fla/models/rodimus/chat_format.py +586 -0
  78. flash_linear_attention-0.2.2/fla/models/rodimus/configuration_rodimus.py +102 -0
  79. flash_linear_attention-0.2.2/fla/models/rodimus/modeling_rodimus.py +597 -0
  80. flash_linear_attention-0.2.2/fla/models/rodimus/tokenization_rodimus_fast.py +226 -0
  81. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/rwkv6/__init__.py +3 -3
  82. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/rwkv6/configuration_rwkv6.py +1 -1
  83. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/rwkv6/modeling_rwkv6.py +18 -5
  84. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/rwkv7/__init__.py +3 -3
  85. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/rwkv7/configuration_rwkv7.py +1 -1
  86. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/rwkv7/modeling_rwkv7.py +59 -24
  87. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/samba/__init__.py +3 -3
  88. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/samba/modeling_samba.py +14 -5
  89. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/transformer/__init__.py +3 -3
  90. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/transformer/configuration_transformer.py +1 -1
  91. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/transformer/modeling_transformer.py +1 -1
  92. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/utils.py +2 -2
  93. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/modules/__init__.py +5 -1
  94. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/modules/activations.py +4 -4
  95. flash_linear_attention-0.2.2/fla/modules/convolution.py +859 -0
  96. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/modules/fused_norm_gate.py +499 -237
  97. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/modules/grpo.py +28 -15
  98. flash_linear_attention-0.2.2/fla/modules/l2norm.py +276 -0
  99. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/modules/layernorm.py +460 -228
  100. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/modules/rotary.py +6 -5
  101. flash_linear_attention-0.2.2/fla/modules/token_shift.py +255 -0
  102. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/__init__.py +2 -0
  103. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/abc/chunk.py +2 -1
  104. {flash_linear_attention-0.2.0/fla/ops/forgetting_attn → flash_linear_attention-0.2.2/fla/ops/attn}/decoding.py +37 -3
  105. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/attn/parallel.py +2 -2
  106. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/common/chunk_delta_h.py +32 -35
  107. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/common/chunk_h.py +1 -1
  108. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/common/chunk_h_parallel.py +1 -1
  109. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/common/chunk_o.py +1 -1
  110. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/common/chunk_scaled_dot_kkt.py +24 -4
  111. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/delta_rule/chunk.py +14 -40
  112. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/delta_rule/fused_recurrent.py +5 -30
  113. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/delta_rule/wy_fast.py +23 -20
  114. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/forgetting_attn/parallel.py +1 -1
  115. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/gated_delta_rule/chunk.py +30 -35
  116. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/gated_delta_rule/fused_recurrent.py +6 -28
  117. flash_linear_attention-0.2.2/fla/ops/gated_delta_rule/wy_fast.py +291 -0
  118. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/generalized_delta_rule/dplr/chunk.py +8 -10
  119. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/generalized_delta_rule/dplr/chunk_A_bwd.py +1 -1
  120. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/generalized_delta_rule/dplr/chunk_A_fwd.py +1 -1
  121. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/generalized_delta_rule/dplr/chunk_h_bwd.py +1 -1
  122. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/generalized_delta_rule/dplr/chunk_h_fwd.py +1 -1
  123. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/generalized_delta_rule/dplr/chunk_o_bwd.py +2 -2
  124. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/generalized_delta_rule/dplr/chunk_o_fwd.py +1 -1
  125. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/generalized_delta_rule/dplr/fused_recurrent.py +6 -31
  126. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/generalized_delta_rule/dplr/wy_fast_bwd.py +3 -3
  127. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/generalized_delta_rule/dplr/wy_fast_fwd.py +14 -9
  128. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/generalized_delta_rule/iplr/chunk.py +4 -10
  129. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/generalized_delta_rule/iplr/fused_recurrent.py +6 -28
  130. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/generalized_delta_rule/iplr/wy_fast.py +49 -44
  131. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/gla/chunk.py +7 -32
  132. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/gla/fused_chunk.py +0 -5
  133. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/gla/fused_recurrent.py +6 -36
  134. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/gsa/chunk.py +4 -7
  135. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/gsa/fused_recurrent.py +10 -43
  136. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/linear_attn/chunk.py +2 -3
  137. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/linear_attn/fused_chunk.py +2 -3
  138. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/linear_attn/fused_recurrent.py +2 -3
  139. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/nsa/compression.py +1 -1
  140. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/nsa/naive.py +0 -5
  141. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/nsa/parallel.py +4 -4
  142. flash_linear_attention-0.2.2/fla/ops/path_attn/__init__.py +7 -0
  143. flash_linear_attention-0.2.2/fla/ops/path_attn/cumprod_householder_bwd.py +117 -0
  144. flash_linear_attention-0.2.2/fla/ops/path_attn/cumprod_householder_fwd.py +167 -0
  145. flash_linear_attention-0.2.2/fla/ops/path_attn/intra_chunk_preprocess_bwd.py +140 -0
  146. flash_linear_attention-0.2.2/fla/ops/path_attn/intra_chunk_preprocess_bwd_prepare.py +199 -0
  147. flash_linear_attention-0.2.2/fla/ops/path_attn/intra_chunk_preprocess_fwd.py +175 -0
  148. flash_linear_attention-0.2.2/fla/ops/path_attn/parallel.py +212 -0
  149. flash_linear_attention-0.2.2/fla/ops/path_attn/parallel_path_bwd_inter_dkv.py +190 -0
  150. flash_linear_attention-0.2.2/fla/ops/path_attn/parallel_path_bwd_inter_dqh.py +165 -0
  151. flash_linear_attention-0.2.2/fla/ops/path_attn/parallel_path_bwd_intra.py +163 -0
  152. flash_linear_attention-0.2.2/fla/ops/path_attn/parallel_path_fwd.py +171 -0
  153. flash_linear_attention-0.2.2/fla/ops/path_attn/prepare_k_cache.py +76 -0
  154. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/retention/chunk.py +1 -1
  155. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/retention/fused_recurrent.py +0 -18
  156. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/retention/parallel.py +1 -1
  157. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/rwkv4/fused_recurrent.py +16 -20
  158. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/rwkv6/chunk.py +2 -6
  159. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/rwkv6/fused_recurrent.py +1 -5
  160. flash_linear_attention-0.2.2/fla/ops/rwkv7/__init__.py +10 -0
  161. flash_linear_attention-0.2.2/fla/ops/rwkv7/fused_addcmul.py +262 -0
  162. flash_linear_attention-0.2.2/fla/ops/rwkv7/fused_k_update.py +148 -0
  163. flash_linear_attention-0.2.2/fla/ops/rwkv7/fused_recurrent.py +315 -0
  164. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/simple_gla/chunk.py +1 -5
  165. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/simple_gla/fused_recurrent.py +5 -30
  166. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/simple_gla/parallel.py +3 -7
  167. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/ttt/chunk.py +2 -8
  168. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/ttt/fused_chunk.py +1 -5
  169. flash_linear_attention-0.2.2/fla/ops/utils/__init__.py +54 -0
  170. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/utils/cumsum.py +9 -1
  171. flash_linear_attention-0.2.0/fla/ops/common/utils.py → flash_linear_attention-0.2.2/fla/ops/utils/index.py +15 -4
  172. flash_linear_attention-0.2.2/fla/ops/utils/pack.py +208 -0
  173. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/utils/pooling.py +3 -7
  174. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/utils/solve_tril.py +15 -16
  175. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/utils.py +73 -0
  176. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/flash_linear_attention.egg-info/PKG-INFO +47 -17
  177. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/flash_linear_attention.egg-info/SOURCES.txt +29 -3
  178. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/pyproject.toml +4 -0
  179. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/tests/test_generation.py +7 -6
  180. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/tests/test_model.py +3 -4
  181. flash_linear_attention-0.2.0/fla/layers/rwkv7.py +0 -226
  182. flash_linear_attention-0.2.0/fla/models/mamba2/modeling_mamba2.py +0 -1093
  183. flash_linear_attention-0.2.0/fla/modules/convolution.py +0 -434
  184. flash_linear_attention-0.2.0/fla/modules/l2norm.py +0 -176
  185. flash_linear_attention-0.2.0/fla/ops/gated_delta_rule/wy_fast.py +0 -526
  186. flash_linear_attention-0.2.0/fla/ops/rwkv7/__init__.py +0 -9
  187. flash_linear_attention-0.2.0/fla/ops/rwkv7/fused_addcmul.py +0 -268
  188. flash_linear_attention-0.2.0/fla/ops/rwkv7/fused_recurrent.py +0 -63
  189. flash_linear_attention-0.2.0/fla/ops/utils/__init__.py +0 -45
  190. flash_linear_attention-0.2.0/fla/ops/utils/testing.py +0 -29
  191. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/LICENSE +0 -0
  192. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/abc.py +0 -0
  193. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/based.py +0 -0
  194. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/gla.py +0 -0
  195. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/lightnet.py +0 -0
  196. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/linear_attn.py +0 -0
  197. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/layers/rebased.py +0 -0
  198. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/models/samba/configuration_samba.py +0 -0
  199. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/modules/feature_map.py +0 -0
  200. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/modules/fused_bitlinear.py +0 -0
  201. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/modules/fused_cross_entropy.py +0 -0
  202. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/modules/fused_kl_div.py +0 -0
  203. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/modules/fused_linear_cross_entropy.py +0 -0
  204. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/modules/layernorm_gated.py +0 -0
  205. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/modules/mlp.py +0 -0
  206. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/modules/parallel.py +0 -0
  207. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/abc/__init__.py +0 -0
  208. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/abc/naive.py +0 -0
  209. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/attn/__init__.py +0 -0
  210. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/based/__init__.py +0 -0
  211. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/based/fused_chunk.py +0 -0
  212. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/based/naive.py +0 -0
  213. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/based/parallel.py +0 -0
  214. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/common/__init__.py +0 -0
  215. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/common/chunk_h_split.py +0 -0
  216. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/common/fused_recurrent.py +0 -0
  217. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/delta_rule/__init__.py +0 -0
  218. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/delta_rule/fused_chunk.py +0 -0
  219. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/delta_rule/naive.py +0 -0
  220. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/delta_rule/parallel.py +0 -0
  221. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/forgetting_attn/__init__.py +0 -0
  222. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/gated_delta_rule/__init__.py +0 -0
  223. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/generalized_delta_rule/__init__.py +0 -0
  224. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/generalized_delta_rule/dplr/__init__.py +0 -0
  225. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/generalized_delta_rule/dplr/naive.py +0 -0
  226. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/generalized_delta_rule/iplr/__init__.py +0 -0
  227. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/generalized_delta_rule/iplr/naive.py +0 -0
  228. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/gla/__init__.py +0 -0
  229. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/gla/naive.py +0 -0
  230. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/gsa/__init__.py +0 -0
  231. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/gsa/naive.py +0 -0
  232. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/hgrn/__init__.py +0 -0
  233. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/hgrn/chunk.py +0 -0
  234. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/hgrn/fused_recurrent.py +0 -0
  235. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/hgrn/naive.py +0 -0
  236. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/lightning_attn/__init__.py +0 -0
  237. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/lightning_attn/chunk.py +0 -0
  238. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/lightning_attn/fused_recurrent.py +0 -0
  239. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/linear_attn/__init__.py +0 -0
  240. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/linear_attn/naive.py +0 -0
  241. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/linear_attn/utils.py +0 -0
  242. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/nsa/__init__.py +0 -0
  243. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/nsa/utils.py +0 -0
  244. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/rebased/__init__.py +0 -0
  245. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/rebased/naive.py +0 -0
  246. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/rebased/parallel.py +0 -0
  247. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/retention/__init__.py +0 -0
  248. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/retention/fused_chunk.py +0 -0
  249. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/retention/naive.py +0 -0
  250. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/rwkv4/__init__.py +0 -0
  251. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/rwkv6/__init__.py +0 -0
  252. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/rwkv6/chunk_naive.py +0 -0
  253. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/rwkv6/recurrent_naive.py +0 -0
  254. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/rwkv7/channel_mixing.py +0 -0
  255. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/rwkv7/chunk.py +0 -0
  256. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/simple_gla/__init__.py +0 -0
  257. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/simple_gla/naive.py +0 -0
  258. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/titans/__init__.py +0 -0
  259. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/titans/log_impl.py +0 -0
  260. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/titans/naive.py +0 -0
  261. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/ttt/__init__.py +0 -0
  262. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/ttt/naive.py +0 -0
  263. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/utils/asm.py +0 -0
  264. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/utils/logcumsumexp.py +0 -0
  265. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/utils/logsumexp.py +0 -0
  266. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/utils/matmul.py +0 -0
  267. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/utils/op.py +0 -0
  268. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/fla/ops/utils/softmax.py +0 -0
  269. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/flash_linear_attention.egg-info/dependency_links.txt +0 -0
  270. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/flash_linear_attention.egg-info/requires.txt +0 -0
  271. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/flash_linear_attention.egg-info/top_level.txt +0 -0
  272. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/setup.cfg +0 -0
  273. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/setup.py +0 -0
  274. {flash_linear_attention-0.2.0 → flash_linear_attention-0.2.2}/tests/test_fused_chunk.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: flash-linear-attention
3
- Version: 0.2.0
3
+ Version: 0.2.2
4
4
  Summary: Fast Triton-based implementations of causal linear attention
5
5
  Home-page: https://github.com/fla-org/flash-linear-attention
6
6
  Author: Songlin Yang, Yu Zhang
@@ -79,9 +79,10 @@ This repo aims at providing a collection of efficient Triton-based implementatio
79
79
  * [Acknowledgments](#acknowledgments)
80
80
 
81
81
  ## News
82
+ - **$\texttt{[2025-05]}$:** 🎉 Add Rodimus* implementation to `fla` ([paper](https://arxiv.org/abs/2410.06577)).
82
83
  - **$\texttt{[2025-04]}$:** 🎉 Add DeltaProduct implementation to `fla` ([paper](https://arxiv.org/abs/2502.10297)).
83
84
  - **$\texttt{[2025-04]}$:** 🎉 Add FoX implementation to `fla` ([paper](https://arxiv.org/abs/2503.02130)).
84
- - **$\texttt{[2025-03]}$:** We have changed the default `initializer_range` to the magic 🐳 0.006, leading to great improvements across all models.
85
+ - **$\texttt{[2025-03]}$:** ~~We have changed the default `initializer_range` to the magic 🐳 0.006~~ The `initializer_range` was rolled back to the default value of 0.02. For actual training, we recommend trying both.
85
86
  - **$\texttt{[2025-02]}$:** 🐳 Add NSA implementations to `fla`. See kernels [here](fla/ops/nsa).
86
87
  - **$\texttt{[2025-01]}$:** 🔥 We are migrating to `torchtitan`-based training framework. Check out the [flame](https://github.com/fla-org/flame) repo for more details.
87
88
  - **$\texttt{[2025-01]}$:** 🎉 Add RWKV7 implementations (both kernels and models) to `fla`.
@@ -102,7 +103,7 @@ This repo aims at providing a collection of efficient Triton-based implementatio
102
103
  Roughly sorted according to the timeline supported in `fla`. The recommended training mode is `chunk` when available.
103
104
 
104
105
  | Year | Venue | Model | Paper | Code | `fla` impl |
105
- |:-----| :------ |:---------------|:----------------------------------------------------------------------------------------------------------------------------------------------| :---------------------------------------------------------------------------------------------: |:------------------------------------------------------------------------------------------------------:|
106
+ | :--- | :------ | :------------- | :-------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------: |
106
107
  | 2023 | | RetNet | [Retentive network: a successor to transformer for large language models](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) |
107
108
  | 2024 | ICML | GLA | [Gated Linear Attention Transformers with Hardware-Efficient Training](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) |
108
109
  | 2024 | ICML | Based | [Simple linear attention language models balance the recall-throughput tradeoff](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) |
@@ -120,11 +121,12 @@ Roughly sorted according to the timeline supported in `fla`. The recommended tra
120
121
  | 2025 | | RWKV7 | [RWKV-7 "Goose" with Expressive Dynamic State Evolution](https://arxiv.org/abs/2503.14456) | [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) |
121
122
  | 2025 | | NSA | [Native Sparse Attention: Hardware-Aligned and Natively Trainable Sparse Attention](https://arxiv.org/abs/2502.11089) | | [code](https://github.com/fla-org/flash-linear-attention/tree/main/fla/ops/nsa) |
122
123
  | 2025 | | FoX | [Forgetting Transformer: Softmax Attention with a Forget Gate](https://arxiv.org/abs/2503.02130) | [official](https://github.com/zhixuan-lin/forgetting-transformer) | [code](https://github.com/fla-org/flash-linear-attention/tree/main/fla/ops/forgetting_attn) |
123
- | 2025 | | DeltaProduct | [DeltaProduct: Improving State-Tracking in Linear RNNs via Householder Products](https://arxiv.org/abs/2502.10297) | | [code](https://github.com/fla-org/flash-linear-attention/tree/main/fla/layers/gated_deltaproduct.py) |
124
+ | 2025 | | DeltaProduct | [DeltaProduct: Improving State-Tracking in Linear RNNs via Householder Products](https://arxiv.org/abs/2502.10297) | | [code](https://github.com/fla-org/flash-linear-attention/tree/main/fla/layers/gated_deltaproduct.py) |
125
+ | 2025 | ICLR | Rodimus* | [Rodimus*: Breaking the Accuracy-Efficiency Trade-Off with Efficient Attentions](https://arxiv.org/abs/2410.06577) | [official](https://github.com/codefuse-ai/rodimus) | [code](https://github.com/fla-org/flash-linear-attention/blob/main/fla/layers/rodimus.py) |
124
126
 
125
127
  ## Installation
126
128
 
127
- [![nvidia-4090-ci](https://github.com/fla-org/flash-linear-attention/actions/workflows/nvidia-4090.yml/badge.svg?branch=main&event=push)](https://github.com/fla-org/flash-linear-attention/actions/workflows/nvidia-4090.yml) [![nvidia-h100-ci](https://github.com/fla-org/flash-linear-attention/actions/workflows/nvidia-h100.yml/badge.svg?branch=main&event=push)](https://github.com/fla-org/flash-linear-attention/actions/workflows/nvidia-h100.yml) [![intel-a770-ci](https://github.com/fla-org/flash-linear-attention/actions/workflows/intel-a770.yml/badge.svg?event=push)](https://github.com/fla-org/flash-linear-attention/actions/workflows/intel-a770.yml)
129
+ [![nvidia-4090-ci](https://github.com/fla-org/flash-linear-attention/actions/workflows/nvidia-4090.yml/badge.svg?branch=main&event=push)](https://github.com/fla-org/flash-linear-attention/actions/workflows/nvidia-4090.yml) [![nvidia-h100-ci](https://github.com/fla-org/flash-linear-attention/actions/workflows/nvidia-h100.yml/badge.svg?branch=main&event=push)](https://github.com/fla-org/flash-linear-attention/actions/workflows/nvidia-h100.yml) [![intel-a770-ci](https://github.com/fla-org/flash-linear-attention/actions/workflows/intel-a770.yml/badge.svg?event=push)](https://github.com/fla-org/flash-linear-attention/actions/workflows/intel-a770.yml)
128
130
 
129
131
  The following requirements should be satisfied
130
132
  - [PyTorch](https://pytorch.org/) >= 2.5
@@ -386,9 +388,8 @@ SambaForCausalLM(
386
388
  (layers): ModuleList(
387
389
  (0): SambaBlock(
388
390
  (mixer_norm): RMSNorm(2304, eps=1e-05)
389
- (mixer): MambaMixer(
391
+ (mixer): Mamba(
390
392
  (conv1d): Conv1d(4608, 4608, kernel_size=(4,), stride=(1,), padding=(3,), groups=4608)
391
- (act): SiLU()
392
393
  (in_proj): Linear(in_features=2304, out_features=9216, bias=False)
393
394
  (x_proj): Linear(in_features=4608, out_features=176, bias=False)
394
395
  (dt_proj): Linear(in_features=144, out_features=4608, bias=True)
@@ -444,14 +445,14 @@ Follow the steps below to use this library:
444
445
 
445
446
  2. Run evaluation with:
446
447
  ```sh
447
- $ PATH='fla-hub/gla-1.3B-100B'
448
+ $ MODEL='fla-hub/gla-1.3B-100B'
448
449
  $ python -m evals.harness --model hf \
449
- --model_args pretrained=$PATH,dtype=bfloat16 \
450
+ --model_args pretrained=$MODEL,dtype=bfloat16 \
450
451
  --tasks wikitext,lambada_openai,piqa,hellaswag,winogrande,arc_easy,arc_challenge,boolq,sciq,copa,openbookqa \
451
452
  --batch_size 64 \
452
453
  --num_fewshot 0 \
453
454
  --device cuda \
454
- --show_config
455
+ --show_config
455
456
  ```
456
457
 
457
458
  We've made `fla` compatible with hf-style evaluations, you can call [evals.harness](evals/harness.py) to finish the evaluations.
@@ -461,14 +462,43 @@ Running the command above will provide the task results reported in the GLA pape
461
462
 
462
463
  To perform data-parallel evaluation (where each GPU loads a separate full copy of the model), we leverage the accelerate launcher as follows:
463
464
  ```sh
464
- $ PATH='fla-hub/gla-1.3B-100B'
465
- $ accelerate launch -m evals.harness --model hf \
466
- --model_args pretrained=$PATH,dtype=bfloat16 \
465
+ $ MODEL='fla-hub/gla-1.3B-100B'
466
+ $ accelerate launch -m evals.harness --model hf \
467
+ --model_args pretrained=$MODEL,dtype=bfloat16,trust_remote_code=True \
467
468
  --tasks wikitext,lambada_openai,piqa,hellaswag,winogrande,arc_easy,arc_challenge,boolq,sciq,copa,openbookqa \
468
- --batch_size 64 \
469
- --num_fewshot 0 \
470
- --device cuda \
471
- --show_config
469
+ --batch_size 64 \
470
+ --num_fewshot 0 \
471
+ --device cuda \
472
+ --show_config \
473
+ --trust_remote_code
474
+ ```
475
+
476
+ 4. 📏 RULER Benchmark suite
477
+
478
+ The RULER benchmarks are commonly used for evaluating model performance on long-context tasks.
479
+ You can evaluate `fla` models on RULER directly using `lm-evaluation-harness`. RULER is only available in a relatively recent version of `lm-evaluation-harness`, so make sure you have the latest version installed.
480
+
481
+ ```
482
+ git clone --depth 1 https://github.com/EleutherAI/lm-evaluation-harness
483
+ cd lm-evaluation-harness
484
+ pip install -e .
485
+ ```
486
+
487
+
488
+ Then, install the necessary dependencies for RULER:
489
+ ```sh
490
+ pip install lm_eval["ruler"]
491
+ ```
492
+ and run evaluation by (e.g., 32k contexts):
493
+ ```sh
494
+ $ accelerate launch -m evals.harness \
495
+ --output_path $OUTPUT \
496
+ --tasks niah_single_1,niah_single_2,niah_single_3,niah_multikey_1,niah_multikey_2,niah_multikey_3,niah_multiquery,niah_multivalue,ruler_vt,ruler_cwe,ruler_fwe,ruler_qa_hotpot,ruler_qa_squad \
497
+ --model_args pretrained=$MODEL,dtype=bfloat16,max_length=32768,trust_remote_code=True \
498
+ --metadata='{"max_seq_lengths":[4096,8192,16384,32768]}' \
499
+ --batch_size 2 \
500
+ --show_config \
501
+ --trust_remote_code
472
502
  ```
473
503
 
474
504
  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.
@@ -28,9 +28,10 @@ This repo aims at providing a collection of efficient Triton-based implementatio
28
28
  * [Acknowledgments](#acknowledgments)
29
29
 
30
30
  ## News
31
+ - **$\texttt{[2025-05]}$:** 🎉 Add Rodimus* implementation to `fla` ([paper](https://arxiv.org/abs/2410.06577)).
31
32
  - **$\texttt{[2025-04]}$:** 🎉 Add DeltaProduct implementation to `fla` ([paper](https://arxiv.org/abs/2502.10297)).
32
33
  - **$\texttt{[2025-04]}$:** 🎉 Add FoX implementation to `fla` ([paper](https://arxiv.org/abs/2503.02130)).
33
- - **$\texttt{[2025-03]}$:** We have changed the default `initializer_range` to the magic 🐳 0.006, leading to great improvements across all models.
34
+ - **$\texttt{[2025-03]}$:** ~~We have changed the default `initializer_range` to the magic 🐳 0.006~~ The `initializer_range` was rolled back to the default value of 0.02. For actual training, we recommend trying both.
34
35
  - **$\texttt{[2025-02]}$:** 🐳 Add NSA implementations to `fla`. See kernels [here](fla/ops/nsa).
35
36
  - **$\texttt{[2025-01]}$:** 🔥 We are migrating to `torchtitan`-based training framework. Check out the [flame](https://github.com/fla-org/flame) repo for more details.
36
37
  - **$\texttt{[2025-01]}$:** 🎉 Add RWKV7 implementations (both kernels and models) to `fla`.
@@ -51,7 +52,7 @@ This repo aims at providing a collection of efficient Triton-based implementatio
51
52
  Roughly sorted according to the timeline supported in `fla`. The recommended training mode is `chunk` when available.
52
53
 
53
54
  | Year | Venue | Model | Paper | Code | `fla` impl |
54
- |:-----| :------ |:---------------|:----------------------------------------------------------------------------------------------------------------------------------------------| :---------------------------------------------------------------------------------------------: |:------------------------------------------------------------------------------------------------------:|
55
+ | :--- | :------ | :------------- | :-------------------------------------------------------------------------------------------------------------------------------------------- | :---------------------------------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------------: |
55
56
  | 2023 | | RetNet | [Retentive network: a successor to transformer for large language models](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) |
56
57
  | 2024 | ICML | GLA | [Gated Linear Attention Transformers with Hardware-Efficient Training](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) |
57
58
  | 2024 | ICML | Based | [Simple linear attention language models balance the recall-throughput tradeoff](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) |
@@ -69,11 +70,12 @@ Roughly sorted according to the timeline supported in `fla`. The recommended tra
69
70
  | 2025 | | RWKV7 | [RWKV-7 "Goose" with Expressive Dynamic State Evolution](https://arxiv.org/abs/2503.14456) | [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) |
70
71
  | 2025 | | NSA | [Native Sparse Attention: Hardware-Aligned and Natively Trainable Sparse Attention](https://arxiv.org/abs/2502.11089) | | [code](https://github.com/fla-org/flash-linear-attention/tree/main/fla/ops/nsa) |
71
72
  | 2025 | | FoX | [Forgetting Transformer: Softmax Attention with a Forget Gate](https://arxiv.org/abs/2503.02130) | [official](https://github.com/zhixuan-lin/forgetting-transformer) | [code](https://github.com/fla-org/flash-linear-attention/tree/main/fla/ops/forgetting_attn) |
72
- | 2025 | | DeltaProduct | [DeltaProduct: Improving State-Tracking in Linear RNNs via Householder Products](https://arxiv.org/abs/2502.10297) | | [code](https://github.com/fla-org/flash-linear-attention/tree/main/fla/layers/gated_deltaproduct.py) |
73
+ | 2025 | | DeltaProduct | [DeltaProduct: Improving State-Tracking in Linear RNNs via Householder Products](https://arxiv.org/abs/2502.10297) | | [code](https://github.com/fla-org/flash-linear-attention/tree/main/fla/layers/gated_deltaproduct.py) |
74
+ | 2025 | ICLR | Rodimus* | [Rodimus*: Breaking the Accuracy-Efficiency Trade-Off with Efficient Attentions](https://arxiv.org/abs/2410.06577) | [official](https://github.com/codefuse-ai/rodimus) | [code](https://github.com/fla-org/flash-linear-attention/blob/main/fla/layers/rodimus.py) |
73
75
 
74
76
  ## Installation
75
77
 
76
- [![nvidia-4090-ci](https://github.com/fla-org/flash-linear-attention/actions/workflows/nvidia-4090.yml/badge.svg?branch=main&event=push)](https://github.com/fla-org/flash-linear-attention/actions/workflows/nvidia-4090.yml) [![nvidia-h100-ci](https://github.com/fla-org/flash-linear-attention/actions/workflows/nvidia-h100.yml/badge.svg?branch=main&event=push)](https://github.com/fla-org/flash-linear-attention/actions/workflows/nvidia-h100.yml) [![intel-a770-ci](https://github.com/fla-org/flash-linear-attention/actions/workflows/intel-a770.yml/badge.svg?event=push)](https://github.com/fla-org/flash-linear-attention/actions/workflows/intel-a770.yml)
78
+ [![nvidia-4090-ci](https://github.com/fla-org/flash-linear-attention/actions/workflows/nvidia-4090.yml/badge.svg?branch=main&event=push)](https://github.com/fla-org/flash-linear-attention/actions/workflows/nvidia-4090.yml) [![nvidia-h100-ci](https://github.com/fla-org/flash-linear-attention/actions/workflows/nvidia-h100.yml/badge.svg?branch=main&event=push)](https://github.com/fla-org/flash-linear-attention/actions/workflows/nvidia-h100.yml) [![intel-a770-ci](https://github.com/fla-org/flash-linear-attention/actions/workflows/intel-a770.yml/badge.svg?event=push)](https://github.com/fla-org/flash-linear-attention/actions/workflows/intel-a770.yml)
77
79
 
78
80
  The following requirements should be satisfied
79
81
  - [PyTorch](https://pytorch.org/) >= 2.5
@@ -335,9 +337,8 @@ SambaForCausalLM(
335
337
  (layers): ModuleList(
336
338
  (0): SambaBlock(
337
339
  (mixer_norm): RMSNorm(2304, eps=1e-05)
338
- (mixer): MambaMixer(
340
+ (mixer): Mamba(
339
341
  (conv1d): Conv1d(4608, 4608, kernel_size=(4,), stride=(1,), padding=(3,), groups=4608)
340
- (act): SiLU()
341
342
  (in_proj): Linear(in_features=2304, out_features=9216, bias=False)
342
343
  (x_proj): Linear(in_features=4608, out_features=176, bias=False)
343
344
  (dt_proj): Linear(in_features=144, out_features=4608, bias=True)
@@ -393,14 +394,14 @@ Follow the steps below to use this library:
393
394
 
394
395
  2. Run evaluation with:
395
396
  ```sh
396
- $ PATH='fla-hub/gla-1.3B-100B'
397
+ $ MODEL='fla-hub/gla-1.3B-100B'
397
398
  $ python -m evals.harness --model hf \
398
- --model_args pretrained=$PATH,dtype=bfloat16 \
399
+ --model_args pretrained=$MODEL,dtype=bfloat16 \
399
400
  --tasks wikitext,lambada_openai,piqa,hellaswag,winogrande,arc_easy,arc_challenge,boolq,sciq,copa,openbookqa \
400
401
  --batch_size 64 \
401
402
  --num_fewshot 0 \
402
403
  --device cuda \
403
- --show_config
404
+ --show_config
404
405
  ```
405
406
 
406
407
  We've made `fla` compatible with hf-style evaluations, you can call [evals.harness](evals/harness.py) to finish the evaluations.
@@ -410,14 +411,43 @@ Running the command above will provide the task results reported in the GLA pape
410
411
 
411
412
  To perform data-parallel evaluation (where each GPU loads a separate full copy of the model), we leverage the accelerate launcher as follows:
412
413
  ```sh
413
- $ PATH='fla-hub/gla-1.3B-100B'
414
- $ accelerate launch -m evals.harness --model hf \
415
- --model_args pretrained=$PATH,dtype=bfloat16 \
414
+ $ MODEL='fla-hub/gla-1.3B-100B'
415
+ $ accelerate launch -m evals.harness --model hf \
416
+ --model_args pretrained=$MODEL,dtype=bfloat16,trust_remote_code=True \
416
417
  --tasks wikitext,lambada_openai,piqa,hellaswag,winogrande,arc_easy,arc_challenge,boolq,sciq,copa,openbookqa \
417
- --batch_size 64 \
418
- --num_fewshot 0 \
419
- --device cuda \
420
- --show_config
418
+ --batch_size 64 \
419
+ --num_fewshot 0 \
420
+ --device cuda \
421
+ --show_config \
422
+ --trust_remote_code
423
+ ```
424
+
425
+ 4. 📏 RULER Benchmark suite
426
+
427
+ The RULER benchmarks are commonly used for evaluating model performance on long-context tasks.
428
+ You can evaluate `fla` models on RULER directly using `lm-evaluation-harness`. RULER is only available in a relatively recent version of `lm-evaluation-harness`, so make sure you have the latest version installed.
429
+
430
+ ```
431
+ git clone --depth 1 https://github.com/EleutherAI/lm-evaluation-harness
432
+ cd lm-evaluation-harness
433
+ pip install -e .
434
+ ```
435
+
436
+
437
+ Then, install the necessary dependencies for RULER:
438
+ ```sh
439
+ pip install lm_eval["ruler"]
440
+ ```
441
+ and run evaluation by (e.g., 32k contexts):
442
+ ```sh
443
+ $ accelerate launch -m evals.harness \
444
+ --output_path $OUTPUT \
445
+ --tasks niah_single_1,niah_single_2,niah_single_3,niah_multikey_1,niah_multikey_2,niah_multikey_3,niah_multiquery,niah_multivalue,ruler_vt,ruler_cwe,ruler_fwe,ruler_qa_hotpot,ruler_qa_squad \
446
+ --model_args pretrained=$MODEL,dtype=bfloat16,max_length=32768,trust_remote_code=True \
447
+ --metadata='{"max_seq_lengths":[4096,8192,16384,32768]}' \
448
+ --batch_size 2 \
449
+ --show_config \
450
+ --trust_remote_code
421
451
  ```
422
452
 
423
453
  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.
@@ -16,6 +16,7 @@ from fla.layers import (
16
16
  LinearAttention,
17
17
  MultiScaleRetention,
18
18
  NativeSparseAttention,
19
+ PaTHAttention,
19
20
  ReBasedLinearAttention,
20
21
  RWKV6Attention,
21
22
  RWKV7Attention
@@ -38,14 +39,19 @@ from fla.models import (
38
39
  HGRN2ForCausalLM,
39
40
  HGRN2Model,
40
41
  HGRNForCausalLM,
42
+ HGRNModel,
41
43
  LightNetForCausalLM,
42
44
  LightNetModel,
43
45
  LinearAttentionForCausalLM,
44
46
  LinearAttentionModel,
45
47
  NSAForCausalLM,
46
48
  NSAModel,
49
+ PaTHAttentionForCausalLM,
50
+ PaTHAttentionModel,
47
51
  RetNetForCausalLM,
48
52
  RetNetModel,
53
+ RodimusForCausalLM,
54
+ RodimusModel,
49
55
  RWKV6ForCausalLM,
50
56
  RWKV6Model,
51
57
  RWKV7ForCausalLM,
@@ -70,6 +76,7 @@ __all__ = [
70
76
  'LinearAttention',
71
77
  'MultiScaleRetention',
72
78
  'NativeSparseAttention',
79
+ 'PaTHAttention',
73
80
  'ReBasedLinearAttention',
74
81
  'RWKV6Attention',
75
82
  'RWKV7Attention',
@@ -97,14 +104,18 @@ __all__ = [
97
104
  'LinearAttentionModel',
98
105
  'NSAForCausalLM',
99
106
  'NSAModel',
107
+ 'PaTHAttentionForCausalLM',
108
+ 'PaTHAttentionModel',
100
109
  'RetNetForCausalLM',
101
110
  'RetNetModel',
102
111
  'RWKV6ForCausalLM',
103
112
  'RWKV6Model',
104
113
  'RWKV7ForCausalLM',
105
114
  'RWKV7Model',
115
+ 'RodimusForCausalLM',
116
+ 'RodimusModel',
106
117
  'TransformerForCausalLM',
107
118
  'TransformerModel',
108
119
  ]
109
120
 
110
- __version__ = '0.2.0'
121
+ __version__ = '0.2.2'
@@ -15,11 +15,15 @@ from .hgrn import HGRNAttention
15
15
  from .hgrn2 import HGRN2Attention
16
16
  from .lightnet import LightNetAttention
17
17
  from .linear_attn import LinearAttention
18
+ from .mamba import Mamba
19
+ from .mamba2 import Mamba2
18
20
  from .multiscale_retention import MultiScaleRetention
19
21
  from .nsa import NativeSparseAttention
22
+ from .path_attn import PaTHAttention
20
23
  from .rebased import ReBasedLinearAttention
21
24
  from .rwkv6 import RWKV6Attention
22
25
  from .rwkv7 import RWKV7Attention
26
+ from .rodimus import RodimusAttention, SlidingWindowSharedKeyAttention
23
27
 
24
28
  __all__ = [
25
29
  'ABCAttention',
@@ -36,9 +40,14 @@ __all__ = [
36
40
  'HGRN2Attention',
37
41
  'LightNetAttention',
38
42
  'LinearAttention',
43
+ 'Mamba',
44
+ 'Mamba2',
39
45
  'MultiScaleRetention',
40
46
  'NativeSparseAttention',
41
47
  'ReBasedLinearAttention',
42
48
  'RWKV6Attention',
43
49
  'RWKV7Attention',
50
+ 'RodimusAttention',
51
+ 'SlidingWindowSharedKeyAttention',
52
+ 'PaTHAttention'
44
53
  ]
@@ -14,6 +14,7 @@ from transformers.utils import logging
14
14
 
15
15
  from fla.layers.utils import pad_input, unpad_input
16
16
  from fla.modules import RMSNorm, RotaryEmbedding
17
+ from fla.ops.utils.index import prepare_lens_from_mask
17
18
 
18
19
  if TYPE_CHECKING:
19
20
  from fla.models.utils import Cache
@@ -109,7 +110,7 @@ class Attention(nn.Module):
109
110
 
110
111
  if attention_mask is not None:
111
112
  # to deliminate the offsets of padding tokens
112
- seqlen_offset = seqlen_offset + attention_mask.sum(-1) - attention_mask.shape[-1]
113
+ seqlen_offset = seqlen_offset + prepare_lens_from_mask(attention_mask) - attention_mask.shape[-1]
113
114
  max_seqlen = q.shape[1] + max(seqlen_offset)
114
115
 
115
116
  if self.max_position_embeddings is not None:
@@ -15,6 +15,7 @@ from transformers.utils import logging
15
15
  from fla.layers.utils import pad_input, unpad_input
16
16
  from fla.modules import RotaryEmbedding
17
17
  from fla.modules.fused_bitlinear import FusedBitLinear
18
+ from fla.ops.utils.index import prepare_lens_from_mask
18
19
 
19
20
  if TYPE_CHECKING:
20
21
  from fla.models.utils import Cache
@@ -100,7 +101,7 @@ class BitAttention(nn.Module):
100
101
 
101
102
  if attention_mask is not None:
102
103
  # to deliminate the offsets of padding tokens
103
- seqlen_offset = seqlen_offset + attention_mask.sum(-1) - attention_mask.shape[-1]
104
+ seqlen_offset = seqlen_offset + prepare_lens_from_mask(attention_mask) - attention_mask.shape[-1]
104
105
  max_seqlen = q.shape[1] + max(seqlen_offset)
105
106
 
106
107
  if self.max_position_embeddings is not None:
@@ -3,6 +3,7 @@
3
3
 
4
4
  from __future__ import annotations
5
5
 
6
+ import warnings
6
7
  from typing import TYPE_CHECKING, Dict, Optional, Tuple
7
8
 
8
9
  import torch
@@ -147,7 +148,7 @@ class DeltaNet(nn.Module):
147
148
  activation='silu'
148
149
  )
149
150
  else:
150
- raise UserWarning(
151
+ warnings.warn(
151
152
  "ShortConvolution is crucial to the performance. "
152
153
  "Do not turn it off, i.e., setting `use_short_conv=False` unless you know what you are doing."
153
154
  )
@@ -14,7 +14,7 @@ from transformers.utils import logging
14
14
 
15
15
  from fla.layers.utils import pad_input, unpad_input
16
16
  from fla.modules import GroupNorm
17
- from fla.ops.forgetting_attn.decoding import attn_decoding_one_step
17
+ from fla.ops.attn.decoding import attn_decoding_one_step
18
18
  from fla.ops.forgetting_attn.parallel import parallel_forgetting_attn
19
19
 
20
20
  if TYPE_CHECKING:
@@ -4,11 +4,12 @@
4
4
  from __future__ import annotations
5
5
 
6
6
  import math
7
+ import warnings
7
8
  from typing import TYPE_CHECKING, Dict, Optional, Tuple
8
9
 
9
10
  import torch
10
11
  import torch.nn as nn
11
- from einops import rearrange
12
+ from einops import rearrange, repeat
12
13
  from torch.nn import functional as F
13
14
 
14
15
  from fla.layers.utils import get_unpad_data, index_first_axis, pad_input
@@ -59,6 +60,9 @@ class GatedDeltaNet(nn.Module):
59
60
  The dimension of each head. Default: 256.
60
61
  num_heads (int, Optional):
61
62
  The number of heads. Default: 4.
63
+ num_v_heads (int, Optional):
64
+ The number of heads for the value projection, equal to `num_heads` if `None`.
65
+ GVA is applied if `num_v_heads` > `num_heads`. Default: `None`.
62
66
  mode (str, Optional):
63
67
  Which Gated DeltaNet kernel to use.
64
68
  Currently available: `chunk` and `fused_recurrent`.
@@ -85,6 +89,7 @@ class GatedDeltaNet(nn.Module):
85
89
  expand_v: float = 2,
86
90
  head_dim: int = 256,
87
91
  num_heads: int = 6,
92
+ num_v_heads: int = None,
88
93
  mode: str = 'chunk',
89
94
  use_gate: bool = True,
90
95
  use_short_conv: bool = True,
@@ -108,19 +113,25 @@ class GatedDeltaNet(nn.Module):
108
113
 
109
114
  self.head_dim = head_dim
110
115
  self.num_heads = num_heads
116
+ self.num_v_heads = num_v_heads if num_v_heads is not None else num_heads
111
117
 
112
- self.key_dim = int(self.num_heads * self.head_dim)
113
- self.value_dim = int(self.key_dim * self.expand_v)
114
118
  self.head_k_dim = head_dim
115
- self.head_v_dim = int(head_dim * self.expand_v)
119
+ self.head_v_dim = int(self.head_dim * self.expand_v)
120
+ self.key_dim = int(self.num_heads * self.head_k_dim)
121
+ self.value_dim = int(self.num_v_heads * self.head_v_dim)
116
122
  self.layer_idx = layer_idx
117
123
 
118
124
  # Consistency check: Ensure expand_v produces integer values
119
- if not math.isclose(self.key_dim * expand_v, self.value_dim, rel_tol=1e-5):
125
+ if not math.isclose(self.num_v_heads * self.head_dim * expand_v, self.value_dim, rel_tol=1e-5):
120
126
  raise ValueError(
121
127
  f"expand_v={expand_v} does not produce an integer value when multiplied by key_dim={self.key_dim}. "
122
- f"Resulting value_dim would be {self.key_dim * expand_v}, which is invalid for nn.Linear."
128
+ f"Resulting value_dim would be {self.num_v_heads * self.head_dim * expand_v}, which is invalid for nn.Linear."
123
129
  )
130
+ if self.num_v_heads > self.num_heads and self.num_v_heads % self.num_heads != 0:
131
+ raise ValueError(
132
+ f"num_v_heads={self.num_v_heads} must be divisible by num_heads={self.num_heads}."
133
+ )
134
+
124
135
  if not math.isclose(head_dim * expand_v, self.head_v_dim, rel_tol=1e-5):
125
136
  raise ValueError(
126
137
  f"expand_v={expand_v} does not produce an integer value when multiplied by head_dim={head_dim}. "
@@ -131,10 +142,10 @@ class GatedDeltaNet(nn.Module):
131
142
  self.q_proj = nn.Linear(hidden_size, self.key_dim, bias=False)
132
143
  self.k_proj = nn.Linear(hidden_size, self.key_dim, bias=False)
133
144
  self.v_proj = nn.Linear(hidden_size, self.value_dim, bias=False)
134
- self.a_proj = nn.Linear(hidden_size, self.num_heads, bias=False)
135
- self.b_proj = nn.Linear(hidden_size, self.num_heads, bias=False)
145
+ self.a_proj = nn.Linear(hidden_size, self.num_v_heads, bias=False)
146
+ self.b_proj = nn.Linear(hidden_size, self.num_v_heads, bias=False)
136
147
 
137
- A = torch.empty(self.num_heads, dtype=torch.float32).uniform_(0, 16)
148
+ A = torch.empty(self.num_v_heads, dtype=torch.float32).uniform_(0, 16)
138
149
  self.A_log = nn.Parameter(torch.log(A))
139
150
  self.A_log._no_weight_decay = True
140
151
  # hard coded for now
@@ -142,7 +153,7 @@ class GatedDeltaNet(nn.Module):
142
153
  dt_max = 0.1
143
154
  dt_init_floor = 1e-4
144
155
  dt = torch.exp(
145
- torch.rand(self.num_heads) * (math.log(dt_max) - math.log(dt_min))
156
+ torch.rand(self.num_v_heads) * (math.log(dt_max) - math.log(dt_min))
146
157
  + math.log(dt_min)
147
158
  )
148
159
  dt = torch.clamp(dt, min=dt_init_floor)
@@ -171,7 +182,7 @@ class GatedDeltaNet(nn.Module):
171
182
  activation='silu'
172
183
  )
173
184
  else:
174
- raise UserWarning(
185
+ warnings.warn(
175
186
  "ShortConvolution is crucial to the performance. "
176
187
  "Do not turn it off, i.e., setting `use_short_conv=False` unless you know what you are doing."
177
188
  )
@@ -242,6 +253,10 @@ class GatedDeltaNet(nn.Module):
242
253
 
243
254
  q, k = map(lambda x: rearrange(x, '... (h d) -> ... h d', d=self.head_k_dim), (q, k))
244
255
  v = rearrange(v, '... (h d) -> ... h d', d=self.head_v_dim)
256
+
257
+ if self.num_v_heads > self.num_heads:
258
+ q, k = map(lambda x: repeat(x, '... h d -> ... (h g) d', g=self.num_v_heads // self.num_heads), (q, k))
259
+
245
260
  beta = self.b_proj(hidden_states).sigmoid()
246
261
  g = -self.A_log.float().exp() * F.softplus(self.a_proj(hidden_states).float() + self.dt_bias)
247
262
 
@@ -119,15 +119,10 @@ class GatedDeltaProduct(nn.Module):
119
119
  ]
120
120
  )
121
121
  if use_short_conv:
122
- self.q_conv1ds = nn.ModuleList(
123
- [
124
- ShortConvolution(
125
- hidden_size=self.key_dim,
126
- kernel_size=conv_size,
127
- activation="silu",
128
- )
129
- for _ in range(num_householder)
130
- ]
122
+ self.q_conv1d = ShortConvolution(
123
+ hidden_size=self.key_dim,
124
+ kernel_size=conv_size,
125
+ activation="silu",
131
126
  )
132
127
  self.k_conv1ds = nn.ModuleList(
133
128
  [
@@ -229,6 +224,13 @@ class GatedDeltaProduct(nn.Module):
229
224
  if attention_mask is not None
230
225
  else None
231
226
  )
227
+ if i == self.num_householder - 1:
228
+ q, conv_state_q = self.q_conv1d(
229
+ x=self.q_proj(hidden_states),
230
+ mask=conv_mask,
231
+ cache=conv_state_q,
232
+ output_final_state=use_cache,
233
+ )
232
234
 
233
235
  k, conv_state_k = self.k_conv1ds[i](
234
236
  x=self.k_projs[i](hidden_states),
@@ -246,6 +248,8 @@ class GatedDeltaProduct(nn.Module):
246
248
  else:
247
249
  k = self.silu(self.k_projs[i](hidden_states))
248
250
  v = self.silu(self.v_projs[i](hidden_states))
251
+ if i == self.num_householder - 1:
252
+ q = self.silu(self.q_proj(hidden_states))
249
253
 
250
254
  ks.append(k)
251
255
  vs.append(v)
@@ -259,15 +263,6 @@ class GatedDeltaProduct(nn.Module):
259
263
  beta = beta * 2
260
264
  betas.append(beta)
261
265
 
262
- if self.use_short_conv:
263
- q, conv_state_q = self.q_conv1ds[0](
264
- x=self.q_proj(hidden_states),
265
- mask=conv_mask,
266
- cache=conv_state_q,
267
- output_final_state=use_cache,
268
- )
269
- else:
270
- q = self.silu(self.q_proj(hidden_states))
271
266
  q = interleave_multiple_sequences(
272
267
  [torch.zeros_like(q)] * (self.num_householder - 1) + [q]
273
268
  )
@@ -9,7 +9,7 @@ from typing import TYPE_CHECKING, Dict, Optional, Tuple
9
9
  import torch
10
10
  import torch.nn as nn
11
11
  import torch.nn.functional as F
12
- from einops import rearrange
12
+ from einops import rearrange, repeat
13
13
 
14
14
  from fla.layers.utils import get_unpad_data, index_first_axis, pad_input
15
15
  from fla.modules import RMSNorm, ShortConvolution
@@ -178,6 +178,9 @@ class GatedSlotAttention(nn.Module):
178
178
  f = F.logsigmoid(f) / self.gate_logit_normalizer
179
179
  s = (1 - f.exp()).to(f.dtype)
180
180
 
181
+ if self.num_kv_groups > 1:
182
+ k, v, f, s = map(lambda x: repeat(x, '... h d -> ... (h g) d', g=self.num_kv_groups), (k, v, f, s))
183
+
181
184
  recurrent_state = last_state['recurrent_state'] if last_state is not None else None
182
185
  if mode == 'fused_recurrent':
183
186
  o, recurrent_state = fused_recurrent_gsa(
@@ -115,12 +115,11 @@ class HGRNAttention(nn.Module):
115
115
  i = self.i_proj(hidden_states)
116
116
  f = self.f_proj(hidden_states)
117
117
 
118
+ f = F.logsigmoid(f)
118
119
  # the lower bound for the first layer is zero
119
- if lower_bound is None or self.layer_idx == 0:
120
- i, f = swiglu(i, 1 - f.sigmoid()), F.logsigmoid(f)
121
- else:
122
- g = lower_bound + (1 - lower_bound) * f.sigmoid()
123
- i, f = swiglu(i, 1 - g), g.log()
120
+ if lower_bound is not None and self.layer_idx > 0:
121
+ f = torch.logaddexp(lower_bound.log(), torch.log1p(-lower_bound) + f).to(f)
122
+ i = swiglu(i, 1 - f.exp())
124
123
 
125
124
  # dealing with left-padding
126
125
  if attention_mask is not None:
@@ -139,15 +139,11 @@ class HGRN2Attention(nn.Module):
139
139
 
140
140
  q = swish(q)
141
141
 
142
- # improve precision
143
- f = f.float()
144
-
142
+ g = F.logsigmoid(f)
145
143
  # the lower bound for the first layer is zero
146
- if lower_bound is None or self.layer_idx == 0:
147
- k, g = 1 - f.sigmoid(), F.logsigmoid(f)
148
- else:
149
- g = lower_bound + (1 - lower_bound) * f.sigmoid()
150
- k, g = 1 - g, g.log()
144
+ if lower_bound is not None and self.layer_idx > 0:
145
+ g = torch.logaddexp(lower_bound.log(), torch.log1p(-lower_bound) + g)
146
+ k = 1 - g.exp()
151
147
 
152
148
  q, k, g = map(lambda x: rearrange(x, '... (h d) -> ... h d', d=self.head_f_dim), (q, k.to(i), g))
153
149
  i = rearrange(i, '... (h d) -> ... h d', d=self.head_i_dim)