syclient-sara 0.1.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 (115) hide show
  1. syclient_sara-0.1.0/LICENSE +220 -0
  2. syclient_sara-0.1.0/PKG-INFO +214 -0
  3. syclient_sara-0.1.0/README.md +177 -0
  4. syclient_sara-0.1.0/pyproject.toml +74 -0
  5. syclient_sara-0.1.0/setup.cfg +4 -0
  6. syclient_sara-0.1.0/src/sara/__init__.py +175 -0
  7. syclient_sara-0.1.0/src/sara/attention.py +177 -0
  8. syclient_sara-0.1.0/src/sara/baselines/__init__.py +277 -0
  9. syclient_sara-0.1.0/src/sara/baselines/gla_ref.py +351 -0
  10. syclient_sara-0.1.0/src/sara/baselines/mamba2_ref.py +385 -0
  11. syclient_sara-0.1.0/src/sara/baselines/transformer_baseline.py +275 -0
  12. syclient_sara-0.1.0/src/sara/blocks.py +194 -0
  13. syclient_sara-0.1.0/src/sara/cache.py +187 -0
  14. syclient_sara-0.1.0/src/sara/cli/__init__.py +33 -0
  15. syclient_sara-0.1.0/src/sara/cli/bench.py +458 -0
  16. syclient_sara-0.1.0/src/sara/config.py +159 -0
  17. syclient_sara-0.1.0/src/sara/configuration_sara.py +284 -0
  18. syclient_sara-0.1.0/src/sara/connectome.py +2148 -0
  19. syclient_sara-0.1.0/src/sara/core/__init__.py +31 -0
  20. syclient_sara-0.1.0/src/sara/core/config.py +93 -0
  21. syclient_sara-0.1.0/src/sara/core/modeling_sara.py +1238 -0
  22. syclient_sara-0.1.0/src/sara/core/tokenizer_sara.py +397 -0
  23. syclient_sara-0.1.0/src/sara/data/__init__.py +39 -0
  24. syclient_sara-0.1.0/src/sara/data/dataset.py +414 -0
  25. syclient_sara-0.1.0/src/sara/data/prepare.py +297 -0
  26. syclient_sara-0.1.0/src/sara/data/synthetic.py +277 -0
  27. syclient_sara-0.1.0/src/sara/data/tokenizer.py +253 -0
  28. syclient_sara-0.1.0/src/sara/data/train_tokenizer.py +103 -0
  29. syclient_sara-0.1.0/src/sara/diagnostics/__init__.py +23 -0
  30. syclient_sara-0.1.0/src/sara/diagnostics/benchmark_architectures.py +1136 -0
  31. syclient_sara-0.1.0/src/sara/diagnostics/verify_sara_brain.py +875 -0
  32. syclient_sara-0.1.0/src/sara/engine/__init__.py +34 -0
  33. syclient_sara-0.1.0/src/sara/engine/generate_with_thinking.py +62 -0
  34. syclient_sara-0.1.0/src/sara/engine/train_mag1.py +511 -0
  35. syclient_sara-0.1.0/src/sara/generate.py +250 -0
  36. syclient_sara-0.1.0/src/sara/horizon/__init__.py +21 -0
  37. syclient_sara-0.1.0/src/sara/horizon/config.py +146 -0
  38. syclient_sara-0.1.0/src/sara/horizon/esl.py +260 -0
  39. syclient_sara-0.1.0/src/sara/horizon/gaspo.py +406 -0
  40. syclient_sara-0.1.0/src/sara/lobes/__init__.py +37 -0
  41. syclient_sara-0.1.0/src/sara/lobes/basal_ganglia.py +404 -0
  42. syclient_sara-0.1.0/src/sara/lobes/curiosity_engine.py +379 -0
  43. syclient_sara-0.1.0/src/sara/lobes/metacognitive_lobe.py +538 -0
  44. syclient_sara-0.1.0/src/sara/lobes/predictive_cortex.py +484 -0
  45. syclient_sara-0.1.0/src/sara/lobes/sleep_consolidator.py +563 -0
  46. syclient_sara-0.1.0/src/sara/mag/__init__.py +60 -0
  47. syclient_sara-0.1.0/src/sara/mag/blocks.py +473 -0
  48. syclient_sara-0.1.0/src/sara/mag/config.py +374 -0
  49. syclient_sara-0.1.0/src/sara/mag/delta_rule.py +414 -0
  50. syclient_sara-0.1.0/src/sara/mag/episodic_memory.py +321 -0
  51. syclient_sara-0.1.0/src/sara/mag/guard.py +340 -0
  52. syclient_sara-0.1.0/src/sara/mag/model.py +1130 -0
  53. syclient_sara-0.1.0/src/sara/mag/vault.py +366 -0
  54. syclient_sara-0.1.0/src/sara/mixer.py +864 -0
  55. syclient_sara-0.1.0/src/sara/modeling_sara.py +831 -0
  56. syclient_sara-0.1.0/src/sara/nervous_system/__init__.py +25 -0
  57. syclient_sara-0.1.0/src/sara/nervous_system/amygdala_shield.py +534 -0
  58. syclient_sara-0.1.0/src/sara/nervous_system/synaptic_bus.py +740 -0
  59. syclient_sara-0.1.0/src/sara/nervous_system/temporal_clock.py +375 -0
  60. syclient_sara-0.1.0/src/sara/scan.py +434 -0
  61. syclient_sara-0.1.0/src/sara/state.py +207 -0
  62. syclient_sara-0.1.0/src/sara/train/__init__.py +19 -0
  63. syclient_sara-0.1.0/src/sara/train/config.py +157 -0
  64. syclient_sara-0.1.0/src/sara/train/evaluator.py +140 -0
  65. syclient_sara-0.1.0/src/sara/train/trainer.py +594 -0
  66. syclient_sara-0.1.0/src/sara/utils.py +137 -0
  67. syclient_sara-0.1.0/src/sara/vpu2.py +195 -0
  68. syclient_sara-0.1.0/src/syclient_sara.egg-info/PKG-INFO +214 -0
  69. syclient_sara-0.1.0/src/syclient_sara.egg-info/SOURCES.txt +113 -0
  70. syclient_sara-0.1.0/src/syclient_sara.egg-info/dependency_links.txt +1 -0
  71. syclient_sara-0.1.0/src/syclient_sara.egg-info/entry_points.txt +5 -0
  72. syclient_sara-0.1.0/src/syclient_sara.egg-info/requires.txt +16 -0
  73. syclient_sara-0.1.0/src/syclient_sara.egg-info/top_level.txt +1 -0
  74. syclient_sara-0.1.0/tests/test_ablation.py +413 -0
  75. syclient_sara-0.1.0/tests/test_audit_fixes.py +183 -0
  76. syclient_sara-0.1.0/tests/test_baselines.py +254 -0
  77. syclient_sara-0.1.0/tests/test_brain_connectome.py +367 -0
  78. syclient_sara-0.1.0/tests/test_cache_generation.py +115 -0
  79. syclient_sara-0.1.0/tests/test_causality.py +53 -0
  80. syclient_sara-0.1.0/tests/test_checkpoint_resume.py +126 -0
  81. syclient_sara-0.1.0/tests/test_chunkwise_equivalence.py +248 -0
  82. syclient_sara-0.1.0/tests/test_chunkwise_stability.py +64 -0
  83. syclient_sara-0.1.0/tests/test_complementary_circuits.py +322 -0
  84. syclient_sara-0.1.0/tests/test_data_pipeline.py +164 -0
  85. syclient_sara-0.1.0/tests/test_ddp_gloo.py +178 -0
  86. syclient_sara-0.1.0/tests/test_gaspo.py +255 -0
  87. syclient_sara-0.1.0/tests/test_generate_fallback.py +87 -0
  88. syclient_sara-0.1.0/tests/test_hf_roundtrip.py +63 -0
  89. syclient_sara-0.1.0/tests/test_horizon.py +364 -0
  90. syclient_sara-0.1.0/tests/test_init_scales.py +47 -0
  91. syclient_sara-0.1.0/tests/test_lr_schedule.py +44 -0
  92. syclient_sara-0.1.0/tests/test_metacognitive_and_sleep.py +463 -0
  93. syclient_sara-0.1.0/tests/test_model_causality.py +33 -0
  94. syclient_sara-0.1.0/tests/test_model_chunkwise_vs_reference.py +46 -0
  95. syclient_sara-0.1.0/tests/test_model_shapes.py +40 -0
  96. syclient_sara-0.1.0/tests/test_nan_guard.py +96 -0
  97. syclient_sara-0.1.0/tests/test_nervous_system.py +444 -0
  98. syclient_sara-0.1.0/tests/test_orthogonality.py +47 -0
  99. syclient_sara-0.1.0/tests/test_overfit_tiny.py +37 -0
  100. syclient_sara-0.1.0/tests/test_param_groups.py +76 -0
  101. syclient_sara-0.1.0/tests/test_ponder.py +278 -0
  102. syclient_sara-0.1.0/tests/test_predictive_cortex.py +335 -0
  103. syclient_sara-0.1.0/tests/test_prefill_then_decode.py +53 -0
  104. syclient_sara-0.1.0/tests/test_sara_mag.py +499 -0
  105. syclient_sara-0.1.0/tests/test_security.py +302 -0
  106. syclient_sara-0.1.0/tests/test_shapes.py +76 -0
  107. syclient_sara-0.1.0/tests/test_stability.py +63 -0
  108. syclient_sara-0.1.0/tests/test_state_size.py +41 -0
  109. syclient_sara-0.1.0/tests/test_step_vs_forward.py +67 -0
  110. syclient_sara-0.1.0/tests/test_synthetic.py +224 -0
  111. syclient_sara-0.1.0/tests/test_task_interface.py +123 -0
  112. syclient_sara-0.1.0/tests/test_tokenizer.py +68 -0
  113. syclient_sara-0.1.0/tests/test_trainer_smoke.py +69 -0
  114. syclient_sara-0.1.0/tests/test_v2_features.py +554 -0
  115. syclient_sara-0.1.0/tests/test_wy_and_acceleration.py +326 -0
@@ -0,0 +1,220 @@
1
+ Sara - O(1) neural runtime
2
+ Copyright 2026 Syclient Labs / Mert Miraç Kaplan (Sara Artificial Brain Architecture)
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ --------------------------------------------------------------------------------
17
+
18
+ Apache License
19
+ Version 2.0, January 2004
20
+ http://www.apache.org/licenses/
21
+
22
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
23
+
24
+ 1. Definitions.
25
+
26
+ "License" shall mean the terms and conditions for use, reproduction,
27
+ and distribution as defined by Sections 1 through 9 of this document.
28
+
29
+ "Licensor" shall mean the copyright owner or entity authorized by
30
+ the copyright owner that is granting the License.
31
+
32
+ "Legal Entity" shall mean the union of the acting entity and all
33
+ other entities that control, are controlled by, or are under common
34
+ control with that entity. For the purposes of this definition,
35
+ "control" means (i) the power, direct or indirect, to cause the
36
+ direction or management of such entity, whether by contract or
37
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
38
+ outstanding shares, or (iii) beneficial ownership of such entity.
39
+
40
+ "You" (or "Your") shall mean an individual or Legal Entity
41
+ exercising permissions granted by this License.
42
+
43
+ "Source" form shall mean the preferred form for making modifications,
44
+ including but not limited to software source code, documentation
45
+ source, and configuration files.
46
+
47
+ "Object" form shall mean any form resulting from mechanical
48
+ transformation or translation of a Source form, including but
49
+ not limited to compiled object code, generated documentation,
50
+ and conversions to other media types.
51
+
52
+ "Work" shall mean the work of authorship, whether in Source or
53
+ Object form, made available under the License, as indicated by a
54
+ copyright notice that is included in or attached to the work
55
+ (an example is provided in the Appendix below).
56
+
57
+ "Derivative Works" shall mean any work, whether in Source or Object
58
+ form, that is based on (or derived from) the Work and for which the
59
+ editorial revisions, annotations, elaborations, or other modifications
60
+ represent, as a whole, an original work of authorship. For the purposes
61
+ of this License, Derivative Works shall not include works that remain
62
+ separable from, or merely link (or bind by name) to the interfaces of,
63
+ the Work and Derivative Works thereof.
64
+
65
+ "Contribution" shall mean any work of authorship, including
66
+ the original version of the Work and any modifications or additions
67
+ to that Work or Derivative Works thereof, that is intentionally
68
+ submitted to Licensor for inclusion in the Work by the copyright owner
69
+ or by an individual or Legal Entity authorized to submit on behalf of
70
+ the copyright owner. For the purposes of this definition, "submitted"
71
+ means any form of electronic, verbal, or written communication sent
72
+ to the Licensor or its representatives, including but not limited to
73
+ communication on electronic mailing lists, source code control systems,
74
+ and issue tracking systems that are managed by, or on behalf of, the
75
+ Licensor for the purpose of discussing and improving the Work, but
76
+ excluding communication that is conspicuously marked or otherwise
77
+ designated in writing by the copyright owner as "Not a Contribution."
78
+
79
+ "Contributor" shall mean Licensor and any individual or Legal Entity
80
+ on behalf of whom a Contribution has been received by Licensor and
81
+ subsequently incorporated within the Work.
82
+
83
+ 2. Grant of Copyright License. Subject to the terms and conditions of
84
+ this License, each Contributor hereby grants to You a perpetual,
85
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
86
+ copyright license to reproduce, prepare Derivative Works of,
87
+ publicly display, publicly perform, sublicense, and distribute the
88
+ Work and such Derivative Works in Source or Object form.
89
+
90
+ 3. Grant of Patent License. Subject to the terms and conditions of
91
+ this License, each Contributor hereby grants to You a perpetual,
92
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
93
+ (except as stated in this section) patent license to make, have made,
94
+ use, offer to sell, sell, import, and otherwise transfer the Work,
95
+ where such license applies only to those patent claims licensable
96
+ by such Contributor that are necessarily infringed by their
97
+ Contribution(s) alone or by combination of their Contribution(s)
98
+ with the Work to which such Contribution(s) was submitted. If You
99
+ institute patent litigation against any entity (including a
100
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
101
+ or a Contribution incorporated within the Work constitutes direct
102
+ or contributory patent infringement, then any patent licenses
103
+ granted to You under this License for that Work shall terminate
104
+ as of the date such litigation is filed.
105
+
106
+ 4. Redistribution. You may reproduce and distribute copies of the
107
+ Work or Derivative Works thereof in any medium, with or without
108
+ modifications, and in Source or Object form, provided that You
109
+ meet the following conditions:
110
+
111
+ (a) You must give any other recipients of the Work or
112
+ Derivative Works a copy of this License; and
113
+
114
+ (b) You must cause any modified files to carry prominent notices
115
+ stating that You changed the files; and
116
+
117
+ (c) You must retain, in the Source form of any Derivative Works
118
+ that You distribute, all copyright, patent, trademark, and
119
+ attribution notices from the Source form of the Work,
120
+ excluding those notices that do not pertain to any part of
121
+ the Derivative Works; and
122
+
123
+ (d) If the Work includes a "NOTICE" text file as part of its
124
+ distribution, then any Derivative Works that You distribute must
125
+ include a readable copy of the attribution notices contained
126
+ within such NOTICE file, excluding those notices that do not
127
+ pertain to any part of the Derivative Works, in at least one
128
+ of the following places: within a NOTICE text file distributed
129
+ as part of the Derivative Works; within the Source form or
130
+ documentation, if provided along with the Derivative Works; or,
131
+ within a display generated by the Derivative Works, if and
132
+ wherever such third-party notices normally appear. The contents
133
+ of the NOTICE file are for informational purposes only and
134
+ do not modify the License. You may add Your own attribution
135
+ notices within Derivative Works that You distribute, alongside
136
+ or as an addendum to the NOTICE text from the Work, provided
137
+ that such additional attribution notices cannot be construed
138
+ as modifying the License.
139
+
140
+ You may add Your own copyright statement to Your modifications and
141
+ may provide additional or different license terms and conditions
142
+ for use, reproduction, or distribution of Your modifications, or
143
+ for any such Derivative Works as a whole, provided Your use,
144
+ reproduction, and distribution of the Work otherwise complies with
145
+ the conditions stated in this License.
146
+
147
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
148
+ any Contribution intentionally submitted for inclusion in the Work
149
+ by You to the Licensor shall be under the terms and conditions of
150
+ this License, without any additional terms or conditions.
151
+ Notwithstanding the above, nothing herein shall supersede or modify
152
+ the terms of any separate license agreement you may have executed
153
+ with Licensor regarding such Contributions.
154
+
155
+ 6. Trademarks. This License does not grant permission to use the trade
156
+ names, trademarks, service marks, or product names of the Licensor,
157
+ except as required for reasonable and customary use in describing the
158
+ origin of the Work and reproducing the content of the NOTICE file.
159
+
160
+ 7. Disclaimer of Warranty. Unless required by applicable law or
161
+ agreed to in writing, Licensor provides the Work (and each
162
+ Contributor provides its Contributions) on an "AS IS" BASIS,
163
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
164
+ implied, including, without limitation, any warranties or conditions
165
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
166
+ PARTICULAR PURPOSE. You are solely responsible for determining the
167
+ appropriateness of using or redistributing the Work and assume any
168
+ risks associated with Your exercise of permissions under this License.
169
+
170
+ 8. Limitation of Liability. In no event and under no legal theory,
171
+ whether in tort (including negligence), contract, or otherwise,
172
+ unless required by applicable law (such as deliberate and grossly
173
+ negligent acts) or agreed to in writing, shall any Contributor be
174
+ liable to You for damages, including any direct, indirect, special,
175
+ incidental, or consequential damages of any character arising as a
176
+ result of this License or out of the use or inability to use the
177
+ Work (including but not limited to damages for loss of goodwill,
178
+ work stoppage, computer failure or malfunction, or any and all
179
+ other commercial damages or losses), even if such Contributor
180
+ has been advised of the possibility of such damages.
181
+
182
+ 9. Accepting Warranty or Additional Liability. While redistributing
183
+ the Work or Derivative Works thereof, You may choose to offer,
184
+ and charge a fee for, acceptance of support, warranty, indemnity,
185
+ or other liability obligations and/or rights consistent with this
186
+ License. However, in accepting such obligations, You may act only
187
+ on Your own behalf and on Your sole responsibility, not on behalf
188
+ of any other Contributor, and only if You agree to indemnify,
189
+ defend, and hold each Contributor harmless for any liability
190
+ incurred by, or claims asserted against, such Contributor by reason
191
+ of your accepting any such warranty or additional liability.
192
+
193
+ END OF TERMS AND CONDITIONS
194
+
195
+ APPENDIX: How to apply the Apache License to your work.
196
+
197
+ To apply the Apache License to your work, attach the following
198
+ boilerplate notice, with the fields enclosed by brackets "[]"
199
+ replaced with your own identifying information. (Don't include
200
+ the brackets!) The text should be enclosed in the appropriate
201
+ comment syntax for the file format. We also recommend that a
202
+ file or class name and description of purpose be included on the
203
+ same "printed page" as the copyright notice for easier
204
+ identification within third-party archives.
205
+
206
+ Copyright [yyyy] [name of copyright owner]
207
+
208
+ Licensed under the Apache License, Version 2.0 (the "License");
209
+ you may not use this file except in compliance with the License.
210
+ You may obtain a copy of the License at
211
+
212
+ http://www.apache.org/licenses/LICENSE-2.0
213
+
214
+ Unless required by applicable law or agreed to in writing, software
215
+ distributed under the License is distributed on an "AS IS" BASIS,
216
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
217
+ See the License for the specific language governing permissions and
218
+ limitations under the License.
219
+
220
+ Copyright 2026 Syclient Labs / Mert Miraç Kaplan
@@ -0,0 +1,214 @@
1
+ Metadata-Version: 2.4
2
+ Name: syclient-sara
3
+ Version: 0.1.0
4
+ Summary: Sara - O(1)-memory neural runtime: hippocampal core, synaptic fast weights, episodic memory, and the SaraConnectome
5
+ Author-email: Mert Miraç Kaplan <mert@syclientlabs.com>
6
+ License: Apache-2.0
7
+ Project-URL: Homepage, https://syclientlabs.com
8
+ Project-URL: Repository, https://github.com/Syclient/sara
9
+ Project-URL: Models, https://huggingface.co/Syclient
10
+ Keywords: sara,sara-brain,connectome,state-space-model,linear-attention,delta-rule,episodic-memory,associative-recall,pytorch
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Science/Research
14
+ Classifier: License :: OSI Approved :: Apache Software License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.10
17
+ Classifier: Programming Language :: Python :: 3.11
18
+ Classifier: Programming Language :: Python :: 3.12
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Requires-Dist: torch>=2.2.0
24
+ Requires-Dist: numpy>=1.24.0
25
+ Provides-Extra: hf
26
+ Requires-Dist: transformers>=4.40.0; extra == "hf"
27
+ Requires-Dist: accelerate>=0.28.0; extra == "hf"
28
+ Requires-Dist: huggingface-hub>=0.23.0; extra == "hf"
29
+ Provides-Extra: dev
30
+ Requires-Dist: pytest; extra == "dev"
31
+ Requires-Dist: build; extra == "dev"
32
+ Requires-Dist: twine; extra == "dev"
33
+ Provides-Extra: vault
34
+ Requires-Dist: cryptography>=41.0; extra == "vault"
35
+ Requires-Dist: safetensors>=0.4.0; extra == "vault"
36
+ Dynamic: license-file
37
+
38
+ # Sara
39
+
40
+ **An O(1)-memory neural runtime.** Fixed-size recurrent state, no growing KV cache: context
41
+ length changes the work you do, never the memory you hold.
42
+
43
+ [![PyPI](https://img.shields.io/pypi/v/sara.svg)](https://pypi.org/project/syclient-sara/)
44
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
45
+ [![Hugging Face](https://img.shields.io/badge/%F0%9F%A4%97-Hugging%20Face-Syclient-yellow)](https://huggingface.co/Syclient)
46
+ [![Tests](https://img.shields.io/badge/tests-passing-brightgreen.svg)](tests)
47
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](pyproject.toml)
48
+
49
+ Sara replaces the quadratic attention cache with a **hippocampal selective state** that is
50
+ updated as tokens stream through it. The runtime ships four pieces that matter:
51
+
52
+ | Component | What it does |
53
+ | --- | --- |
54
+ | `SaraConnectome` | Unified brain graph: core state + neuromodulation + cognitive lobes, one fixed-size state object |
55
+ | L1 **Delta-Rule** fast weights | `SynapticFastWeights` writes token-local associations into a small second-order matrix |
56
+ | L2 **episodic memory** | `HippocampalSelectiveCore` keeps a chunkwise-parallel, gated long-range state |
57
+ | `PrefrontalThinkingLoop` + `InternalVerifierHead` | Recurrent "think again" passes with a learned halting/verifier signal and rollback |
58
+
59
+ ## Verified numbers
60
+
61
+ Measured decoder and training runs on a retail **NVIDIA RTX 3060 8 GB** (Windows 11, WDDM
62
+ driver) and a **cloud NVIDIA L4 24 GB**. Energy is wall power per 1K generated tokens.
63
+
64
+ | Workload | Throughput | Energy | Peak VRAM | Verified on |
65
+ | --- | ---: | ---: | ---: | --- |
66
+ | `SPM-350M` decode | **32,733.3 tok/s** | **3.14 J / 1K tok** | — | RTX 3060 / cloud L4 |
67
+ | `SPM-1B` decode | **19,762.3 tok/s** | **5.77 J / 1K tok** | **2,984 MB** | RTX 3060 / cloud L4 |
68
+ | `MAG-3.01B` training | — | — | **< 5.5 GB** (WDDM-safe) | RTX 3060 8 GB |
69
+ | O(1) state, 512 → 128K+ tokens | — | — | **9.00–9.25 MiB constant** | RTX 3060 / cloud L4 |
70
+
71
+ The last row is the point: the recurrent state stays between **9.00 and 9.25 MiB from 512 to
72
+ 128K+ tokens**, i.e. `0.00 MiB` growth. A KV-cache model at 128K tokens needs gigabytes for the
73
+ cache alone. `sara-bench` measures this live on your hardware.
74
+
75
+ <sub>Full-scale throughput/energy figures were recorded with Syclient's production VPU-2 kernel
76
+ build. This repository ships the **same architecture** with the portable PyTorch/`bfloat16`
77
+ runtime (`sara.patch_vpu2`), so the memory invariance reproduces exactly while absolute
78
+ throughput depends on your kernels and hardware.</sub>
79
+
80
+ ## Install
81
+
82
+ ```bash
83
+ pip install syclient-sara # torch + numpy only
84
+ pip install "sara[hf]" # + transformers / accelerate / huggingface-hub
85
+ ```
86
+
87
+ Python 3.10+, PyTorch 2.2+ (CUDA builds pick up `bfloat16` and SDPA automatically).
88
+
89
+ ## Quickstart
90
+
91
+ ### 1. Measure the O(1) state yourself
92
+
93
+ ```bash
94
+ sara-bench --max-seq-len 32768
95
+ ```
96
+
97
+ Stage 1 streams 512 → 32K tokens through the connectome and prints state MiB + tok/s per
98
+ context length; stage 2 reports CUDA peak VRAM and throughput (it skips cleanly on CPU).
99
+
100
+ * `--preset release` swaps in the ~350M release shape — `sara-bench --device cpu --preset
101
+ release --max-seq-len 512` reports **9.25 MiB** state, the same figure as the table above.
102
+ * `--hf-model Qwen/Qwen2.5-1.5B` benchmarks a Hugging Face checkpoint through `patch_vpu2`
103
+ instead of the Sara training step.
104
+ * The default `compact` preset is deliberately small so the 32K sweep finishes in seconds on a
105
+ laptop; at that size per-token throughput is dominated by Python/kernel launch overhead, not
106
+ by GEMM throughput, so treat its tok/s as a smoke number rather than a peak.
107
+
108
+ ### 2. Run the runtime
109
+
110
+ ```python
111
+ import torch
112
+ from sara import SaraBrainConfig, SaraConnectome
113
+
114
+ model = SaraConnectome(
115
+ config=SaraBrainConfig(), # ~350M release shape
116
+ ).eval()
117
+
118
+ # Fixed-size state: allocated once, carried forever.
119
+ state = model.init_brain_state(batch_size=1)
120
+
121
+ out = model.forward_step(
122
+ input_ids=token_ids, # [B, T] long
123
+ state=state,
124
+ enable_rollback=False, # max throughput; True = think/verify/rollback
125
+ )
126
+ state = out.state # same byte size, any T
127
+ logits = out.logits
128
+
129
+ print(model.total_state_nbytes(state) / 1024**2, "MiB")
130
+ ```
131
+
132
+ Long context is just more chunks through the same state:
133
+
134
+ ```python
135
+ state = model.init_brain_state(batch_size=1)
136
+ for chunk in chunks: # any chunk length
137
+ state = model.forward_step(input_ids=chunk, state=state).state
138
+ ```
139
+
140
+ `SaraConnectome` signature (keyword-only after `core`):
141
+
142
+ ```python
143
+ SaraConnectome(
144
+ core=None, # Optional[SaraBrainForCausalLM]
145
+ *,
146
+ config=None, # Optional[SaraBrainConfig]
147
+ d_meta=32,
148
+ max_replay_slots=64,
149
+ dopamine_seal_threshold=0.65,
150
+ surprise_push_threshold=0.45,
151
+ clamp_val=10.0,
152
+ )
153
+ ```
154
+
155
+ ### 3. Patch an existing model
156
+
157
+ `sara.patch_vpu2` is the public runtime entry point. It routes a model onto the portable
158
+ PyTorch/`bfloat16` fast path — fused RMSNorm, bf16 weights, SDPA kernels — and returns a
159
+ report describing what was applied. It patches in place and never requires a compiled kernel.
160
+
161
+ ```python
162
+ import sara
163
+ from transformers import AutoModelForCausalLM
164
+
165
+ model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-1.5B")
166
+ report = sara.patch_vpu2(model) # in-place; also works on SaraConnectome
167
+ print(report.summary())
168
+ # patch_vpu2[pytorch-bf16] dtype=torch.bfloat16 device=cuda rmsnorm=17 ... sdpa=on
169
+ ```
170
+
171
+ ## Checkpoints
172
+
173
+ Weights live on the Hugging Face Hub under [**Syclient**](https://huggingface.co/Syclient):
174
+
175
+ | Model | Link |
176
+ | --- | --- |
177
+ | `SPM-70M-Vertigo` | https://huggingface.co/Syclient/SPM-70M-Vertigo |
178
+ | `SPM-350M` | https://huggingface.co/Syclient/SPM-350M |
179
+ | `MAG-350M` | https://huggingface.co/Syclient/MAG-350M |
180
+
181
+ ## What is in this repository
182
+
183
+ ```text
184
+ src/sara/
185
+ connectome.py SaraConnectome, ConnectomeState, ConnectomeOutput, CompiledStepRunner
186
+ core/ HippocampalSelectiveCore, SynapticFastWeights (L1),
187
+ PrefrontalThinkingLoop, InternalVerifierHead, SaraBrainForCausalLM
188
+ lobes/ predictive cortex, metacognition, sleep consolidation,
189
+ basal ganglia, intrinsic curiosity
190
+ nervous_system/ neuromodulator bus, synaptic packet, circadian clock, amygdala shield
191
+ mag/ Delta-rule L1 + episodic L2 blocks, MAG model, guard, weight vault
192
+ engine/ generate_with_thinking, MAG1 trainer
193
+ diagnostics/ architecture verification + Transformer/Mamba comparison harness
194
+ vpu2.py public patch_vpu2 runtime patcher
195
+ cli/bench.py sara-bench
196
+ tests/ full suite (CPU + CUDA paths)
197
+ SPEC.md architecture specification
198
+ ```
199
+
200
+ Diagnostics entry points: `sara-verify`, `sara-benchmark`, `sara-train`, `sara-bench`.
201
+
202
+ ## Development
203
+
204
+ ```bash
205
+ git clone https://github.com/Syclient/sara
206
+ cd sara
207
+ pip install -e ".[dev]"
208
+ pytest -q # 371 tests (CPU + CUDA paths)
209
+ sara-bench --max-seq-len 16384
210
+ ```
211
+
212
+ ## License
213
+
214
+ Apache-2.0. Copyright 2026 Syclient Labs / Mert Miraç Kaplan. See [LICENSE](LICENSE).
@@ -0,0 +1,177 @@
1
+ # Sara
2
+
3
+ **An O(1)-memory neural runtime.** Fixed-size recurrent state, no growing KV cache: context
4
+ length changes the work you do, never the memory you hold.
5
+
6
+ [![PyPI](https://img.shields.io/pypi/v/sara.svg)](https://pypi.org/project/syclient-sara/)
7
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE)
8
+ [![Hugging Face](https://img.shields.io/badge/%F0%9F%A4%97-Hugging%20Face-Syclient-yellow)](https://huggingface.co/Syclient)
9
+ [![Tests](https://img.shields.io/badge/tests-passing-brightgreen.svg)](tests)
10
+ [![Python](https://img.shields.io/badge/python-3.10%2B-blue.svg)](pyproject.toml)
11
+
12
+ Sara replaces the quadratic attention cache with a **hippocampal selective state** that is
13
+ updated as tokens stream through it. The runtime ships four pieces that matter:
14
+
15
+ | Component | What it does |
16
+ | --- | --- |
17
+ | `SaraConnectome` | Unified brain graph: core state + neuromodulation + cognitive lobes, one fixed-size state object |
18
+ | L1 **Delta-Rule** fast weights | `SynapticFastWeights` writes token-local associations into a small second-order matrix |
19
+ | L2 **episodic memory** | `HippocampalSelectiveCore` keeps a chunkwise-parallel, gated long-range state |
20
+ | `PrefrontalThinkingLoop` + `InternalVerifierHead` | Recurrent "think again" passes with a learned halting/verifier signal and rollback |
21
+
22
+ ## Verified numbers
23
+
24
+ Measured decoder and training runs on a retail **NVIDIA RTX 3060 8 GB** (Windows 11, WDDM
25
+ driver) and a **cloud NVIDIA L4 24 GB**. Energy is wall power per 1K generated tokens.
26
+
27
+ | Workload | Throughput | Energy | Peak VRAM | Verified on |
28
+ | --- | ---: | ---: | ---: | --- |
29
+ | `SPM-350M` decode | **32,733.3 tok/s** | **3.14 J / 1K tok** | — | RTX 3060 / cloud L4 |
30
+ | `SPM-1B` decode | **19,762.3 tok/s** | **5.77 J / 1K tok** | **2,984 MB** | RTX 3060 / cloud L4 |
31
+ | `MAG-3.01B` training | — | — | **< 5.5 GB** (WDDM-safe) | RTX 3060 8 GB |
32
+ | O(1) state, 512 → 128K+ tokens | — | — | **9.00–9.25 MiB constant** | RTX 3060 / cloud L4 |
33
+
34
+ The last row is the point: the recurrent state stays between **9.00 and 9.25 MiB from 512 to
35
+ 128K+ tokens**, i.e. `0.00 MiB` growth. A KV-cache model at 128K tokens needs gigabytes for the
36
+ cache alone. `sara-bench` measures this live on your hardware.
37
+
38
+ <sub>Full-scale throughput/energy figures were recorded with Syclient's production VPU-2 kernel
39
+ build. This repository ships the **same architecture** with the portable PyTorch/`bfloat16`
40
+ runtime (`sara.patch_vpu2`), so the memory invariance reproduces exactly while absolute
41
+ throughput depends on your kernels and hardware.</sub>
42
+
43
+ ## Install
44
+
45
+ ```bash
46
+ pip install syclient-sara # torch + numpy only
47
+ pip install "sara[hf]" # + transformers / accelerate / huggingface-hub
48
+ ```
49
+
50
+ Python 3.10+, PyTorch 2.2+ (CUDA builds pick up `bfloat16` and SDPA automatically).
51
+
52
+ ## Quickstart
53
+
54
+ ### 1. Measure the O(1) state yourself
55
+
56
+ ```bash
57
+ sara-bench --max-seq-len 32768
58
+ ```
59
+
60
+ Stage 1 streams 512 → 32K tokens through the connectome and prints state MiB + tok/s per
61
+ context length; stage 2 reports CUDA peak VRAM and throughput (it skips cleanly on CPU).
62
+
63
+ * `--preset release` swaps in the ~350M release shape — `sara-bench --device cpu --preset
64
+ release --max-seq-len 512` reports **9.25 MiB** state, the same figure as the table above.
65
+ * `--hf-model Qwen/Qwen2.5-1.5B` benchmarks a Hugging Face checkpoint through `patch_vpu2`
66
+ instead of the Sara training step.
67
+ * The default `compact` preset is deliberately small so the 32K sweep finishes in seconds on a
68
+ laptop; at that size per-token throughput is dominated by Python/kernel launch overhead, not
69
+ by GEMM throughput, so treat its tok/s as a smoke number rather than a peak.
70
+
71
+ ### 2. Run the runtime
72
+
73
+ ```python
74
+ import torch
75
+ from sara import SaraBrainConfig, SaraConnectome
76
+
77
+ model = SaraConnectome(
78
+ config=SaraBrainConfig(), # ~350M release shape
79
+ ).eval()
80
+
81
+ # Fixed-size state: allocated once, carried forever.
82
+ state = model.init_brain_state(batch_size=1)
83
+
84
+ out = model.forward_step(
85
+ input_ids=token_ids, # [B, T] long
86
+ state=state,
87
+ enable_rollback=False, # max throughput; True = think/verify/rollback
88
+ )
89
+ state = out.state # same byte size, any T
90
+ logits = out.logits
91
+
92
+ print(model.total_state_nbytes(state) / 1024**2, "MiB")
93
+ ```
94
+
95
+ Long context is just more chunks through the same state:
96
+
97
+ ```python
98
+ state = model.init_brain_state(batch_size=1)
99
+ for chunk in chunks: # any chunk length
100
+ state = model.forward_step(input_ids=chunk, state=state).state
101
+ ```
102
+
103
+ `SaraConnectome` signature (keyword-only after `core`):
104
+
105
+ ```python
106
+ SaraConnectome(
107
+ core=None, # Optional[SaraBrainForCausalLM]
108
+ *,
109
+ config=None, # Optional[SaraBrainConfig]
110
+ d_meta=32,
111
+ max_replay_slots=64,
112
+ dopamine_seal_threshold=0.65,
113
+ surprise_push_threshold=0.45,
114
+ clamp_val=10.0,
115
+ )
116
+ ```
117
+
118
+ ### 3. Patch an existing model
119
+
120
+ `sara.patch_vpu2` is the public runtime entry point. It routes a model onto the portable
121
+ PyTorch/`bfloat16` fast path — fused RMSNorm, bf16 weights, SDPA kernels — and returns a
122
+ report describing what was applied. It patches in place and never requires a compiled kernel.
123
+
124
+ ```python
125
+ import sara
126
+ from transformers import AutoModelForCausalLM
127
+
128
+ model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-1.5B")
129
+ report = sara.patch_vpu2(model) # in-place; also works on SaraConnectome
130
+ print(report.summary())
131
+ # patch_vpu2[pytorch-bf16] dtype=torch.bfloat16 device=cuda rmsnorm=17 ... sdpa=on
132
+ ```
133
+
134
+ ## Checkpoints
135
+
136
+ Weights live on the Hugging Face Hub under [**Syclient**](https://huggingface.co/Syclient):
137
+
138
+ | Model | Link |
139
+ | --- | --- |
140
+ | `SPM-70M-Vertigo` | https://huggingface.co/Syclient/SPM-70M-Vertigo |
141
+ | `SPM-350M` | https://huggingface.co/Syclient/SPM-350M |
142
+ | `MAG-350M` | https://huggingface.co/Syclient/MAG-350M |
143
+
144
+ ## What is in this repository
145
+
146
+ ```text
147
+ src/sara/
148
+ connectome.py SaraConnectome, ConnectomeState, ConnectomeOutput, CompiledStepRunner
149
+ core/ HippocampalSelectiveCore, SynapticFastWeights (L1),
150
+ PrefrontalThinkingLoop, InternalVerifierHead, SaraBrainForCausalLM
151
+ lobes/ predictive cortex, metacognition, sleep consolidation,
152
+ basal ganglia, intrinsic curiosity
153
+ nervous_system/ neuromodulator bus, synaptic packet, circadian clock, amygdala shield
154
+ mag/ Delta-rule L1 + episodic L2 blocks, MAG model, guard, weight vault
155
+ engine/ generate_with_thinking, MAG1 trainer
156
+ diagnostics/ architecture verification + Transformer/Mamba comparison harness
157
+ vpu2.py public patch_vpu2 runtime patcher
158
+ cli/bench.py sara-bench
159
+ tests/ full suite (CPU + CUDA paths)
160
+ SPEC.md architecture specification
161
+ ```
162
+
163
+ Diagnostics entry points: `sara-verify`, `sara-benchmark`, `sara-train`, `sara-bench`.
164
+
165
+ ## Development
166
+
167
+ ```bash
168
+ git clone https://github.com/Syclient/sara
169
+ cd sara
170
+ pip install -e ".[dev]"
171
+ pytest -q # 371 tests (CPU + CUDA paths)
172
+ sara-bench --max-seq-len 16384
173
+ ```
174
+
175
+ ## License
176
+
177
+ Apache-2.0. Copyright 2026 Syclient Labs / Mert Miraç Kaplan. See [LICENSE](LICENSE).
@@ -0,0 +1,74 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "syclient-sara"
7
+ version = "0.1.0"
8
+ description = "Sara - O(1)-memory neural runtime: hippocampal core, synaptic fast weights, episodic memory, and the SaraConnectome"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = { text = "Apache-2.0" }
12
+ authors = [{ name = "Mert Miraç Kaplan", email = "mert@syclientlabs.com" }]
13
+ keywords = [
14
+ "sara",
15
+ "sara-brain",
16
+ "connectome",
17
+ "state-space-model",
18
+ "linear-attention",
19
+ "delta-rule",
20
+ "episodic-memory",
21
+ "associative-recall",
22
+ "pytorch",
23
+ ]
24
+ classifiers = [
25
+ "Development Status :: 4 - Beta",
26
+ "Intended Audience :: Developers",
27
+ "Intended Audience :: Science/Research",
28
+ "License :: OSI Approved :: Apache Software License",
29
+ "Programming Language :: Python :: 3",
30
+ "Programming Language :: Python :: 3.10",
31
+ "Programming Language :: Python :: 3.11",
32
+ "Programming Language :: Python :: 3.12",
33
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
34
+ ]
35
+ dependencies = [
36
+ "torch>=2.2.0",
37
+ "numpy>=1.24.0",
38
+ ]
39
+
40
+ [project.optional-dependencies]
41
+ hf = [
42
+ "transformers>=4.40.0",
43
+ "accelerate>=0.28.0",
44
+ "huggingface-hub>=0.23.0",
45
+ ]
46
+ dev = [
47
+ "pytest",
48
+ "build",
49
+ "twine",
50
+ ]
51
+ vault = [
52
+ "cryptography>=41.0",
53
+ "safetensors>=0.4.0",
54
+ ]
55
+
56
+ [project.urls]
57
+ Homepage = "https://syclientlabs.com"
58
+ Repository = "https://github.com/Syclient/sara"
59
+ Models = "https://huggingface.co/Syclient"
60
+
61
+ [project.scripts]
62
+ sara-bench = "sara.cli.bench:main"
63
+ sara-verify = "sara.cli:verify_main"
64
+ sara-benchmark = "sara.cli:benchmark_main"
65
+ sara-train = "sara.cli:train_main"
66
+
67
+ [tool.setuptools.packages.find]
68
+ where = ["src"]
69
+ include = ["sara*"]
70
+
71
+ [tool.pytest.ini_options]
72
+ testpaths = ["tests"]
73
+ python_files = ["test_*.py"]
74
+ pythonpath = ["src"]