ejkernel 0.0.1__py3-none-any.whl

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 (183) hide show
  1. ejkernel/__init__.py +51 -0
  2. ejkernel/benchmarks.py +772 -0
  3. ejkernel/callib/__init__.py +34 -0
  4. ejkernel/callib/_ejit.py +513 -0
  5. ejkernel/callib/_triton_call.py +891 -0
  6. ejkernel/callib/_utils.py +243 -0
  7. ejkernel/kernels/__init__.py +65 -0
  8. ejkernel/kernels/_cuda/__init__.py +15 -0
  9. ejkernel/kernels/_pallas/__init__.py +18 -0
  10. ejkernel/kernels/_pallas/gpu/__init__.py +19 -0
  11. ejkernel/kernels/_pallas/gpu/ragged_decode_attention/__init__.py +18 -0
  12. ejkernel/kernels/_pallas/gpu/ragged_decode_attention/_interface.py +81 -0
  13. ejkernel/kernels/_pallas/gpu/ragged_decode_attention/_pallas_impl_fwd.py +382 -0
  14. ejkernel/kernels/_pallas/gpu/scaled_dot_product_attention/__init__.py +25 -0
  15. ejkernel/kernels/_pallas/gpu/scaled_dot_product_attention/_interface.py +131 -0
  16. ejkernel/kernels/_pallas/tpu/__init__.py +32 -0
  17. ejkernel/kernels/_pallas/tpu/blocksparse_attention/__init__.py +66 -0
  18. ejkernel/kernels/_pallas/tpu/blocksparse_attention/_info.py +975 -0
  19. ejkernel/kernels/_pallas/tpu/blocksparse_attention/_kernel.py +2573 -0
  20. ejkernel/kernels/_pallas/tpu/blocksparse_attention/_masks.py +546 -0
  21. ejkernel/kernels/_pallas/tpu/flash_attention/__init__.py +24 -0
  22. ejkernel/kernels/_pallas/tpu/flash_attention/_interface.py +188 -0
  23. ejkernel/kernels/_pallas/tpu/flash_attention/_pallas_impl_bwd.py +676 -0
  24. ejkernel/kernels/_pallas/tpu/flash_attention/_pallas_impl_fwd.py +451 -0
  25. ejkernel/kernels/_pallas/tpu/flash_attention/_utils.py +373 -0
  26. ejkernel/kernels/_pallas/tpu/grouped_matmul/__init__.py +18 -0
  27. ejkernel/kernels/_pallas/tpu/grouped_matmul/_interface.py +250 -0
  28. ejkernel/kernels/_pallas/tpu/grouped_matmul/_pallas_impl.py +979 -0
  29. ejkernel/kernels/_pallas/tpu/grouped_matmul/_utils.py +191 -0
  30. ejkernel/kernels/_pallas/tpu/page_attention/__init__.py +18 -0
  31. ejkernel/kernels/_pallas/tpu/page_attention/_interface.py +253 -0
  32. ejkernel/kernels/_pallas/tpu/page_attention/_pallas_impl_fwd.py +290 -0
  33. ejkernel/kernels/_pallas/tpu/ragged_decode_attention/__init__.py +18 -0
  34. ejkernel/kernels/_pallas/tpu/ragged_decode_attention/_interface.py +74 -0
  35. ejkernel/kernels/_pallas/tpu/ragged_decode_attention/_pallas_impl_fwd.py +247 -0
  36. ejkernel/kernels/_pallas/tpu/ragged_page_attention/__init__.py +20 -0
  37. ejkernel/kernels/_pallas/tpu/ragged_page_attention/_interface.py +245 -0
  38. ejkernel/kernels/_pallas/tpu/ragged_page_attention/_pallas_impl_fwd.py +590 -0
  39. ejkernel/kernels/_pallas/tpu/ragged_page_attention/_utils.py +437 -0
  40. ejkernel/kernels/_pallas/tpu/ragged_page_attention_v3/__init__.py +20 -0
  41. ejkernel/kernels/_pallas/tpu/ragged_page_attention_v3/_interface.py +115 -0
  42. ejkernel/kernels/_pallas/tpu/ragged_page_attention_v3/_pallas_impl_fwd.py +1230 -0
  43. ejkernel/kernels/_pallas/tpu/ragged_page_attention_v3/_pallas_impl_fwd_h64.py +1184 -0
  44. ejkernel/kernels/_pallas/tpu/ragged_page_attention_v3/_utils.py +4545 -0
  45. ejkernel/kernels/_pallas/tpu/ring_attention/__init__.py +24 -0
  46. ejkernel/kernels/_pallas/tpu/ring_attention/_interface.py +225 -0
  47. ejkernel/kernels/_pallas/tpu/ring_attention/_pallas_impl_bwd.py +1003 -0
  48. ejkernel/kernels/_pallas/tpu/ring_attention/_pallas_impl_fwd.py +769 -0
  49. ejkernel/kernels/_pallas/tpu/ring_attention/_utils.py +192 -0
  50. ejkernel/kernels/_registry.py +377 -0
  51. ejkernel/kernels/_triton/__init__.py +59 -0
  52. ejkernel/kernels/_triton/blocksparse_attention/__init__.py +33 -0
  53. ejkernel/kernels/_triton/blocksparse_attention/_interface.py +465 -0
  54. ejkernel/kernels/_triton/blocksparse_attention/_mask.py +530 -0
  55. ejkernel/kernels/_triton/blocksparse_attention/_triton_impl_bwd.py +1380 -0
  56. ejkernel/kernels/_triton/blocksparse_attention/_triton_impl_fwd.py +695 -0
  57. ejkernel/kernels/_triton/blocksparse_attention/_utilities.py +437 -0
  58. ejkernel/kernels/_triton/flash_attention/__init__.py +24 -0
  59. ejkernel/kernels/_triton/flash_attention/_interface.py +385 -0
  60. ejkernel/kernels/_triton/flash_attention/_triton_impl_bwd.py +1494 -0
  61. ejkernel/kernels/_triton/flash_attention/_triton_impl_fwd.py +827 -0
  62. ejkernel/kernels/_triton/flash_attention/_utilities.py +358 -0
  63. ejkernel/kernels/_triton/flash_mla/__init__.py +38 -0
  64. ejkernel/kernels/_triton/flash_mla/_interface.py +100 -0
  65. ejkernel/kernels/_triton/flash_mla/_triton_impl_bwd.py +15 -0
  66. ejkernel/kernels/_triton/flash_mla/_triton_impl_fwd.py +180 -0
  67. ejkernel/kernels/_triton/flash_mla/_utilities.py +15 -0
  68. ejkernel/kernels/_triton/gla/__init__.py +18 -0
  69. ejkernel/kernels/_triton/gla/_interface.py +136 -0
  70. ejkernel/kernels/_triton/lightning_attn/__init__.py +18 -0
  71. ejkernel/kernels/_triton/lightning_attn/_interface.py +143 -0
  72. ejkernel/kernels/_triton/mean_pooling/__init__.py +30 -0
  73. ejkernel/kernels/_triton/mean_pooling/_interface.py +163 -0
  74. ejkernel/kernels/_triton/mean_pooling/_triton_impl_bwd.py +130 -0
  75. ejkernel/kernels/_triton/mean_pooling/_triton_impl_fwd.py +126 -0
  76. ejkernel/kernels/_triton/native_sparse_attention/__init__.py +32 -0
  77. ejkernel/kernels/_triton/native_sparse_attention/_compression.py +753 -0
  78. ejkernel/kernels/_triton/native_sparse_attention/_interface.py +403 -0
  79. ejkernel/kernels/_triton/native_sparse_attention/_triton_impl_bwd.py +394 -0
  80. ejkernel/kernels/_triton/native_sparse_attention/_triton_impl_fwd.py +428 -0
  81. ejkernel/kernels/_triton/native_sparse_attention/_utilities.py +87 -0
  82. ejkernel/kernels/_triton/page_attention/__init__.py +18 -0
  83. ejkernel/kernels/_triton/page_attention/_interface.py +369 -0
  84. ejkernel/kernels/_triton/page_attention/_triton_impl_fwd.py +257 -0
  85. ejkernel/kernels/_triton/ragged_decode_attention/__init__.py +18 -0
  86. ejkernel/kernels/_triton/ragged_decode_attention/_interface.py +75 -0
  87. ejkernel/kernels/_triton/ragged_decode_attention/_triton_impl_fwd.py +302 -0
  88. ejkernel/kernels/_triton/ragged_page_attention/__init__.py +18 -0
  89. ejkernel/kernels/_triton/ragged_page_attention/_interface.py +226 -0
  90. ejkernel/kernels/_triton/ragged_page_attention/_triton_impl_fwd.py +613 -0
  91. ejkernel/kernels/_triton/recurrent/__init__.py +30 -0
  92. ejkernel/kernels/_triton/recurrent/_interface.py +291 -0
  93. ejkernel/kernels/_triton/recurrent/_triton_impl_bwd.py +354 -0
  94. ejkernel/kernels/_triton/recurrent/_triton_impl_fwd.py +216 -0
  95. ejkernel/kernels/_xla/__init__.py +44 -0
  96. ejkernel/kernels/_xla/attention/__init__.py +18 -0
  97. ejkernel/kernels/_xla/attention/_interface.py +197 -0
  98. ejkernel/kernels/_xla/flash_attention/__init__.py +24 -0
  99. ejkernel/kernels/_xla/flash_attention/_interface.py +376 -0
  100. ejkernel/kernels/_xla/flash_attention/_xla_impl_bwd.py +85 -0
  101. ejkernel/kernels/_xla/flash_attention/_xla_impl_fwd.py +474 -0
  102. ejkernel/kernels/_xla/gla/__init__.py +18 -0
  103. ejkernel/kernels/_xla/gla/_interface.py +123 -0
  104. ejkernel/kernels/_xla/grouped_matmul/__init__.py +18 -0
  105. ejkernel/kernels/_xla/grouped_matmul/_interface.py +124 -0
  106. ejkernel/kernels/_xla/lightning_attn/__init__.py +18 -0
  107. ejkernel/kernels/_xla/lightning_attn/_interface.py +129 -0
  108. ejkernel/kernels/_xla/mean_pooling/__init__.py +18 -0
  109. ejkernel/kernels/_xla/mean_pooling/_interface.py +171 -0
  110. ejkernel/kernels/_xla/native_sparse_attention/__init__.py +32 -0
  111. ejkernel/kernels/_xla/native_sparse_attention/_interface.py +435 -0
  112. ejkernel/kernels/_xla/native_sparse_attention/_xla_impl_bwd.py +138 -0
  113. ejkernel/kernels/_xla/native_sparse_attention/_xla_impl_fwd.py +86 -0
  114. ejkernel/kernels/_xla/page_attention/__init__.py +18 -0
  115. ejkernel/kernels/_xla/page_attention/_interface.py +123 -0
  116. ejkernel/kernels/_xla/page_attention/_xla_impl_fwd.py +97 -0
  117. ejkernel/kernels/_xla/ragged_decode_attention/__init__.py +18 -0
  118. ejkernel/kernels/_xla/ragged_decode_attention/_interface.py +119 -0
  119. ejkernel/kernels/_xla/ragged_decode_attention/_xla_impl_fwd.py +468 -0
  120. ejkernel/kernels/_xla/ragged_page_attention/__init__.py +18 -0
  121. ejkernel/kernels/_xla/ragged_page_attention/_interface.py +109 -0
  122. ejkernel/kernels/_xla/ragged_page_attention/_xla_impl_fwd.py +214 -0
  123. ejkernel/kernels/_xla/recurrent/__init__.py +30 -0
  124. ejkernel/kernels/_xla/recurrent/_interface.py +201 -0
  125. ejkernel/kernels/_xla/recurrent/_xla_impl_bwd.py +163 -0
  126. ejkernel/kernels/_xla/recurrent/_xla_impl_fwd.py +242 -0
  127. ejkernel/kernels/_xla/ring_attention/__init__.py +24 -0
  128. ejkernel/kernels/_xla/ring_attention/_interface.py +212 -0
  129. ejkernel/kernels/_xla/ring_attention/_utils.py +163 -0
  130. ejkernel/kernels/_xla/ring_attention/_xla_impl_bwd.py +354 -0
  131. ejkernel/kernels/_xla/ring_attention/_xla_impl_fwd.py +388 -0
  132. ejkernel/kernels/_xla/scaled_dot_product_attention/__init__.py +24 -0
  133. ejkernel/kernels/_xla/scaled_dot_product_attention/_interface.py +106 -0
  134. ejkernel/loggings.py +482 -0
  135. ejkernel/modules/__init__.py +138 -0
  136. ejkernel/modules/base.py +213 -0
  137. ejkernel/modules/operations/__init__.py +143 -0
  138. ejkernel/modules/operations/attention.py +286 -0
  139. ejkernel/modules/operations/blocksparse_attention.py +937 -0
  140. ejkernel/modules/operations/configs.py +333 -0
  141. ejkernel/modules/operations/flash_attention.py +886 -0
  142. ejkernel/modules/operations/gated_linear_attention.py +301 -0
  143. ejkernel/modules/operations/grouped_matmul.py +300 -0
  144. ejkernel/modules/operations/lightning_attention.py +306 -0
  145. ejkernel/modules/operations/multi_head_latent_attention.py +290 -0
  146. ejkernel/modules/operations/native_sparse_attention.py +374 -0
  147. ejkernel/modules/operations/page_attention.py +444 -0
  148. ejkernel/modules/operations/pooling.py +244 -0
  149. ejkernel/modules/operations/ragged_decode_attention.py +588 -0
  150. ejkernel/modules/operations/ragged_page_attention.py +641 -0
  151. ejkernel/modules/operations/recurrent.py +328 -0
  152. ejkernel/modules/operations/ring_attention.py +617 -0
  153. ejkernel/modules/operations/scaled_dot_product_attention.py +417 -0
  154. ejkernel/ops/__init__.py +150 -0
  155. ejkernel/ops/config/__init__.py +43 -0
  156. ejkernel/ops/config/cache.py +187 -0
  157. ejkernel/ops/config/persistent.py +188 -0
  158. ejkernel/ops/config/selection.py +569 -0
  159. ejkernel/ops/core/__init__.py +36 -0
  160. ejkernel/ops/core/kernel.py +671 -0
  161. ejkernel/ops/core/types.py +50 -0
  162. ejkernel/ops/execution/__init__.py +67 -0
  163. ejkernel/ops/execution/batch.py +191 -0
  164. ejkernel/ops/execution/executor.py +505 -0
  165. ejkernel/ops/execution/offline.py +80 -0
  166. ejkernel/ops/execution/profiler.py +475 -0
  167. ejkernel/ops/execution/tuning.py +1197 -0
  168. ejkernel/ops/registry.py +93 -0
  169. ejkernel/ops/utils/__init__.py +72 -0
  170. ejkernel/ops/utils/datacarrier.py +126 -0
  171. ejkernel/ops/utils/fingerprint.py +342 -0
  172. ejkernel/ops/utils/meta.py +156 -0
  173. ejkernel/ops/utils/serialize.py +97 -0
  174. ejkernel/types/__init__.py +18 -0
  175. ejkernel/types/mask.py +1787 -0
  176. ejkernel/utils.py +677 -0
  177. ejkernel/xla_utils/__init__.py +45 -0
  178. ejkernel/xla_utils/cumsum.py +297 -0
  179. ejkernel/xla_utils/shardings.py +102 -0
  180. ejkernel/xla_utils/utils.py +184 -0
  181. ejkernel-0.0.1.dist-info/METADATA +607 -0
  182. ejkernel-0.0.1.dist-info/RECORD +183 -0
  183. ejkernel-0.0.1.dist-info/WHEEL +4 -0
ejkernel/__init__.py ADDED
@@ -0,0 +1,51 @@
1
+ # Copyright 2025 The EasyDeL/ejKernel Author @erfanzar (Erfan Zare Chavoshi).
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # https://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ """ejKernel: High-performance kernel library for JAX.
17
+
18
+ This module provides a comprehensive collection of optimized kernels for various
19
+ deep learning operations, with support for multiple backends (XLA, Triton, Pallas)
20
+ and platforms (TPU, GPU). The library focuses on efficient attention mechanisms,
21
+ matrix operations, and other performance-critical computations.
22
+
23
+ Key Features:
24
+ - Multi-backend support (XLA, Triton, Pallas) for optimal performance
25
+ - Platform-specific optimizations for TPU and GPU
26
+ - Extensive collection of attention mechanisms (Flash, Sparse, Ring, etc.)
27
+ - Automatic kernel selection and registration
28
+ - Modular architecture for easy extension
29
+
30
+ Example:
31
+ >>> import ejkernel
32
+ >>> from ejkernel import Backend, Platform
33
+ >>>
34
+ >>> kernel = ejkernel.kernel_registry.get_kernel(
35
+ ... name="flash_attention",
36
+ ... backend=Backend.TRITON,
37
+ ... platform=Platform.GPU
38
+ ... )
39
+ """
40
+
41
+ import os as _os
42
+
43
+ _os.environ["TF_GPU_ALLOCATOR"] = "cuda_malloc_async"
44
+ __version__ = "0.0.1"
45
+
46
+ from . import kernels, modules, types
47
+ from .kernels import Backend, Platform, kernel_registry
48
+
49
+ kernel_registry.validate_signatures(None)
50
+
51
+ __all__ = ("Backend", "Platform", "kernel_registry", "kernels", "modules", "types")