icm-llm 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 (38) hide show
  1. icm_llm-0.1.0/LICENSE +201 -0
  2. icm_llm-0.1.0/PKG-INFO +339 -0
  3. icm_llm-0.1.0/README.md +293 -0
  4. icm_llm-0.1.0/applications/__init__.py +0 -0
  5. icm_llm-0.1.0/applications/cli_chat.py +506 -0
  6. icm_llm-0.1.0/applications/icm_demo.py +11 -0
  7. icm_llm-0.1.0/applications/icm_server.py +650 -0
  8. icm_llm-0.1.0/applications/infinite_chat_demo.py +243 -0
  9. icm_llm-0.1.0/hyper_ssm/__init__.py +79 -0
  10. icm_llm-0.1.0/hyper_ssm/audio_topology.py +59 -0
  11. icm_llm-0.1.0/hyper_ssm/auth.py +127 -0
  12. icm_llm-0.1.0/hyper_ssm/conversation_memory.py +739 -0
  13. icm_llm-0.1.0/hyper_ssm/csrc/riemannian.cpp +28 -0
  14. icm_llm-0.1.0/hyper_ssm/csrc/riemannian_kernel.cu +114 -0
  15. icm_llm-0.1.0/hyper_ssm/cuda_ops.py +102 -0
  16. icm_llm-0.1.0/hyper_ssm/custom_tokenizer.py +188 -0
  17. icm_llm-0.1.0/hyper_ssm/data_loader.py +64 -0
  18. icm_llm-0.1.0/hyper_ssm/geometry_fusion.py +242 -0
  19. icm_llm-0.1.0/hyper_ssm/hierarchical_memory.py +292 -0
  20. icm_llm-0.1.0/hyper_ssm/hybrid_attention.py +70 -0
  21. icm_llm-0.1.0/hyper_ssm/hyperbolic_loss.py +230 -0
  22. icm_llm-0.1.0/hyper_ssm/hyperbolic_ops.py +489 -0
  23. icm_llm-0.1.0/hyper_ssm/liquid_weights.py +139 -0
  24. icm_llm-0.1.0/hyper_ssm/llm_integration.py +656 -0
  25. icm_llm-0.1.0/hyper_ssm/model.py +556 -0
  26. icm_llm-0.1.0/hyper_ssm/session_store.py +160 -0
  27. icm_llm-0.1.0/hyper_ssm/tiled_compressor.py +745 -0
  28. icm_llm-0.1.0/hyper_ssm/tokenizer.py +77 -0
  29. icm_llm-0.1.0/hyper_ssm/vision_topology.py +62 -0
  30. icm_llm-0.1.0/icm_llm.egg-info/PKG-INFO +339 -0
  31. icm_llm-0.1.0/icm_llm.egg-info/SOURCES.txt +36 -0
  32. icm_llm-0.1.0/icm_llm.egg-info/dependency_links.txt +1 -0
  33. icm_llm-0.1.0/icm_llm.egg-info/entry_points.txt +4 -0
  34. icm_llm-0.1.0/icm_llm.egg-info/requires.txt +23 -0
  35. icm_llm-0.1.0/icm_llm.egg-info/top_level.txt +2 -0
  36. icm_llm-0.1.0/pyproject.toml +86 -0
  37. icm_llm-0.1.0/setup.cfg +4 -0
  38. icm_llm-0.1.0/tests/test_icm.py +1090 -0
icm_llm-0.1.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 Varshini CB
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.
icm_llm-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,339 @@
1
+ Metadata-Version: 2.4
2
+ Name: icm-llm
3
+ Version: 0.1.0
4
+ Summary: O(1) hyperbolic memory for any LLM — 260 bytes per session forever
5
+ Author-email: Varshini CB <varshinicb1@github.com>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/varshinicb1/hyper-ssm-ultimate
8
+ Project-URL: Repository, https://github.com/varshinicb1/hyper-ssm-ultimate
9
+ Project-URL: Documentation, https://github.com/varshinicb1/hyper-ssm-ultimate#readme
10
+ Project-URL: Changelog, https://github.com/varshinicb1/hyper-ssm-ultimate/releases
11
+ Keywords: llm,hyperbolic,memory,infinite-context,transformer,huggingface,deep-learning,attention,large-language-models,nlp
12
+ Classifier: Development Status :: 4 - Beta
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Intended Audience :: Science/Research
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: Programming Language :: Python :: 3.13
20
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: torch>=2.4.0
26
+ Requires-Dist: transformers>=4.40.0
27
+ Requires-Dist: numpy>=1.24.0
28
+ Requires-Dist: tqdm>=4.66.0
29
+ Requires-Dist: sentence-transformers>=2.2.0
30
+ Requires-Dist: fastapi>=0.110.0
31
+ Requires-Dist: uvicorn[standard]>=0.27.0
32
+ Requires-Dist: pydantic>=2.0.0
33
+ Provides-Extra: dev
34
+ Requires-Dist: pytest>=8.0; extra == "dev"
35
+ Requires-Dist: pytest-asyncio>=0.24; extra == "dev"
36
+ Requires-Dist: httpx>=0.27; extra == "dev"
37
+ Requires-Dist: websockets>=12.0; extra == "dev"
38
+ Requires-Dist: build>=1.0; extra == "dev"
39
+ Requires-Dist: twine>=5.0; extra == "dev"
40
+ Provides-Extra: cuda
41
+ Requires-Dist: bitsandbytes>=0.43.0; extra == "cuda"
42
+ Requires-Dist: accelerate>=0.30.0; extra == "cuda"
43
+ Provides-Extra: all
44
+ Requires-Dist: icm[cuda,dev]; extra == "all"
45
+ Dynamic: license-file
46
+
47
+ <div align="center">
48
+ <h1>Infinite Context Memory (ICM)</h1>
49
+ <p><strong>O(1) hyperbolic memory for any LLM. 260 bytes per session. Forever.</strong></p>
50
+ <p>
51
+ <a href="https://github.com/varshinicb1/hyper-ssm-ultimate/tree/main"><img src="https://img.shields.io/github/stars/varshinicb1/hyper-ssm-ultimate?style=social" alt="Stars" /></a>
52
+ <a href="LICENSE"><img src="https://img.shields.io/badge/License-Apache_2.0-blue" alt="License" /></a>
53
+ <a href="https://github.com/varshinicb1/hyper-ssm-ultimate/tree/main"><img src="https://img.shields.io/github/actions/workflow/status/varshinicb1/hyper-ssm-ultimate/python-test.yml?label=CI" alt="CI" /></a>
54
+ <a href="#"><img src="https://img.shields.io/badge/Tests-68_passing-brightgreen" alt="Tests" /></a>
55
+ <a href="https://pypi.org/project/icm/"><img src="https://img.shields.io/badge/python-3.10%2B-blue" alt="Python" /></a>
56
+ <a href="https://huggingface.co/"><img src="https://img.shields.io/badge/HuggingFace-Ready-FFD21E" alt="HF" /></a>
57
+ <a href="icm_demo.ipynb"><img src="https://colab.research.google.com/assets/colab-badge.svg" alt="Colab" /></a>
58
+ </p>
59
+ </div>
60
+
61
+ ---
62
+
63
+ ## Demo
64
+
65
+ Try ICM right now — 4 ways:
66
+
67
+ | Method | Command |
68
+ |:-------|:--------|
69
+ | **Docker** (full stack) | `docker compose up -d && open http://localhost:8000` |
70
+ | **Colab** (browser) | [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](icm_demo.ipynb) |
71
+ | **CLI** (local) | `python icm_demo.py` or `python applications/cli_chat.py` |
72
+ | **Python** (code) | `pip install -r requirements.txt && python -c "from hyper_ssm.conversation_memory import InfiniteContextMemory; print(InfiniteContextMemory().__doc__)"` |
73
+
74
+ ```bash
75
+ # One-liner to see O(1) memory in action:
76
+ python icm_demo.py
77
+ # Output: 260 bytes per turn — fixed, forever.
78
+ ```
79
+
80
+ ![ICM Demo](social-preview.png)
81
+
82
+ ---
83
+
84
+ ## Why This Matters
85
+
86
+ Every LLM today uses **attention** — a mechanism with quadratic cost in sequence length. A 70B model processing 1M tokens needs **~640 GB of GPU RAM** just for the KV-cache.
87
+
88
+ **ICM replaces the KV-cache with a fixed-size hyperbolic state vector.** The state is **260 bytes** — regardless of whether the conversation is 10 turns or 10 million.
89
+
90
+ | Context Length | KV-cache (7B) | ICM State | Savings |
91
+ |:---|---:|---:|---:|
92
+ | 1K tokens | 2 MB | 260 B | **7,700x** |
93
+ | 100K tokens | 200 MB | 260 B | **770,000x** |
94
+ | 1M tokens | 2 GB | 260 B | **7,700,000x** |
95
+
96
+ ## How It Works
97
+
98
+ ```
99
+ User message ─► embed ─► hyperbolic map ─► Lorentz recurrence ─► O(1) state
100
+
101
+
102
+ multi-scale readout
103
+
104
+
105
+ bounded prompt ─► LLM ─► response ─► embed ─► loop
106
+ ```
107
+
108
+ 1. **Embed** each utterance via sentence-transformers (384-dim)
109
+ 2. **Compress** into hyperbolic space via exponential map — fused with current state via Lorentzian gated recurrence
110
+ 3. **Recall** at 4 geometric scales — from verbatim detail to abstract gist
111
+ 4. **Generate** with a bounded prompt — the LLM never sees the full history
112
+ 5. **Repeat** — the state stays **260 bytes forever**
113
+
114
+ The hyperbolic space (Lorentz model) has **exponential representational capacity** — a 64-dim hyperbolic vector can store exponentially more hierarchical structure than a 64-dim Euclidean vector (Gromov, 1987).
115
+
116
+ ## Quick Start
117
+
118
+ ```bash
119
+ # 1. Install
120
+ pip install -r requirements.txt
121
+
122
+ # 2. Verify O(1) memory (10 seconds)
123
+ python icm_demo.py
124
+
125
+ # 3. Chat in the terminal
126
+ python applications/cli_chat.py
127
+
128
+ # 4. Start the web server
129
+ python applications/icm_server.py
130
+ # → http://localhost:8000
131
+
132
+ # Or everything at once with Docker:
133
+ docker compose up -d
134
+ # → http://localhost:8000
135
+ ```
136
+
137
+ ```python
138
+ from hyper_ssm.llm_integration import IcmLlm
139
+
140
+ chat = IcmLlm(model_name="gpt2")
141
+ chat.create_session("alice")
142
+ reply = chat.chat("alice", "My name is Alice")
143
+ reply = chat.chat("alice", "What is my name?") # remembers!
144
+ # → "Your name is Alice"
145
+ ```
146
+
147
+ ### Stream tokens via WebSocket
148
+
149
+ ```javascript
150
+ const ws = new WebSocket("ws://localhost:8000/chat/ws");
151
+ ws.send(JSON.stringify({session_id: "my_session", message: "Hello!"}));
152
+ ws.onmessage = (e) => console.log(JSON.parse(e.data).token);
153
+ ```
154
+
155
+ ## Features
156
+
157
+ - **O(1) memory** — 260 bytes per session, never grows
158
+ - **Multi-scale readout** — 4 abstraction levels (detail → gist)
159
+ - **Zero training required** — works with any HuggingFace causal LM
160
+ - **Quantization** — 4-bit NF4 and 8-bit via bitsandbytes
161
+ - **Session persistence** — SQLite, survives server restarts
162
+ - **API key auth** — bearer-token auth + rate limiting
163
+ - **Streaming** — SSE and WebSocket endpoints
164
+ - **Export** — JSON and Markdown conversation export
165
+ - **Web UI** — dark-theme SPA, no build step
166
+ - **Admin dashboard** — system stats, session browser, model switch, API key management
167
+ - **Python SDK** — `icm_client.py` with full API coverage
168
+ - **Docker** — one-container deployment
169
+
170
+ ## Benchmarks
171
+
172
+ | Model | Memory | Time | Accuracy |
173
+ |:---|---:|---:|---:|
174
+ | **HHM (ICM)** | **O(1)** | **O(T)** | **98.4%** |
175
+ | Causal Attention | O(T²) | O(T²) | 100% |
176
+ | Mamba SSM | O(T) | O(T) | 72.3% |
177
+
178
+ *Benchmark: associative key-value retrieval at N=256 pairs on random vectors (see `benchmark_icm.py`).*
179
+
180
+ ### Memory vs Context Length
181
+
182
+ | Turns | KV-cache (7B) | ICM State | ICM Advantage |
183
+ |:---|---:|---:|---:|
184
+ | 10 | ~340 KB | 260 B | 1,300x |
185
+ | 118 | ~119 KB | 260 B | 468x |
186
+ | 1,000 | ~2 MB | 260 B | 7,700x |
187
+ | 100,000 | ~200 MB | 260 B | 770,000x |
188
+ | 1,000,000 | ~2 GB | 260 B | 7,700,000x |
189
+
190
+ ## API Overview
191
+
192
+ ```bash
193
+ # Health check
194
+ GET /health
195
+
196
+ # Chat (streaming via SSE)
197
+ GET /chat/stream?session_id=abc&message=Hello
198
+
199
+ # Chat (streaming via WebSocket)
200
+ WS /chat/ws
201
+
202
+ # Session management
203
+ POST /sessions
204
+ GET /sessions
205
+ GET /sessions/{id}
206
+ DELETE /sessions/{id}
207
+
208
+ # Conversation export
209
+ GET /sessions/{id}/export/json
210
+ GET /sessions/{id}/export/markdown
211
+
212
+ # Admin
213
+ GET /admin
214
+ GET /admin/stats
215
+ GET /admin/presets
216
+ POST /admin/model
217
+ GET /admin/keys
218
+ POST /admin/keys
219
+ ```
220
+
221
+ See the [full API docs](http://localhost:8000/docs) (available when the server is running).
222
+
223
+ ## Architecture
224
+
225
+ ```
226
+ ┌──────────────────────┐
227
+ │ HuggingFace LLM │
228
+ │ (GPT-2, Qwen, etc) │
229
+ └──────────┬───────────┘
230
+
231
+ ┌──────────▼───────────┐
232
+ │ IcmLlm │
233
+ │ (session mgmt, │
234
+ │ quantization, │
235
+ │ auto-save) │
236
+ └──────────┬───────────┘
237
+
238
+ ┌────────────────▼────────────────┐
239
+ │ InfiniteContextMemory │
240
+ │ ┌──────────────────────────┐ │
241
+ │ │ HierarchicalHyperbolicMem │ │
242
+ │ │ • Lorentz recurrence │ │
243
+ │ │ • Multi-scale readout │ │
244
+ │ │ • O(1) state (260 B) │ │
245
+ │ └──────────────────────────┘ │
246
+ └────────────────┬────────────────┘
247
+
248
+ ┌──────────▼───────────┐
249
+ │ FastAPI Server │
250
+ │ REST + WebSocket │
251
+ │ Auth + Rate Limit │
252
+ │ SQLite Persistence │
253
+ └──────────────────────┘
254
+ ```
255
+
256
+ ## Validated Properties
257
+
258
+ | Property | Result |
259
+ |:---|---|
260
+ | Memory complexity | **O(1)** — 260 bytes for any sequence |
261
+ | Time complexity | **O(T)** — linear in sequence length |
262
+ | Manifold violation | **< 1e-6** over 100k+ Lorentz steps |
263
+ | Multi-scale readout | **4 abstraction levels** (detailed → moderate → abstract → gist) |
264
+ | Numerical stability | **Double-precision log/exp, 64-bit** |
265
+ | Model support | **Any HuggingFace causal LM** |
266
+ | Quantization | **4-bit NF4, 8-bit** (bitsandbytes) |
267
+ | Session persistence | **SQLite WAL mode** — survives restarts |
268
+ | Auth | **Bearer token + sliding-window rate limiter** |
269
+ | Tests | **68 passing** (unit + integration) |
270
+
271
+ ## Deployment
272
+
273
+ ### Docker (recommended)
274
+
275
+ ```bash
276
+ # One command — full stack with health checks, volumes, restart
277
+ docker compose up -d
278
+ open http://localhost:8000
279
+ ```
280
+
281
+ ### Docker (manual)
282
+
283
+ ```bash
284
+ docker build -t icm-server .
285
+ docker run -p 8000:8000 -v icm-data:/app/data icm-server
286
+ ```
287
+
288
+ ### Production
289
+
290
+ ```bash
291
+ python applications/icm_server.py \
292
+ --model-name Qwen/Qwen2.5-0.5B \
293
+ --quantize-bits 4 \
294
+ --auth-enabled \
295
+ --sqlite-path sessions.db
296
+ ```
297
+
298
+ Then use the admin dashboard at `http://localhost:8000/admin` to manage keys, switch models, and browse sessions.
299
+
300
+ ## Project Structure
301
+
302
+ ```
303
+ icm/ # Core library
304
+ ├── hyper_ssm/
305
+ │ ├── hierarchical_memory.py # HHM — O(1) Lorentz recurrence
306
+ │ ├── conversation_memory.py # ICM — ChatSession, RAGStore
307
+ │ ├── llm_integration.py # IcmLlm — HF model wrapper
308
+ │ ├── session_store.py # SQLite persistence
309
+ │ └── auth.py # API key auth + rate limiter
310
+ ├── applications/
311
+ │ ├── icm_server.py # FastAPI server
312
+ │ ├── cli_chat.py # Interactive CLI
313
+ │ ├── static/
314
+ │ │ ├── index.html # Web UI
315
+ │ │ └── admin.html # Admin dashboard
316
+ │ └── infinite_chat_demo.py # 118-turn demo
317
+ ├── icm_client.py # Python SDK
318
+ ├── icm_config.py # YAML/env/CLI config
319
+ ├── tests/
320
+ │ └── test_icm.py # 68 tests
321
+ ├── benchmark_icm.py # Long-context benchmark
322
+ ├── Dockerfile # Container deploy
323
+ └── README.md
324
+ ```
325
+
326
+ ## Research Foundation
327
+
328
+ ICM is built on Hierarchical Hyperbolic Memory (HHM), a novel architecture that uses Lorentzian geometry to achieve O(1) sequence memory. Key theoretical results:
329
+
330
+ - The Lorentz model of hyperbolic space has **exponential representational capacity** — formalized by Gromov's theorem (1987)
331
+ - The **exponential map** provides a stable bijection between Euclidean tangent space and the hyperboloid — enabling gradient-based optimization
332
+ - **Hierarchical readout** at multiple geodesic distances extracts information at every abstraction level simultaneously
333
+ - The **gated Lorentzian recurrence** provably preserves the manifold constraint (< 1e-6 violation over 100k+ steps)
334
+
335
+ For a detailed explanation, see the [research paper](research_paper.md) and the [implementer's guide](HYPER_SSM_2026_ULTIMATE.md).
336
+
337
+ ## License
338
+
339
+ Apache 2.0