Demo
Try ICM right now — 4 ways:
# One-liner to see O(1) memory in action:
pip install icm-llm && icm-demo
# Output: 260 bytes per turn — fixed, forever.
Why This Matters
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.
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.
| Context Length | KV-cache (7B) | ICM State | Savings |
|---|---|---|---|
| 1K tokens | 2 MB | 260 B | 7,700x |
| 100K tokens | 200 MB | 260 B | 770,000x |
| 1M tokens | 2 GB | 260 B | 7,700,000x |
How It Works
User message ─► embed ─► hyperbolic map ─► Lorentz recurrence ─► O(1) state
│
▼
multi-scale readout
│
▼
bounded prompt ─► LLM ─► response ─► embed ─► loop
- Embed each utterance via sentence-transformers (384-dim)
- Compress into hyperbolic space via exponential map — fused with current state via Lorentzian gated recurrence
- Recall at 4 geometric scales — from verbatim detail to abstract gist
- Generate with a bounded prompt — the LLM never sees the full history
- Repeat — the state stays 260 bytes forever
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).
Quick Start
# 1. Install (60 seconds)
pip install icm-llm
# 2. Verify O(1) memory (10 seconds)
icm-demo
# 3. Chat in the terminal
icm-chat
# 4. Start the web server
icm-server
# → http://localhost:8000
# Or everything at once with Docker:
docker compose up -d
# → http://localhost:8000
from hyper_ssm.llm_integration import IcmLlm
chat = IcmLlm(model_name="gpt2")
chat.create_session("alice")
reply = chat.chat("alice", "My name is Alice")
reply = chat.chat("alice", "What is my name?") # remembers!
# → "Your name is Alice"
Stream tokens via WebSocket
const ws = new WebSocket("ws://localhost:8000/chat/ws");
ws.send(JSON.stringify({session_id: "my_session", message: "Hello!"}));
ws.onmessage = (e) => console.log(JSON.parse(e.data).token);
Features
- O(1) memory — 260 bytes per session, never grows
- Multi-scale readout — 4 abstraction levels (detail → gist)
- Zero training required — works with any HuggingFace causal LM
- Quantization — 4-bit NF4 and 8-bit via bitsandbytes
- Session persistence — SQLite, survives server restarts
- API key auth — bearer-token auth + rate limiting
- Streaming — SSE and WebSocket endpoints
- Export — JSON and Markdown conversation export
- Web UI — dark-theme SPA, no build step
- Admin dashboard — system stats, session browser, model switch, API key management
- Python SDK —
icm_client.pywith full API coverage - Docker — one-container deployment
Benchmarks
| Model | Memory | Time | Accuracy |
|---|---|---|---|
| HHM (ICM) | O(1) | O(T) | 98.4% |
| Causal Attention | O(T²) | O(T²) | 100% |
| Mamba SSM | O(T) | O(T) | 72.3% |
Benchmark: associative key-value retrieval at N=256 pairs on random vectors (see benchmark_icm.py).
Memory vs Context Length
| Turns | KV-cache (7B) | ICM State | ICM Advantage |
|---|---|---|---|
| 10 | ~340 KB | 260 B | 1,300x |
| 118 | ~119 KB | 260 B | 468x |
| 1,000 | ~2 MB | 260 B | 7,700x |
| 100,000 | ~200 MB | 260 B | 770,000x |
| 1,000,000 | ~2 GB | 260 B | 7,700,000x |
API Overview
# Health check
GET /health
# Chat (streaming via SSE)
GET /chat/stream?session_id=abc&message=Hello
# Chat (streaming via WebSocket)
WS /chat/ws
# Session management
POST /sessions
GET /sessions
GET /sessions/{id}
DELETE /sessions/{id}
# Conversation export
GET /sessions/{id}/export/json
GET /sessions/{id}/export/markdown
# Admin
GET /admin
GET /admin/stats
GET /admin/presets
POST /admin/model
GET /admin/keys
POST /admin/keys
See the full API docs (available when the server is running).
Architecture
┌──────────────────────┐
│ HuggingFace LLM │
│ (GPT-2, Qwen, etc) │
└──────────┬───────────┘
│
┌──────────▼───────────┐
│ IcmLlm │
│ (session mgmt, │
│ quantization, │
│ auto-save) │
└──────────┬───────────┘
│
┌────────────────▼────────────────┐
│ InfiniteContextMemory │
│ ┌──────────────────────────┐ │
│ │ HierarchicalHyperbolicMem │ │
│ │ • Lorentz recurrence │ │
│ │ • Multi-scale readout │ │
│ │ • O(1) state (260 B) │ │
│ └──────────────────────────┘ │
└────────────────┬────────────────┘
│
┌──────────▼───────────┐
│ FastAPI Server │
│ REST + WebSocket │
│ Auth + Rate Limit │
│ SQLite Persistence │
└──────────────────────┘
Validated Properties
| Property | Result |
|---|---|
| Memory complexity | O(1) — 260 bytes for any sequence |
| Time complexity | O(T) — linear in sequence length |
| Manifold violation | < 1e-6 over 100k+ Lorentz steps |
| Multi-scale readout | 4 abstraction levels (detailed → moderate → abstract → gist) |
| Numerical stability | Double-precision log/exp, 64-bit |
| Model support | Any HuggingFace causal LM |
| Quantization | 4-bit NF4, 8-bit (bitsandbytes) |
| Session persistence | SQLite WAL mode — survives restarts |
| Auth | Bearer token + sliding-window rate limiter |
| Tests | 68 passing (unit + integration) |
Deployment
Docker (recommended)
# One command — full stack with health checks, volumes, restart
docker compose up -d
open http://localhost:8000
Docker (manual)
docker build -t icm-server .
docker run -p 8000:8000 -v icm-data:/app/data icm-server
Production
python applications/icm_server.py \
--model-name Qwen/Qwen2.5-0.5B \
--quantize-bits 4 \
--auth-enabled \
--sqlite-path sessions.db
Then use the admin dashboard at http://localhost:8000/admin to manage keys, switch models, and browse sessions.
Project Structure
icm/ # Core library
├── hyper_ssm/
│ ├── hierarchical_memory.py # HHM — O(1) Lorentz recurrence
│ ├── conversation_memory.py # ICM — ChatSession, RAGStore
│ ├── llm_integration.py # IcmLlm — HF model wrapper
│ ├── session_store.py # SQLite persistence
│ └── auth.py # API key auth + rate limiter
├── applications/
│ ├── icm_server.py # FastAPI server
│ ├── cli_chat.py # Interactive CLI
│ ├── static/
│ │ ├── index.html # Web UI
│ │ └── admin.html # Admin dashboard
│ └── infinite_chat_demo.py # 118-turn demo
├── icm_client.py # Python SDK
├── icm_config.py # YAML/env/CLI config
├── tests/
│ └── test_icm.py # 68 tests
├── benchmark_icm.py # Long-context benchmark
├── Dockerfile # Container deploy
└── README.md
Research Foundation
ICM is built on Hierarchical Hyperbolic Memory (HHM), a novel architecture that uses Lorentzian geometry to achieve O(1) sequence memory. Key theoretical results:
- The Lorentz model of hyperbolic space has exponential representational capacity — formalized by Gromov's theorem (1987)
- The exponential map provides a stable bijection between Euclidean tangent space and the hyperboloid — enabling gradient-based optimization
- Hierarchical readout at multiple geodesic distances extracts information at every abstraction level simultaneously
- The gated Lorentzian recurrence provably preserves the manifold constraint (< 1e-6 violation over 100k+ steps)
For a detailed explanation, see the research paper and the implementer's guide.
License
Apache 2.0
Metadata
Release files for icm-llm 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| icm_llm-0.1.1.tar.gz | 95.4 kB | Without provenance | Details for icm_llm-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| icm_llm-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for icm_llm-0.1.1-py3-none-any.whl |
Total release size: 187.3 kB
Release files / icm_llm-0.1.1.tar.gz
| Download URL | icm_llm-0.1.1.tar.gz |
|---|---|
| Size | 95.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c11ec5f2c43a4ae44e2b48e6497f5e70875fef8c25399a7222cfe93a4e49ae7c
|
|
BLAKE2b-256 checksum How to use checksums |
6463c0bae75b6fa0513fd264aa66fb1af44aefc51853075e93e55922ad23fe27
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Release files / icm_llm-0.1.1-py3-none-any.whl
| Download URL | icm_llm-0.1.1-py3-none-any.whl |
|---|---|
| Size | 91.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
91778df9249d6ab0cc352f2e234270efb47392f34f889343b0974212722ee145
|
|
BLAKE2b-256 checksum How to use checksums |
fc886c7e582b178683ada12dab20e0769e69253a1c198a83c7efcf0829725236
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.3
|
Security for icm-llm 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.