rxnn 0.1.0__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.
@@ -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
+ 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 owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the 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 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 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
+ 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 , 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 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 2024-2025 Adam Filipek
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.
@@ -0,0 +1,257 @@
1
+ Metadata-Version: 2.3
2
+ Name: rxnn
3
+ Version: 0.1.0
4
+ Summary: RxNN: Reactive Neural Networks Platform
5
+ License: Apache-2.0
6
+ Keywords: deep-learning,ai,machine-learning
7
+ Author: Adam Filipek
8
+ Author-email: adamfilipek@rxai.dev
9
+ Requires-Python: >=3.10
10
+ Classifier: License :: OSI Approved :: Apache Software License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Requires-Dist: datasets (>=3.5.0,<4.0.0)
17
+ Requires-Dist: flash-attention (>=1.0.0,<2.0.0)
18
+ Requires-Dist: huggingface-hub (>=0.30.0,<0.31.0)
19
+ Requires-Dist: tensorboard (>=2.19.0,<3.0.0)
20
+ Requires-Dist: tokenizers (>=0.21.0,<0.22.0)
21
+ Requires-Dist: torch (>=2.6.0,<3.0.0)
22
+ Requires-Dist: transformers (>=4.51.0,<5.0.0)
23
+ Project-URL: Homepage, https://rxai.dev/rxnn
24
+ Project-URL: Repository, https://github.com/RxAI-dev/rxnn/python
25
+ Description-Content-Type: text/markdown
26
+
27
+ <img src="logo_rxai.webp" width="300" />
28
+ <img src="logo_rxnn.webp" width="300" />
29
+
30
+ # Reactive AI - RxNN
31
+ ## Reactive Neural Networks Platform
32
+
33
+ RxNN is AI/DeepLearning development platform made for Reactive Neural Networks and Event-driven AI, introduced by Reactive AI.
34
+
35
+ ## Reactive Neural Networks and Event-driven AI
36
+ Reactive neural networks (RxNN) are a new family of memory-augmented neural networks that combine classical deep learning
37
+ algorithms with reactive communication patterns. In Event-driven AI, input data (sequence) is treated as event, and memory
38
+ state has to be kept between events/interactions. Technically, it's a specific kind of RNN that's storing data between
39
+ processed sequences, instead of between sequence elements like in regular RNN. Then, their recurrence is on a higher level.
40
+ In the case of reactive communication patterns, RxRNNs are stateful reactive data sources that you have to connect before
41
+ you can send and receive messages.
42
+ While RxNNs are using some RNN concepts, they are rather made to extend Transformer language/multi-modal models. In our
43
+ opinion, the biggest downside of current LLMs is their stateless nature - conversational models have to process full chat
44
+ history on every interaction! That's not real-time processing, and it's not how human's awareness is working. In RxNN based
45
+ transformers, model is processing single messages, while all the previous interactions history should be saved and read
46
+ from memory. That features are required for **Weak** Reactive Neural Networks specification, and it will be the first major
47
+ step in transition from language models to awareness models - in Reactive AI ecosystem, it will be introduced in Reactive
48
+ Transformer architecture.
49
+
50
+ Additionally, to achieve awareness, **Strong** Reactive Neural Networks are working in reactive infinite reasoning loop,
51
+ that's generating Infinite Chain-of-Thoughts and is communicating in push-based mode (model decides if and when return output).
52
+
53
+ Reactive communication patterns in RxNN models are adapted to handle asynchronous nature of model - after it finish generating
54
+ sequence, it has to process it and save it in memory, but it could be done in background.
55
+
56
+ Apache License
57
+ Version 2.0, January 2004
58
+ http://www.apache.org/licenses/
59
+
60
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
61
+
62
+ 1. Definitions.
63
+
64
+ "License" shall mean the terms and conditions for use, reproduction,
65
+ and distribution as defined by Sections 1 through 9 of this document.
66
+
67
+ "Licensor" shall mean the copyright owner or entity authorized by
68
+ the copyright owner that is granting the License.
69
+
70
+ "Legal Entity" shall mean the union of the acting entity and all
71
+ other entities that control, are controlled by, or are under common
72
+ control with that entity. For the purposes of this definition,
73
+ "control" means (i) the power, direct or indirect, to cause the
74
+ direction or management of such entity, whether by contract or
75
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
76
+ outstanding shares, or (iii) beneficial ownership of such entity.
77
+
78
+ "You" (or "Your") shall mean an individual or Legal Entity
79
+ exercising permissions granted by this License.
80
+
81
+ "Source" form shall mean the preferred form for making modifications,
82
+ including but not limited to software source code, documentation
83
+ source, and configuration files.
84
+
85
+ "Object" form shall mean any form resulting from mechanical
86
+ transformation or translation of a Source form, including but
87
+ not limited to compiled object code, generated documentation,
88
+ and conversions to other media types.
89
+
90
+ "Work" shall mean the work of authorship, whether in Source or
91
+ Object form, made available under the License, as indicated by a
92
+ notice that is included in or attached to the work
93
+ (an example is provided in the Appendix below).
94
+
95
+ "Derivative Works" shall mean any work, whether in Source or Object
96
+ form, that is based on (or derived from) the Work and for which the
97
+ editorial revisions, annotations, elaborations, or other modifications
98
+ represent, as a whole, an original work of authorship. For the purposes
99
+ of this License, Derivative Works shall not include works that remain
100
+ separable from, or merely link (or bind by name) to the interfaces of,
101
+ the Work and Derivative Works thereof.
102
+
103
+ "Contribution" shall mean any work of authorship, including
104
+ the original version of the Work and any modifications or additions
105
+ to that Work or Derivative Works thereof, that is intentionally
106
+ submitted to Licensor for inclusion in the Work by the owner
107
+ or by an individual or Legal Entity authorized to submit on behalf of
108
+ the owner. For the purposes of this definition, "submitted"
109
+ means any form of electronic, verbal, or written communication sent
110
+ to the Licensor or its representatives, including but not limited to
111
+ communication on electronic mailing lists, source code control systems,
112
+ and issue tracking systems that are managed by, or on behalf of, the
113
+ Licensor for the purpose of discussing and improving the Work, but
114
+ excluding communication that is conspicuously marked or otherwise
115
+ designated in writing by the owner as "Not a Contribution."
116
+
117
+ "Contributor" shall mean Licensor and any individual or Legal Entity
118
+ on behalf of whom a Contribution has been received by Licensor and
119
+ subsequently incorporated within the Work.
120
+
121
+ 2. Grant of License. Subject to the terms and conditions of
122
+ this License, each Contributor hereby grants to You a perpetual,
123
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
124
+ license to reproduce, prepare Derivative Works of,
125
+ publicly display, publicly perform, sublicense, and distribute the
126
+ Work and such Derivative Works in Source or Object form.
127
+
128
+ 3. Grant of Patent License. Subject to the terms and conditions of
129
+ this License, each Contributor hereby grants to You a perpetual,
130
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
131
+ (except as stated in this section) patent license to make, have made,
132
+ use, offer to sell, sell, import, and otherwise transfer the Work,
133
+ where such license applies only to those patent claims licensable
134
+ by such Contributor that are necessarily infringed by their
135
+ Contribution(s) alone or by combination of their Contribution(s)
136
+ with the Work to which such Contribution(s) was submitted. If You
137
+ institute patent litigation against any entity (including a
138
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
139
+ or a Contribution incorporated within the Work constitutes direct
140
+ or contributory patent infringement, then any patent licenses
141
+ granted to You under this License for that Work shall terminate
142
+ as of the date such litigation is filed.
143
+
144
+ 4. Redistribution. You may reproduce and distribute copies of the
145
+ Work or Derivative Works thereof in any medium, with or without
146
+ modifications, and in Source or Object form, provided that You
147
+ meet the following conditions:
148
+
149
+ (a) You must give any other recipients of the Work or
150
+ Derivative Works a copy of this License; and
151
+
152
+ (b) You must cause any modified files to carry prominent notices
153
+ stating that You changed the files; and
154
+
155
+ (c) You must retain, in the Source form of any Derivative Works
156
+ that You distribute, all , patent, trademark, and
157
+ attribution notices from the Source form of the Work,
158
+ excluding those notices that do not pertain to any part of
159
+ the Derivative Works; and
160
+
161
+ (d) If the Work includes a "NOTICE" text file as part of its
162
+ distribution, then any Derivative Works that You distribute must
163
+ include a readable copy of the attribution notices contained
164
+ within such NOTICE file, excluding those notices that do not
165
+ pertain to any part of the Derivative Works, in at least one
166
+ of the following places: within a NOTICE text file distributed
167
+ as part of the Derivative Works; within the Source form or
168
+ documentation, if provided along with the Derivative Works; or,
169
+ within a display generated by the Derivative Works, if and
170
+ wherever such third-party notices normally appear. The contents
171
+ of the NOTICE file are for informational purposes only and
172
+ do not modify the License. You may add Your own attribution
173
+ notices within Derivative Works that You distribute, alongside
174
+ or as an addendum to the NOTICE text from the Work, provided
175
+ that such additional attribution notices cannot be construed
176
+ as modifying the License.
177
+
178
+ You may add Your own statement to Your modifications and
179
+ may provide additional or different license terms and conditions
180
+ for use, reproduction, or distribution of Your modifications, or
181
+ for any such Derivative Works as a whole, provided Your use,
182
+ reproduction, and distribution of the Work otherwise complies with
183
+ the conditions stated in this License.
184
+
185
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
186
+ any Contribution intentionally submitted for inclusion in the Work
187
+ by You to the Licensor shall be under the terms and conditions of
188
+ this License, without any additional terms or conditions.
189
+ Notwithstanding the above, nothing herein shall supersede or modify
190
+ the terms of any separate license agreement you may have executed
191
+ with Licensor regarding such Contributions.
192
+
193
+ 6. Trademarks. This License does not grant permission to use the trade
194
+ names, trademarks, service marks, or product names of the Licensor,
195
+ except as required for reasonable and customary use in describing the
196
+ origin of the Work and reproducing the content of the NOTICE file.
197
+
198
+ 7. Disclaimer of Warranty. Unless required by applicable law or
199
+ agreed to in writing, Licensor provides the Work (and each
200
+ Contributor provides its Contributions) on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
202
+ implied, including, without limitation, any warranties or conditions
203
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
204
+ PARTICULAR PURPOSE. You are solely responsible for determining the
205
+ appropriateness of using or redistributing the Work and assume any
206
+ risks associated with Your exercise of permissions under this License.
207
+
208
+ 8. Limitation of Liability. In no event and under no legal theory,
209
+ whether in tort (including negligence), contract, or otherwise,
210
+ unless required by applicable law (such as deliberate and grossly
211
+ negligent acts) or agreed to in writing, shall any Contributor be
212
+ liable to You for damages, including any direct, indirect, special,
213
+ incidental, or consequential damages of any character arising as a
214
+ result of this License or out of the use or inability to use the
215
+ Work (including but not limited to damages for loss of goodwill,
216
+ work stoppage, computer failure or malfunction, or any and all
217
+ other commercial damages or losses), even if such Contributor
218
+ has been advised of the possibility of such damages.
219
+
220
+ 9. Accepting Warranty or Additional Liability. While redistributing
221
+ the Work or Derivative Works thereof, You may choose to offer,
222
+ and charge a fee for, acceptance of support, warranty, indemnity,
223
+ or other liability obligations and/or rights consistent with this
224
+ License. However, in accepting such obligations, You may act only
225
+ on Your own behalf and on Your sole responsibility, not on behalf
226
+ of any other Contributor, and only if You agree to indemnify,
227
+ defend, and hold each Contributor harmless for any liability
228
+ incurred by, or claims asserted against, such Contributor by reason
229
+ of your accepting any such warranty or additional liability.
230
+
231
+ END OF TERMS AND CONDITIONS
232
+
233
+ APPENDIX: How to apply the Apache License to your work.
234
+
235
+ To apply the Apache License to your work, attach the following
236
+ boilerplate notice, with the fields enclosed by brackets "[]"
237
+ replaced with your own identifying information. (Don't include
238
+ the brackets!) The text should be enclosed in the appropriate
239
+ comment syntax for the file format. We also recommend that a
240
+ file or class name and description of purpose be included on the
241
+ same "printed page" as the copyright notice for easier
242
+ identification within third-party archives.
243
+
244
+ Copyright 2024-2025 Adam Filipek
245
+
246
+ Licensed under the Apache License, Version 2.0 (the "License");
247
+ you may not use this file except in compliance with the License.
248
+ You may obtain a copy of the License at
249
+
250
+ http://www.apache.org/licenses/LICENSE-2.0
251
+
252
+ Unless required by applicable law or agreed to in writing, software
253
+ distributed under the License is distributed on an "AS IS" BASIS,
254
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
255
+ See the License for the specific language governing permissions and
256
+ limitations under the License.
257
+
@@ -0,0 +1,23 @@
1
+ src/experimental/attention.py,sha256=BxNFOqQcz3v_wzn5n07UuZQIRLkVxNJEqZedvv8K_WQ,5633
2
+ src/memory/norm.py,sha256=Ofl8Q5NYEF9GQeO0bhM43tkTW91J0y6TSvTAOYMgloM,6278
3
+ src/memory/stm.py,sha256=EsD8slSP4_9dLuq6aFPDmuFe8PWilxh90so5Z3nm-ig,2057
4
+ src/rxt/models.py,sha256=jmxdQ0FHjqYKVrwoEURez1WV-0quv-5q2eBFGhXyJM0,6932
5
+ src/training/base.py,sha256=DHankUIta0wWuczN1O0pK7MCis9dYUvc5dAFkap9t5Q,11030
6
+ src/training/bml.py,sha256=Al-qcQYQ-GsdXfa1DB1YF2vGJKgfIfMBy0GlZabUz1Y,14579
7
+ src/training/callbacks.py,sha256=VAjwaAoSgYgU5WV9FybINznLhBRX9WMWNdgS41FtNfY,21093
8
+ src/training/dataset.py,sha256=vQ5mDF3bA0HXya474n4D4iL8Mn3AEpJukgzFNVkxjGU,5106
9
+ src/training/scheduler.py,sha256=ow6oALzWjWQmHSpcJEjv6tg4g4CDMvr73TypxfcefMc,712
10
+ src/training/tokenizer.py,sha256=4Y41f07uo2KPA_7bp3FCcwGKbXoS2hsckOoXUsXfQxY,8052
11
+ src/transformers/attention.py,sha256=fqNziF9gZOLM-RnrkaCOkel8w-EkLEAOiv7WO5G6IMw,14021
12
+ src/transformers/ff.py,sha256=jJnuBDsnnX5uYC_WZH8cXAYrMnz0P-iX7MwcPivjRtI,2533
13
+ src/transformers/layers.py,sha256=PBlnQzS_cyaAjEAQEgdsttSXhtwWsx4PKxRAtPMhTbY,5361
14
+ src/transformers/mask.py,sha256=J0cfLVLt3SzS2ra3KcY4khrkhI975Dw4CjpUi3Sn25s,419
15
+ src/transformers/models.py,sha256=aVY3YTKGKvwzRraduhIgO8phPDRkJytdTglDQm_U2_c,6716
16
+ src/transformers/moe.py,sha256=JQ5QSX4FS7S-fqB7-s1ZmJbPpOeD_Injn8o4vo7wGQE,4936
17
+ src/transformers/positional.py,sha256=2l38RS0Dini3f6Z3LUHr3XwWzg1UK7fO2C6wazWDAYU,4292
18
+ src/transformers/sampler.py,sha256=wSz_1wNloqtuiix5w2Mcsj5NhaO9QlY0j__TVG7wJnM,3938
19
+ src/utils.py,sha256=d5U8i5ukovgDyqiycc2AoxObTz_eF_bgo2MKvdtJ98s,467
20
+ rxnn-0.1.0.dist-info/LICENSE,sha256=C8coDFIUYuOcke4JLPwTqahQUCyXyGq6WOaigOkx8tY,11275
21
+ rxnn-0.1.0.dist-info/METADATA,sha256=HAt-q9BKoWBJNYr9Ht_sbBcPWMttuEMQmYj4RDrsFrA,14486
22
+ rxnn-0.1.0.dist-info/WHEEL,sha256=fGIA9gx4Qxk2KDKeNJCbOEwSrmLtjWCwzBz351GyrPQ,88
23
+ rxnn-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.1.2
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,133 @@
1
+ import torch
2
+ from torch import nn
3
+ from src.transformers.attention import MultiHeadAttention
4
+
5
+ class FlexAttention(MultiHeadAttention):
6
+ def __init__(
7
+ self,
8
+ embed_dim: int,
9
+ num_heads: int,
10
+ num_global_tokens: int = 16,
11
+ window_size: int = 128,
12
+ **kwargs
13
+ ):
14
+ super().__init__(embed_dim, num_heads, **kwargs)
15
+ self.num_global_tokens = num_global_tokens
16
+ self.window_size = window_size
17
+ self.global_tokens = nn.Parameter(torch.zeros(1, num_global_tokens, embed_dim))
18
+
19
+ def forward(self, query: torch.Tensor, key: torch.Tensor, value: torch.Tensor, mask=None):
20
+ b, t, d = query.size()
21
+ head_dim = d // self.num_heads
22
+
23
+ # Split into global and local
24
+ x = torch.cat([self.global_tokens.expand(b, -1, -1), query], dim=1)
25
+ seq_len = x.size(1)
26
+ num_windows = (seq_len - self.num_global_tokens + self.window_size - 1) // self.window_size
27
+
28
+ # Project Q, K, V
29
+ q, k, v = self._forward_qkv(x, key, value, b, seq_len, d)
30
+
31
+ # Process Global-to-Global Attention
32
+ global_q = q[:, :, :self.num_global_tokens] # [B, H, G, head_dim]
33
+ global_k = k[:, :, :self.num_global_tokens]
34
+ global_v = v[:, :, :self.num_global_tokens]
35
+ global_attn = self._calculate_attn_weights(global_q, global_k, d) @ global_v
36
+
37
+ # Process Global-to-Local Attention
38
+ local_k = k[:, :, self.num_global_tokens:] # [B, H, (num_windows * window_size), head_dim]
39
+ local_v = v[:, :, self.num_global_tokens:]
40
+ # Apply RoPE to local_k if needed
41
+ if self.rope:
42
+ # Compute frequencies for entire local sequence
43
+ local_k = self.rope.forward_one(local_k)
44
+
45
+ global_local_attn = self._calculate_attn_weights(global_q, local_k, d) @ local_v
46
+
47
+ # Process Local-to-Local Attention (per window)
48
+ local_q = q[:, :, self.num_global_tokens:] # [B, H, (num_windows * window_size), head_dim]
49
+ local_q = local_q.view(b, self.num_heads, num_windows, self.window_size, head_dim)
50
+ local_k = local_k.view(b, self.num_heads, num_windows, self.window_size, head_dim)
51
+ local_v = local_v.view(b, self.num_heads, num_windows, self.window_size, head_dim)
52
+
53
+ local_attn = []
54
+ for i in range(num_windows):
55
+ window_q = local_q[:, :, i] # [B, H, window_size, head_dim]
56
+ window_k = local_k[:, :, i]
57
+ window_v = local_v[:, :, i]
58
+
59
+ # Apply RoPE to window_q and window_k
60
+ if self.rope:
61
+ # Compute frequencies for this window
62
+ window_q, window_k = self.rope(window_q, window_k)
63
+
64
+ # Calculate attention for this window
65
+ attn = self._calculate_attn_weights(window_q, window_k, d)
66
+ attn_i = torch.einsum('bhij, bhjd -> bhid', attn, window_v)
67
+ local_attn.append(attn_i)
68
+ local_attn = torch.cat(local_attn, dim=2).view(b, self.num_heads, -1, head_dim)
69
+
70
+ # Combine all attention outputs
71
+ combined_attn = torch.cat([global_attn, global_local_attn, local_attn], dim=2)
72
+ output = self._calculate_output(combined_attn, v, b, t, d)
73
+ return self.out_proj(output)
74
+
75
+ class InfiniteAttention(MultiHeadAttention):
76
+ def __init__(
77
+ self,
78
+ embed_dim: int,
79
+ num_heads: int,
80
+ kernel_size: int = 128,
81
+ use_rotary: bool = True,
82
+ **kwargs
83
+ ):
84
+ super().__init__(embed_dim, num_heads, **kwargs)
85
+ self.kernel_size = kernel_size
86
+ self.use_rotary = use_rotary
87
+ self.register_buffer("fourier_basis", self._init_fourier_basis(embed_dim))
88
+
89
+ def _init_fourier_basis(self, embed_dim):
90
+ # Initialize Fourier features for positional encoding
91
+ freqs = torch.randn(embed_dim // 2)
92
+ return freqs
93
+
94
+ def _positional_encodings(self, x: torch.Tensor, device: torch.device):
95
+ """Generate positional encodings for arbitrary sequence length."""
96
+ seq_len = x.size(1)
97
+ pos = torch.arange(seq_len, device=device).float()
98
+ fourier_features = torch.einsum("d, s -> sd", self.fourier_basis, pos)
99
+ pe = torch.cat([torch.sin(fourier_features), torch.cos(fourier_features)], dim=1)
100
+ return pe.unsqueeze(0).expand(x.size(0), -1, -1)
101
+
102
+ def forward(self, query: torch.Tensor, key: torch.Tensor, value: torch.Tensor, mask=None):
103
+ b, t, d = query.size()
104
+ # Add positional encodings
105
+ pe = self._positional_encodings(query, query.device)
106
+ query = query + pe
107
+ key = key + pe
108
+
109
+ # Split into chunks for kernel-based attention
110
+ chunks = []
111
+ for i in range(0, t, self.kernel_size):
112
+ chunk = query[:, i:i + self.kernel_size]
113
+ chunks.append(chunk)
114
+
115
+ # Compute attention for each chunk
116
+ attn_output = []
117
+ for chunk in chunks:
118
+ q, k, v = self._forward_qkv(chunk, key, value, b, chunk.size(1), d)
119
+ # Use kernel approximation (e.g., Performer)
120
+ attn = self._performer_attention(q, k, v)
121
+ attn_output.append(attn)
122
+
123
+ # Concatenate and apply output projection
124
+ output = torch.cat(attn_output, dim=1)
125
+ return self.out_proj(output)
126
+
127
+ def _performer_attention(self, q: torch.Tensor, k: torch.Tensor, v: torch.Tensor):
128
+ # Performer kernel approximation (simplified)
129
+ # TODO: Replace with preferred kernel method
130
+ q = q / (q.shape[-1] ** 0.5)
131
+ attn = torch.einsum('b h i d, b h j d -> b h i j', q, k)
132
+ attn = torch.softmax(attn, dim=-1)
133
+ return torch.einsum('b h i j, b h j d -> b h i d', attn, v)