kilat 2.0.0__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 (131) hide show
  1. kilat-2.0.0/LICENSE +201 -0
  2. kilat-2.0.0/PKG-INFO +368 -0
  3. kilat-2.0.0/README.md +310 -0
  4. kilat-2.0.0/pyproject.toml +184 -0
  5. kilat-2.0.0/setup.cfg +4 -0
  6. kilat-2.0.0/src/kilat/__init__.py +39 -0
  7. kilat-2.0.0/src/kilat/assurance/__init__.py +67 -0
  8. kilat-2.0.0/src/kilat/assurance/chaos/__init__.py +30 -0
  9. kilat-2.0.0/src/kilat/assurance/chaos/hf_scenarios.py +438 -0
  10. kilat-2.0.0/src/kilat/assurance/chaos/saboteur.py +358 -0
  11. kilat-2.0.0/src/kilat/assurance/chaos/scenarios.py +443 -0
  12. kilat-2.0.0/src/kilat/assurance/flight_recorder.py +367 -0
  13. kilat-2.0.0/src/kilat/assurance/gates/__init__.py +19 -0
  14. kilat-2.0.0/src/kilat/assurance/gates/gate0_security.py +249 -0
  15. kilat-2.0.0/src/kilat/assurance/gates/gate1_theory.py +209 -0
  16. kilat-2.0.0/src/kilat/assurance/gates/gate2_numerical.py +355 -0
  17. kilat-2.0.0/src/kilat/assurance/gates/gate3_equivalence.py +261 -0
  18. kilat-2.0.0/src/kilat/assurance/gates/gate4_data.py +253 -0
  19. kilat-2.0.0/src/kilat/assurance/gates/gate5_dynamics.py +272 -0
  20. kilat-2.0.0/src/kilat/assurance/gates/gate6_system.py +329 -0
  21. kilat-2.0.0/src/kilat/assurance/project_rules.py +112 -0
  22. kilat-2.0.0/src/kilat/assurance/quality.py +231 -0
  23. kilat-2.0.0/src/kilat/assurance/runner.py +238 -0
  24. kilat-2.0.0/src/kilat/assurance/scaling.py +215 -0
  25. kilat-2.0.0/src/kilat/assurance/types.py +193 -0
  26. kilat-2.0.0/src/kilat/benchmarking/__init__.py +17 -0
  27. kilat-2.0.0/src/kilat/benchmarking/__main__.py +12 -0
  28. kilat-2.0.0/src/kilat/benchmarking/arms.py +135 -0
  29. kilat-2.0.0/src/kilat/benchmarking/benchmark_config.py +284 -0
  30. kilat-2.0.0/src/kilat/benchmarking/benchmark_runner.py +248 -0
  31. kilat-2.0.0/src/kilat/benchmarking/component_numerics.py +125 -0
  32. kilat-2.0.0/src/kilat/benchmarking/harness.py +102 -0
  33. kilat-2.0.0/src/kilat/benchmarking/loss_ablation.py +162 -0
  34. kilat-2.0.0/src/kilat/benchmarking/mqar_benchmark.py +248 -0
  35. kilat-2.0.0/src/kilat/benchmarking/pillars/__init__.py +19 -0
  36. kilat-2.0.0/src/kilat/benchmarking/pillars/p1_correctness.py +189 -0
  37. kilat-2.0.0/src/kilat/benchmarking/pillars/p2_capability.py +228 -0
  38. kilat-2.0.0/src/kilat/benchmarking/pillars/p3_scaling.py +269 -0
  39. kilat-2.0.0/src/kilat/benchmarking/pillars/p4_efficiency.py +175 -0
  40. kilat-2.0.0/src/kilat/benchmarking/pillars/p5_diagnostics.py +342 -0
  41. kilat-2.0.0/src/kilat/benchmarking/plots.py +101 -0
  42. kilat-2.0.0/src/kilat/benchmarking/protocol.py +101 -0
  43. kilat-2.0.0/src/kilat/benchmarking/recipe.py +41 -0
  44. kilat-2.0.0/src/kilat/benchmarking/registry.py +244 -0
  45. kilat-2.0.0/src/kilat/benchmarking/reporter.py +192 -0
  46. kilat-2.0.0/src/kilat/benchmarking/results.py +107 -0
  47. kilat-2.0.0/src/kilat/benchmarking/stability.py +72 -0
  48. kilat-2.0.0/src/kilat/benchmarking/tasks/__init__.py +13 -0
  49. kilat-2.0.0/src/kilat/benchmarking/tasks/induction_heads.py +130 -0
  50. kilat-2.0.0/src/kilat/benchmarking/tasks/mqar.py +162 -0
  51. kilat-2.0.0/src/kilat/benchmarking/tasks/selective_copying.py +125 -0
  52. kilat-2.0.0/src/kilat/benchmarking/time_to_quality.py +145 -0
  53. kilat-2.0.0/src/kilat/cli.py +782 -0
  54. kilat-2.0.0/src/kilat/configs/__init__.py +19 -0
  55. kilat-2.0.0/src/kilat/configs/base.py +99 -0
  56. kilat-2.0.0/src/kilat/configs/dataloader_config.py +332 -0
  57. kilat-2.0.0/src/kilat/configs/main_config.py +855 -0
  58. kilat-2.0.0/src/kilat/configs/model_config.py +579 -0
  59. kilat-2.0.0/src/kilat/configs/tokenizer_config.py +726 -0
  60. kilat-2.0.0/src/kilat/configs/training_config.py +473 -0
  61. kilat-2.0.0/src/kilat/data/__init__.py +47 -0
  62. kilat-2.0.0/src/kilat/data/collator.py +145 -0
  63. kilat-2.0.0/src/kilat/data/dataloader.py +508 -0
  64. kilat-2.0.0/src/kilat/data/dataset.py +1210 -0
  65. kilat-2.0.0/src/kilat/data/preprocess.py +620 -0
  66. kilat-2.0.0/src/kilat/data/sft.py +277 -0
  67. kilat-2.0.0/src/kilat/data/tokenizer.py +677 -0
  68. kilat-2.0.0/src/kilat/distillation/__init__.py +25 -0
  69. kilat-2.0.0/src/kilat/distillation/losses.py +317 -0
  70. kilat-2.0.0/src/kilat/distillation/student.py +70 -0
  71. kilat-2.0.0/src/kilat/distillation/teacher.py +71 -0
  72. kilat-2.0.0/src/kilat/engine/__init__.py +157 -0
  73. kilat-2.0.0/src/kilat/engine/args.py +352 -0
  74. kilat-2.0.0/src/kilat/engine/callbacks.py +550 -0
  75. kilat-2.0.0/src/kilat/engine/checkpoint.py +1049 -0
  76. kilat-2.0.0/src/kilat/engine/distributed.py +131 -0
  77. kilat-2.0.0/src/kilat/engine/integrations.py +1089 -0
  78. kilat-2.0.0/src/kilat/engine/memory.py +386 -0
  79. kilat-2.0.0/src/kilat/engine/optimizer.py +322 -0
  80. kilat-2.0.0/src/kilat/engine/relay.py +290 -0
  81. kilat-2.0.0/src/kilat/engine/scheduler.py +931 -0
  82. kilat-2.0.0/src/kilat/engine/sft_trainer.py +149 -0
  83. kilat-2.0.0/src/kilat/engine/trainer.py +1395 -0
  84. kilat-2.0.0/src/kilat/inference/__init__.py +143 -0
  85. kilat-2.0.0/src/kilat/inference/beam_search.py +599 -0
  86. kilat-2.0.0/src/kilat/inference/export_hf.py +814 -0
  87. kilat-2.0.0/src/kilat/inference/generation_config.py +371 -0
  88. kilat-2.0.0/src/kilat/inference/generation_mixin.py +687 -0
  89. kilat-2.0.0/src/kilat/inference/generator.py +470 -0
  90. kilat-2.0.0/src/kilat/inference/logit_processor.py +869 -0
  91. kilat-2.0.0/src/kilat/inference/sampler.py +1032 -0
  92. kilat-2.0.0/src/kilat/inference/stopping_criteria.py +900 -0
  93. kilat-2.0.0/src/kilat/inference/templates/modeling_kilat_hub.py +1491 -0
  94. kilat-2.0.0/src/kilat/integrations/__init__.py +11 -0
  95. kilat-2.0.0/src/kilat/integrations/huggingface/__init__.py +72 -0
  96. kilat-2.0.0/src/kilat/integrations/huggingface/configuration_kilat.py +167 -0
  97. kilat-2.0.0/src/kilat/integrations/huggingface/data.py +118 -0
  98. kilat-2.0.0/src/kilat/integrations/huggingface/modeling_kilat.py +65 -0
  99. kilat-2.0.0/src/kilat/integrations/huggingface/peft.py +111 -0
  100. kilat-2.0.0/src/kilat/integrations/huggingface/trl.py +190 -0
  101. kilat-2.0.0/src/kilat/integrations/serving/__init__.py +24 -0
  102. kilat-2.0.0/src/kilat/integrations/serving/openai_server.py +204 -0
  103. kilat-2.0.0/src/kilat/integrations/serving/schemas.py +109 -0
  104. kilat-2.0.0/src/kilat/models/__init__.py +55 -0
  105. kilat-2.0.0/src/kilat/models/attention.py +592 -0
  106. kilat-2.0.0/src/kilat/models/base.py +1165 -0
  107. kilat-2.0.0/src/kilat/models/blocks.py +343 -0
  108. kilat-2.0.0/src/kilat/models/decay.py +214 -0
  109. kilat-2.0.0/src/kilat/models/ffn.py +674 -0
  110. kilat-2.0.0/src/kilat/models/kernels/__init__.py +45 -0
  111. kilat-2.0.0/src/kilat/models/kernels/chunked_ce.py +550 -0
  112. kilat-2.0.0/src/kilat/models/kernels/flash_decay.py +1121 -0
  113. kilat-2.0.0/src/kilat/models/kernels/flash_mla.py +799 -0
  114. kilat-2.0.0/src/kilat/models/kernels/swiglu.py +231 -0
  115. kilat-2.0.0/src/kilat/models/loading.py +87 -0
  116. kilat-2.0.0/src/kilat/models/mla.py +378 -0
  117. kilat-2.0.0/src/kilat/models/norm.py +54 -0
  118. kilat-2.0.0/src/kilat/models/rope.py +493 -0
  119. kilat-2.0.0/src/kilat/models/transformer.py +892 -0
  120. kilat-2.0.0/src/kilat/utils/__init__.py +70 -0
  121. kilat-2.0.0/src/kilat/utils/banner.py +38 -0
  122. kilat-2.0.0/src/kilat/utils/base_model.py +34 -0
  123. kilat-2.0.0/src/kilat/utils/report.py +111 -0
  124. kilat-2.0.0/src/kilat/utils/security.py +138 -0
  125. kilat-2.0.0/src/kilat/utils/validators.py +451 -0
  126. kilat-2.0.0/src/kilat.egg-info/PKG-INFO +368 -0
  127. kilat-2.0.0/src/kilat.egg-info/SOURCES.txt +129 -0
  128. kilat-2.0.0/src/kilat.egg-info/dependency_links.txt +1 -0
  129. kilat-2.0.0/src/kilat.egg-info/entry_points.txt +2 -0
  130. kilat-2.0.0/src/kilat.egg-info/requires.txt +47 -0
  131. kilat-2.0.0/src/kilat.egg-info/top_level.txt +1 -0
kilat-2.0.0/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 Abdul Wahid Rukua
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
kilat-2.0.0/PKG-INFO ADDED
@@ -0,0 +1,368 @@
1
+ Metadata-Version: 2.4
2
+ Name: kilat
3
+ Version: 2.0.0
4
+ Summary: Kilat: kernelized lightweight attention.
5
+ Author-email: Abdul Wahid Rukua <rukuaabdulwahid@gmail.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/Airukua/Kilat
8
+ Project-URL: Repository, https://github.com/Airukua/Kilat
9
+ Project-URL: Issues, https://github.com/Airukua/Kilat/issues
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Requires-Python: >=3.10
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: torch>=2.0
18
+ Requires-Dist: transformers>=4.40
19
+ Requires-Dist: tqdm>=4.66
20
+ Requires-Dist: pyarrow>=14.0
21
+ Requires-Dist: triton>=2.0; sys_platform == "linux"
22
+ Requires-Dist: sentencepiece>=0.2.0
23
+ Requires-Dist: numpy>=1.24
24
+ Requires-Dist: pyyaml>=6.0
25
+ Requires-Dist: huggingface_hub>=0.23.0
26
+ Requires-Dist: filelock>=4.3.0
27
+ Provides-Extra: reporting
28
+ Requires-Dist: wandb>=0.16; extra == "reporting"
29
+ Requires-Dist: tensorboard>=2.14; extra == "reporting"
30
+ Requires-Dist: mlflow>=2.10; extra == "reporting"
31
+ Requires-Dist: comet_ml>=3.45; extra == "reporting"
32
+ Provides-Extra: serving
33
+ Requires-Dist: fastapi>=0.100.0; extra == "serving"
34
+ Requires-Dist: uvicorn>=0.23.0; extra == "serving"
35
+ Requires-Dist: httpx>=0.24.0; extra == "serving"
36
+ Requires-Dist: pydantic>=2.0; extra == "serving"
37
+ Provides-Extra: benchmark
38
+ Requires-Dist: pandas>=2.0; extra == "benchmark"
39
+ Requires-Dist: matplotlib>=3.7; extra == "benchmark"
40
+ Requires-Dist: huggingface_hub>=0.23.0; extra == "benchmark"
41
+ Provides-Extra: integrations
42
+ Requires-Dist: peft>=0.10.0; extra == "integrations"
43
+ Requires-Dist: trl>=0.8.0; extra == "integrations"
44
+ Requires-Dist: fastapi>=0.100.0; extra == "integrations"
45
+ Requires-Dist: uvicorn>=0.23.0; extra == "integrations"
46
+ Requires-Dist: httpx>=0.24.0; extra == "integrations"
47
+ Requires-Dist: pydantic>=2.0; extra == "integrations"
48
+ Provides-Extra: dev
49
+ Requires-Dist: ruff>=0.4.0; extra == "dev"
50
+ Requires-Dist: mypy>=1.10.0; extra == "dev"
51
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
52
+ Requires-Dist: pre-commit>=3.5.0; extra == "dev"
53
+ Requires-Dist: types-PyYAML>=6.0; extra == "dev"
54
+ Requires-Dist: types-tqdm>=4.66; extra == "dev"
55
+ Requires-Dist: pip-audit>=2.7; extra == "dev"
56
+ Requires-Dist: setuptools>=84.1.0; extra == "dev"
57
+ Dynamic: license-file
58
+
59
+ <div align="center">
60
+
61
+ # โšก Kilat
62
+
63
+ **A lightweight framework for training sub-quadratic language models on a single GPU**
64
+
65
+ *Kilat* (Indonesian: *lightning*) pre-trains, fine-tunes and exports small hybrid LLMs that mix
66
+ linear-time decay layers with compressed attention, so long context and training fit on one GPU or a free Colab.
67
+
68
+ [![Hugging Face: 150M-Kilat-SMALL-10B](https://img.shields.io/badge/๐Ÿค—%20HuggingFace-150M--Kilat--SMALL--10B-FFD21E?style=flat-square)](https://huggingface.co/AiRukua/150M-Kilat-SMALL-10B)
69
+ [![Python 3.10+](https://img.shields.io/badge/python-3.10%2B-blue?style=flat-square)](https://www.python.org/downloads/)
70
+ [![PyTorch 2.0+](https://img.shields.io/badge/PyTorch-2.0%2B-EE4C2C?style=flat-square&logo=pytorch&logoColor=white)](https://pytorch.org/)
71
+ [![Assurance & Chaos](https://img.shields.io/badge/Assurance-16%20Chaos%20Gates%20Passed-brightgreen?style=flat-square)](#-how-kilat-catches-silent-training-bugs)
72
+ [![License: Apache 2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg?style=flat-square)](LICENSE)
73
+
74
+ <p align="center">
75
+ <img src="https://raw.githubusercontent.com/Airukua/Kilat/main/images/illustration.png" alt="Kilat illustration" width="720" />
76
+ </p>
77
+
78
+ </div>
79
+
80
+ ---
81
+
82
+ ## Contents
83
+
84
+ 1. [Kilat in one minute](#-kilat-in-one-minute)
85
+ 2. [Install](#-install)
86
+ 3. [Try the released model](#-try-the-released-model)
87
+ 4. [How the architecture saves memory](#-how-the-architecture-saves-memory)
88
+ 5. [Measured results](#-measured-results)
89
+ 6. [Train your own](#-train-your-own)
90
+ 7. [How Kilat catches silent training bugs](#-how-kilat-catches-silent-training-bugs)
91
+ 8. [Project status](#-project-status)
92
+ 9. [Repository map](#-repository-map)
93
+
94
+ ---
95
+
96
+ ## โšก Kilat in one minute
97
+
98
+ - **What it is**: a PyTorch library + CLI (`kilat train`, `kilat sft`, `kilat export-hf`, `kilat verify`) for
99
+ small language models built from three parts: **Global Exponential Decay** layers (constant-size state,
100
+ no KV cache growth), **Latent MLA** attention (compressed KV cache) and optional **DeepSeekMoE** feed-forward.
101
+ - **Why you might care**: the 150M model trains at roughly 2.5ร— the throughput of an equally sized HF Llama-3
102
+ with about a third of the peak VRAM on the same GPU (see [Measured results](#-measured-results)), and its
103
+ inference cache is about 12ร— smaller than a standard MHA transformer.
104
+ - **What exists today**: a released 150M base model trained on 10B tokens, notebooks to train your own, export
105
+ to Hugging Face `AutoModelForCausalLM`, and a test/assurance suite that guards against silent training bugs.
106
+
107
+ ---
108
+
109
+ ## ๐Ÿ“ฆ Install
110
+
111
+ Install the `kilat` package first to use the Python API (`kilat.models`, `kilat.engine`) and CLI (`kilat train`, `kilat profile`, `kilat sft`, `kilat export-hf`, `kilat verify`):
112
+
113
+ ```bash
114
+ pip install git+https://github.com/Airukua/Kilat.git
115
+ ```
116
+
117
+ Or for local development (Python 3.10+, PyTorch 2.0+; CUDA enables the Triton kernels):
118
+
119
+ ```bash
120
+ git clone https://github.com/Airukua/Kilat.git
121
+ cd Kilat
122
+ pip install -e ".[dev]"
123
+ ```
124
+
125
+ ---
126
+
127
+ ## ๐Ÿ’ป Try the released model
128
+
129
+ [**`AiRukua/150M-Kilat-SMALL-10B`**](https://huggingface.co/AiRukua/150M-Kilat-SMALL-10B): 151.5M parameters
130
+ (66.5M active per token), 12 layers, width 384, 8 routed experts (top-2) + 1 shared, trained from scratch on
131
+ 10B tokens of [FineWeb-Edu](https://huggingface.co/datasets/HuggingFaceFW/fineweb-edu), 2,048-token context,
132
+ Apache 2.0.
133
+
134
+ To run inference directly from Hugging Face without installing `kilat` (model code is bundled in the Hub repo):
135
+
136
+ ```bash
137
+ pip install torch transformers accelerate huggingface_hub
138
+ ```
139
+
140
+ > โš ๏ธ This is a **base model**, not a chat assistant: it continues factual, educational text. Small base models
141
+ > loop without repetition control, so use the sampling settings below.
142
+
143
+ ```python
144
+ import torch
145
+ from transformers import AutoModelForCausalLM, AutoTokenizer
146
+
147
+ model_id = "AiRukua/150M-Kilat-SMALL-10B"
148
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True)
149
+ model = AutoModelForCausalLM.from_pretrained(
150
+ model_id,
151
+ trust_remote_code=True,
152
+ dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
153
+ device_map="auto" if torch.cuda.is_available() else None,
154
+ )
155
+
156
+ inputs = tokenizer("Photosynthesis is the process by which green plants", return_tensors="pt").to(model.device)
157
+ outputs = model.generate(
158
+ **inputs, max_new_tokens=60, do_sample=True, temperature=0.75, top_p=0.92, top_k=50,
159
+ repetition_penalty=1.18, no_repeat_ngram_size=3, use_cache=True,
160
+ )
161
+ print(tokenizer.decode(outputs[0], skip_special_tokens=True))
162
+ ```
163
+
164
+ Example output:
165
+ > *"Photosynthesis is the process by which green plants convert sunlight into energy. The plant can use this
166
+ > energy to produce food, especially carbohydrates, as well as photosynthesis. However, while there are many
167
+ > other methods for converting light energy into chemical energy..."*
168
+
169
+ `trust_remote_code=True` runs the Kilat model code shipped in the Hub repository; read it there first if your
170
+ environment requires that.
171
+
172
+ ---
173
+
174
+ ## ๐Ÿง  How the architecture saves memory
175
+
176
+ Each attention layer splits its heads between two mechanisms (`model.recall_ratio` = share of MLA heads):
177
+
178
+ | Part | What it does | Memory at inference |
179
+ | :--- | :--- | :--- |
180
+ | **Global Exponential Decay** | Linear-time recurrent scan over the sequence | Constant state per layer, independent of length |
181
+ | **Latent MLA** (decoupled RoPE) | Exact attention over a low-rank joint K/V latent (`latent_dim=96`, `rope_head_dim=32`) | Grows with length, ~6ร— smaller per layer than MHA |
182
+ | **DeepSeekMoE** (optional) | 8 routed experts (top-2) + 1 shared, loss-free bias balancing | 151.5M capacity, ~66.5M parameters computed per token |
183
+
184
+ How heads are placed across layers is the **recall pattern**: `macro_synergy` alternates whole Decay and MLA
185
+ layers (the released model), `uniform` splits every layer 50/50, `custom` sets a ratio per layer. Which layout
186
+ is best is an open question under study in [`benchmarking/`](benchmarking/README.md).
187
+
188
+ | 150M config (`L=12, D=384, H=6`, BF16, batch 1) | Standard MHA | Kilat (macro_synergy) |
189
+ | :--- | :---: | :---: |
190
+ | KV cache at 2,048 tokens | 36.00 MB | **3.01 MB** (9 KB decay + 3.00 MB MLA), 12ร— smaller |
191
+ | KV cache at 8,192 tokens | 144.00 MB | **12.01 MB**, 12ร— smaller (4ร— vs 3:1 GQA) |
192
+ | Associative recall (MQAR, micro certification) | high | **99.76%**, where pure decay stagnates |
193
+
194
+ ---
195
+
196
+ ## ๐Ÿ“Š Measured results
197
+
198
+ End-to-end training step (forward + backward + fused AdamW), NVIDIA RTX PRO 6000 Blackwell 96 GB, BF16,
199
+ `N=2048, B=16`:
200
+
201
+ | Model | Total / active params | Throughput | MFU (BF16 dense) | Peak VRAM |
202
+ | :--- | :---: | :---: | :---: | :---: |
203
+ | HF Llama-3 (SDPA) | 114.1M / 114.1M | ~113k tok/s | ~15.4% | ~41.0 GB |
204
+ | HF Qwen2 (SDPA) | 114.1M / 114.1M | ~112k tok/s | ~15.2% | ~41.0 GB |
205
+ | HF Mistral (SWA) | 114.1M / 114.1M | ~91k tok/s | ~12.4% | ~43.5 GB |
206
+ | HF GPT-2 | 126.8M / 126.8M | ~86k tok/s | ~13.0% | ~51.0 GB |
207
+ | HF Mixtral (2/8 MoE) | 137.3M / 52.4M | ~130k tok/s | ~8.1% | ~44.6 GB |
208
+ | **Kilat Dense** (macro_synergy, chunked CE) | **114.0M / 114.0M** | **~255k tok/s** | **~34.6%** | **~12.5 GB** |
209
+ | **Kilat MoE** (2/8 + 1 shared) | **151.5M / 66.5M** | **~291k tok/s** | **~23.1%** | **~14.8 GB** |
210
+
211
+ <p align="center">
212
+ <img src="https://raw.githubusercontent.com/Airukua/Kilat/main/images/kilat_vs_hf_blackwell_suite1.png" alt="Kilat vs Hugging Face, Suite 1 on RTX PRO 6000 Blackwell (BF16)" width="820" />
213
+ </p>
214
+
215
+ At `N=4096, B=8`, Kilat MoE runs at ~275k tok/s in ~15 GB, against HF Mixtral ~127k tok/s in ~45 GB and HF
216
+ Llama-3 ~108k tok/s in ~41 GB.
217
+
218
+ <p align="center">
219
+ <img src="https://raw.githubusercontent.com/Airukua/Kilat/main/images/kilat_vs_hf_blackwell_suite3.jpg" alt="Kilat vs Hugging Face, context scaling on RTX PRO 6000 Blackwell (BF16)" width="820" />
220
+ </p>
221
+
222
+ Where the savings come from: single-pass chunked linear cross-entropy (no full logits tensor), the Triton
223
+ chunked decay scan, the compressed MLA cache and fused 3D MoE experts. No gradient checkpointing is used.
224
+
225
+ > **Method and source.** MFU = 6 ร— active params ร— tok/s รท 503.8 TFLOPS (Blackwell dense BF16 peak, FP32
226
+ > accumulate; tied `lm_head` counted once, quadratic attention FLOPs excluded). `~` values are read from the
227
+ > charts. These numbers come from the benchmark notebook as of commit `8cb9ce1`
228
+ > ([Marimo](https://github.com/Airukua/Kilat/blob/8cb9ce1eb1cac0fbb881235f92216191b46a9ca6/notebooks/kilat_vs_hf_benchmark_marimo.py),
229
+ > [Colab](https://github.com/Airukua/Kilat/blob/8cb9ce1eb1cac0fbb881235f92216191b46a9ca6/notebooks/kilat_vs_hf_benchmark_colab.ipynb)).
230
+ > The current, config-driven benchmark against GPT-2, Llama 3 and Mixtral (time-to-quality on FineWeb-Edu
231
+ > with a shared tokenizer, CE agreement, memory scaling) lives in [`benchmarking/`](benchmarking/README.md).
232
+
233
+ ---
234
+
235
+ ## ๐Ÿ‹๏ธ Train your own
236
+
237
+ ### Notebooks (no local GPU needed)
238
+
239
+ | Notebook | What you get | Open |
240
+ | :--- | :--- | :---: |
241
+ | **150M MoE relay pre-training** | 150M MoE on FineWeb-Edu 100B, 12 h molab sessions resumed from a private HF checkpoint repo | [Marimo / molab](notebooks/pretraining/kilat_moe_150m_relay_marimo.py) |
242
+ | **500M MoE relay pre-training** | Same scheme, 500M MoE on 30B/60B tokens | [Marimo / molab](notebooks/kilat_moe_500m_relay_marimo.py) |
243
+ | **General pre-training** | Small dense or hybrid model from scratch, assurance gates, Hub export | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Airukua/Kilat/blob/main/notebooks/pretraining/kilat_general_pretraining_colab.ipynb) |
244
+ | **SFT** | Instruction tuning with prompt-masked loss | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Airukua/Kilat/blob/main/notebooks/post_training/kilat_sft_colab.ipynb) |
245
+ | **PEFT LoRA** | LoRA adapters with `peft`, merged back with `merge_and_unload()` | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/Airukua/Kilat/blob/main/notebooks/post_training/kilat_peft_lora_example.ipynb) |
246
+ | **150M SFT + DPO** | Turns the 150M base model into the instruct model | [Marimo / molab](notebooks/kilat_150m_sft_dpo_marimo.py) |
247
+
248
+ More detail per notebook: [`notebooks/README.md`](notebooks/README.md).
249
+
250
+ ### CLI quickstart
251
+
252
+ ```bash
253
+ # Check the setup on CPU in seconds (synthetic data, tiny model)
254
+ kilat verify --config configs/debug_cpu.yaml --full
255
+
256
+ # Profile VRAM and auto-pick the fastest micro-batch + selective recompute on your GPU
257
+ kilat profile --config configs/small_moe.yaml --optimize
258
+
259
+ # Pre-train from a preset; any config field can be overridden with --set
260
+ kilat train --config configs/small_moe.yaml \
261
+ --set training.max_steps=10000 \
262
+ --set training.output_dir=./checkpoints/my_moe_model
263
+
264
+ # Instruction-tune (Alpaca, ChatML or JSONL)
265
+ kilat sft --model ./checkpoints/my_moe_model/checkpoint-best --data ./my_instructions.jsonl \
266
+ --output-dir ./checkpoints/my_sft_model --epochs 3 --batch-size 4 --lr 3e-5
267
+
268
+ # Export to Hugging Face format (model.safetensors + remote code + generation_config.json)
269
+ kilat export-hf --checkpoint ./checkpoints/my_moe_model/checkpoint-best --output ./checkpoints/my_moe_model_hf
270
+ ```
271
+
272
+ Presets and the meaning of each config field: [`configs/README.md`](configs/README.md).
273
+
274
+ ---
275
+
276
+ ## ๐Ÿ›ก๏ธ How Kilat catches silent training bugs
277
+
278
+ A training run can finish without errors and still be wrong: detached gradients, future-token leaks, lost
279
+ optimizer state, broken RNG on resume. Kilat ships checks for these:
280
+
281
+ ```bash
282
+ kilat verify --config configs/small_moe.yaml # pre-flight gates: theory, gradients, equivalence, resumption
283
+ kilat chaos -s all # inject training faults C-01..C-08 and confirm they are caught
284
+ kilat chaos -s hf # Hugging Face integration faults HFC-01..HFC-08
285
+ ```
286
+
287
+ - **C-01..C-08**: silent autograd detachment, causal future leak, cross-batch reshape, FP16 overflow storm,
288
+ decay horizon singularity, MoE router collapse, poisoned batch, preemption during checkpoint save.
289
+ - **HFC-01..HFC-08**: foreign `DynamicCache` injection, config schema drift, adversarial sampling parameters,
290
+ asymmetric left padding, PEFT LoRA gradient isolation, streaming cancellation across threads.
291
+
292
+ Checkpoints are written atomically with a SHA-256 manifest and full RNG state; untrusted artefacts are loaded
293
+ with `torch.load(weights_only=True)` only (see [`SECURITY.md`](SECURITY.md)).
294
+
295
+ ---
296
+
297
+ ## ๐Ÿงญ Project status
298
+
299
+ | Item | Status |
300
+ | :--- | :--- |
301
+ | 150M base model, 10B tokens | Released on the Hub |
302
+ | 150M instruct model (SFT + DPO) | Recipe in `notebooks/kilat_150m_sft_dpo_marimo.py` |
303
+ | 500M MoE, 60B tokens | Pre-training in progress (relay) |
304
+ | 150M MoE, 100B tokens | Notebook and config ready |
305
+ | Layer layout study (macro vs micro mixing, MLA share) | Ongoing, [`benchmarking/`](benchmarking/README.md) |
306
+ | INT8 / INT4 quantization | Not implemented |
307
+
308
+ ---
309
+
310
+ ## ๐Ÿ“ Repository map
311
+
312
+ ```text
313
+ Kilat/
314
+ โ”œโ”€โ”€ src/kilat/
315
+ โ”‚ โ”œโ”€โ”€ cli.py # kilat train | sft | generate | export-hf | verify | chaos
316
+ โ”‚ โ”œโ”€โ”€ models/ # KilatTransformer: Global Decay, Latent MLA, DeepSeekMoE, Triton kernels
317
+ โ”‚ โ”œโ”€โ”€ engine/ # Trainer, SFT trainer, optimizer, atomic checkpoints, relay sessions
318
+ โ”‚ โ”œโ”€โ”€ data/ # Datasets, collator, tokenizer, memmap / llm.c .bin loaders
319
+ โ”‚ โ”œโ”€โ”€ inference/ # Generation, hybrid cache, Hugging Face export and Hub templates
320
+ โ”‚ โ”œโ”€โ”€ integrations/ # Hugging Face AutoModel, PEFT LoRA, TRL, OpenAI-compatible serving
321
+ โ”‚ โ”œโ”€โ”€ assurance/ # Pre-flight gates and chaos saboteur
322
+ โ”‚ โ”œโ”€โ”€ benchmarking/ # Benchmark phases used by benchmarking/ notebooks
323
+ โ”‚ โ””โ”€โ”€ distillation/ # Knowledge distillation losses
324
+ โ”œโ”€โ”€ configs/ # Training presets; benchmark/ and certification/ configs
325
+ โ”œโ”€โ”€ notebooks/ # pretraining/, post_training/ (see notebooks/README.md)
326
+ โ”œโ”€โ”€ benchmarking/ # Benchmark and ablation notebooks (molab, Colab)
327
+ โ”œโ”€โ”€ tests/ # ~380 unit, invariant, integration and chaos tests
328
+ โ”œโ”€โ”€ docs/ # Math spec, architecture and assurance plans, model cards
329
+ โ””โ”€โ”€ tools/ # Maintenance scripts
330
+ ```
331
+
332
+ ---
333
+
334
+ ## ๐Ÿค Contributing & Community
335
+
336
+ Contributions are very welcome! Whether you are implementing new attention kernels, optimizing memory efficiency, improving documentation, or adding chaos scenarios:
337
+
338
+ - Please read our [**Contributing Guide**](CONTRIBUTING.md) to understand our 5 Golden Invariants, code standards, and verification workflow.
339
+ - All participants must adhere to our [**Code of Conduct**](CODE_OF_CONDUCT.md).
340
+
341
+ ---
342
+
343
+ ## ๐Ÿ“„ License & Citation
344
+
345
+ Kilat is licensed under the **Apache 2.0 License**. See [LICENSE](LICENSE) for details.
346
+
347
+ > Kilat is built to be shared. Anyone is welcome to use, study, modify, and build upon it, including for commercial purposes. You don't owe me payment for using my work, but please respect the effort behind it. Preserve the original attribution, acknowledge the project, and never claim someone else's work as your own.
348
+
349
+ ```bibtex
350
+ @misc{kilat2026,
351
+ author = {Abdul Wahid Rukua},
352
+ title = {Kilat: Kernelized Lightweight Attention Transformer with Hybrid Macro-Synergy and Sparse MoE},
353
+ year = {2026},
354
+ publisher = {GitHub},
355
+ howpublished = {\url{https://github.com/Airukua/Kilat}}
356
+ }
357
+ ```
358
+
359
+ ---
360
+
361
+ ## ๐Ÿ‘ค Author & Community
362
+
363
+ **Abdul Wahid Rukua** โ€” AI/ML Engineer
364
+ *Focus: Efficient Sequence Modeling, Lightweight LLMs, and Sub-Quadratic Architectures.*
365
+
366
+ [![Hugging Face](https://img.shields.io/badge/๐Ÿค—%20HuggingFace-AiRukua-FFD21E?style=flat-square)](https://huggingface.co/AiRukua)
367
+ [![LinkedIn](https://img.shields.io/badge/LinkedIn-abdul--wahid--rukua-0A66C2?style=flat-square&logo=linkedin&logoColor=white)](https://www.linkedin.com/in/abdul-wahid-rukua/)
368
+ [![GitHub](https://img.shields.io/badge/GitHub-Airukua-181717?style=flat-square&logo=github)](https://github.com/Airukua)