À propos
Your LLM's chat memory lives on the SSD, not in RAM. Drop-in for Ollama: flat RAM as chats grow.
IA et apprentissage automatiqueProgression mesurée des étoiles
- in 24h
- 0
- in 7 days
- Historique en cours
- in 15 days
- Historique en cours
- in 1 month
- Historique en cours
Variations nettes sur des périodes qui se chevauchent, pas des totaux quotidiens. Les mesures absentes restent vides. Les étoiles indiquent l’intérêt, pas la qualité.
README.md
OriginalLoft
Your LLM's chat memory lives on the SSD, not in RAM. RAM stays flat however long the chat gets.

On a 16 GB MacBook Air, a 30,000-token chat makes stock Ollama use +3.2 GB of extra RAM and take 144 s per answer. Put Loft in front of the same Ollama model (same weights, unquantized) and the chat moves to the SSD. Only about 1.1 MB of index stays in RAM, answers take 1.8 s, and it gets 81% of questions right versus 62%.
Loft works with models you already have. It is a drop-in server for anything that talks to Ollama, and it also runs in front of llama.cpp, LM Studio, vLLM or Colibri.
pip install "git+https://github.com/DaniyalBaluwala/loft"
loft serve --ollama qwen3:8b # Loft listens on :11435 and uses your Ollama underneath
# point any Ollama client/app at http://127.0.0.1:11435 instead of :11434, e.g.
curl localhost:11435/api/generate -d '{"prompt": "<your long chat>... Question: ...", "stream": false}'
Or the easy way: just chat in your terminal. No server, no second terminal:
loft # chat with your local Ollama model, Loft memory underneath
loft chat notes.txt # start the chat with a long file loaded
loft ask notes.txt "What is the vault password?" --compare # one answer, plus stock Ollama side by side
Results
Measured on an M2 MacBook Air with 16 GB of RAM, using Qwen3-1.7B-Base at full precision (no quantization) for every system. All systems answered the same sealed test questions. The tests were built and hashed before any system was run on them, and nothing was tuned on them. Scores are exact match.

Demo: one chat grows from 2k to 30k tokens. At each step, the same question is asked and RAM and answer time are measured
(bench/demo_memory.py); the animation replays those readings. The dip at ~17k tokens is real: Ollama reset its cache and
re-read the chat. Note: this demo's single code-completion question from the very start of the chat was one of Loft's weak
spots. Loft answered it right at 5 of the 14 steps, versus 10 for stock. The accuracy numbers below come from the full 48-question set.
| Stock Ollama | Loft on Ollama | Loft on Ollama, no tokenizer¹ | Loft + Colibri² | |
|---|---|---|---|---|
| Long chats (7k–30k tokens), right answers | 62% (30/48) | 81% (39/48) | 85% (41/48) | 80% (32/40) |
| Short chats (80–1,000 tokens), right answers | 84% (300 q) | 78% | 79% | 77% (60 q) |
| RAM used while answering, 30k-token chat | 6.5 GB | 4.6 GB | 4.4 GB | 4.7 GB |
| Highest RAM at any point | 10.0 GB | 5.5 GB | 5.0 GB | 7.9 GB |
| Extra RAM over idle, 7k → 16k → 30k chat | +1.2 → +2.1 → +3.2 GB | +1.0 → +0.8 → +1.0 GB | +0.4 → +0.7 → +0.8 GB | |
| Chat state held in RAM, 30k-token chat | 3.2 GB of KV cache | 1.1 MB index | 0.9 MB | |
| Seconds per answer, 30k-token chat (median) | 144 s | 1.8 s | 2.1 s | ~61 s |
¹ The setup anyone with any Ollama model gets: Loft splits text itself, without the model's tokenizer. ² Colibri runs unquantized models on the CPU only, so it's slow here. The run was stopped before the last 30k-token chat, so its long-chat score covers 5 of the 6 chats.
Native mode (loft serve --hf ...: Loft runs the Hugging Face model itself with PyTorch, and the full KV cache goes to the SSD):
| Stock Ollama | Loft native | |
|---|---|---|
| Long chats, right answers | 62% (30/48) | 81% (39/48) |
| Short chats, right answers (same 60 questions) | 88% | 83% |
| RAM while answering, 30k-token chat | 6.5 GB | 4.3 GB (+0.2 GB over idle) |
| Chat state held in RAM, 30k-token chat | 3.2 GB of KV cache | 6.2 MB (window KV + index) |
| Seconds per answer, 30k-token chat | 144 s | 1.6 s |
| Highest RAM at any point | 10.0 GB | 11.0 GB, while first reading the chat |
Native mode reads each chat once to save its exact KV cache to the SSD. That takes about 6.5 minutes for 30k tokens on this laptop, and it causes the peak. Proxy mode never builds that backup, so its peak stays low.
Reading the numbers honestly
- RAM stops growing; it doesn't go to zero. Loft's extra RAM stayed under ~1 GB at every chat length: the model's working buffers for a short prompt, plus Loft's own process (its index grows by ~40 bytes per token). Stock Ollama's grows by about 112 KB for every token of chat on this model.
- Short chats are 5–6 points worse. When the whole chat fits easily, reading all of it is best.
--passthrough 2048sends chats up to 2,048 tokens unchanged, so for those Loft is identical to stock by construction. - Speed: on 7k–16k chats both take 1–2 s, because Ollama's prompt cache helps stock. At 30k tokens stock re-read the whole chat for each question in our runs.
- Why accuracy goes up: a small model gets lost in a 30k-token chat. Handing it only the relevant ~300 tokens helps.
- Small test: one small model, synthetic chats (records, code, reading questions), 48 long-chat questions. See Not done yet below.
What this means for bigger models (calculated, not measured)
For Llama-3.1-8B, the KV cache takes 128 KB per token: 4 GB at 32k tokens, 16 GB at 128k. Loft caps the model's context at a fixed 4,096 tokens (0.5 GB) and keeps the chat on the SSD. That freed RAM can hold a bigger or less-quantized model instead.
How it works
long chat ──► SSD (native mode: the full KV cache · proxy mode: the text)
│
└──► RAM: first 4 tokens + last ~28 tokens + a tiny word index (~1 MB per 30k tokens)
question ──► 1. cheap pass the question against the small RAM window only
2. checker tiny classifier: is that enough? (index match + model uncertainty)
3. fetch if not: pull the best-matching chunks (+ the chunk after each) from
the SSD, ~256 tokens, and answer from window + chunks + question
4. full reload (native, optional) unsure answer → load the WHOLE stored KV back
from the SSD: exactly the same as never having dropped it
| Part | What it does |
|---|---|
| Sink + recent window | The first and last few tokens stay in RAM, so the model keeps its footing. |
| SSD tier | The chat in 32-token chunks on disk, written and read past the OS page cache, so it really leaves RAM. |
| Word index | Per-chunk word and token sets with IDF scoring. About 40 bytes of RAM per chat token. |
| Checker | Logistic regression on 5 signals available before any disk read. Trained on separate training chats and shipped in loft/checker_default.json. On the long test chats it chose to fetch for 100% of questions. |
| Full KV reload | Native mode only: exact recovery from the SSD. Off by default, because tuning on validation chats showed retrieval was more accurate. |
| SSD scheduler | One priority queue for disk reads: chat chunks go ahead of model-weight streaming (for MoE engines such as Colibri). |
| Colibri patch | Makes Colibri's prefix store SSD-backed and frees KV memory after each turn. See colibri/. |
What's new here, and what isn't
Each piece has relatives: retrieval over chat history (RAG / MemGPT-style memory), attention sinks and sliding windows (StreamingLLM), and KV-cache offloading to CPU or disk (FlexGen, LMCache and others). Loft puts them together into one local system: a learned checker decides per question whether the in-RAM window is enough; the full KV cache stays on the SSD for exact recovery; a shared SSD scheduler serves both chat memory and MoE weight streaming; and it all runs as a drop-in for the Ollama API, with measured process memory on a laptop.
Not done yet (help welcome):
- Standard long-context benchmarks: LongBench, RULER, needle-in-a-haystack.
- Head-to-head comparisons with related systems such as Cache2LoRA and VeriCache.
- Models other than Qwen3-1.7B, Linux/CUDA numbers, and real chat transcripts.
- Chat-style
/api/chaton instruction models works but hasn't been benchmarked. - Native mode supports standard-attention models. For sliding-window or hybrid models, use proxy mode.
Terminal chat (the easy way)
Type loft and you're in a chat, like Claude Code's CLI. Loft picks your first local Ollama
model (cloud models are skipped, so nothing leaves your machine). Every turn, and every file you load,
becomes one long conversation that Loft keeps on the SSD.
+==================================================================+
| _.-''''''''''-._ |
| .-' '-. |
| .' ~~ ~~ '. |
| / \ |
| | _.---. .---._ | |
| @@@@@| __/ ___ \__/ ___ \__ |@@@@@ |
| @@&@@@|==| / o \ / o \ |==|@@@&@@ |
| @@@@&@| | \___/ __ \___/ | |@&@@@@ |
| @@&@@ \ '-.____.-/ \-.____.-' / @@&@@ |
| @@@@ | ( .. ) | @@@@ |
| |\ __ '----' __ /| |
| @|@\ .-~~~~~~~~~~~~~~-. /@|@ |
| @@&@@@@\'~~~~~~~~~~~~~~~~'/@@@@&@@ |
| @@@&@@@@@@&&@@@@&@@@@&&@@@@@@&@@@@@ |
| @&@@@1@@&@@0@@@&@@1@@@&@@@0@@&@@1@@@& |
| @@@0@@&@@@1@@&@@@0@@@&@@1@@@&@@0@@@@@ |
| @&@@@@1@@&@@@0@@@&@@1@@@&@@0@@@&@@@ |
| @@@&@@@@0@@&@@@1@@@&@@0@@@&@@@@@@ |
| @@&@@@@1@@@&@@0@@@&@@1@@@&@@@ |
| @@@&@@@@0@@&@@@1@@@&@@@@@ |
| @@@&@@@@@&@@@@@&@@@@ |
| @@@&@@@@@&@@ |
| @@@&@@ |
| _______|__|_______ |
| / S O K R A T E S \ |
| /____________________\ |
| |
| "I know that I know nothing." -- root@agora:~$ _ |
| |
| /\/\/\/\/\/\/\/\/\/\/\/\ |
| | | ( ) ( ) ) |
| | >_ CHIPS.EXE | ) ( ) ( ( |
| | [ spicy_payload ] | ( ) ( ) ) |
| | | _______________ |
| | .~~~. .~~~~. | <_______________> ___ |
| | .~~~~~~.~~~~~~~~. | | |/ _ \ |
| | (~~~~~~~~~~~~~~~~~) | | $ sudo | | | | |
| | '~~~~~~~~~~~~~~~' | | brew |_| | | |
| | | | --strong |\___/ |
| | crunch_lvl: 1337 | | | |
| | status: ROOTED | \_____________/ |
| \/\/\/\/\/\/\/\/\/\/\/\/ \___________________/ |
| |
| >> the unexamined code is not worth running << |
+==================================================================+
› /load notes.txt
✓ loaded notes.txt: 11,100 tokens in 0.0s, now on the SSD
› What is the vault password?
◆ The vault password is Blue-Falcon-42.
⚡ 3.5s · model read 791 of 11,213 tokens · chat in RAM 554 KB · full KV would be 1.2 GB · pulled 8 chunks from SSD
| Command | What it does |
|---|---|
/load file.txt |
add a file to the conversation (stored on the SSD) |
/stats |
what Loft keeps in RAM vs on the SSD |
/compare |
also ask stock Ollama with the whole conversation, and show its answer and time |
/model NAME, /models |
switch or list models (cloud models are flagged) |
/clear, /save FILE, /exit |
new conversation, save it, quit (or Ctrl+D) |
The chat keeps the last 512 tokens in RAM so follow-ups work, and conversations under 2,048 tokens are
sent whole (exactly like plain Ollama). Use a chat/instruct model (e.g. ollama pull qwen3:4b) for
an assistant; base models just continue text. --no-logo hides the logo.
Usage
# Server for apps (Ollama-compatible API on :11435). Proxy mode: in front of a server you already run
loft serve --ollama llama3.1:8b # Ollama
loft serve --openai my-model --backend-url http://127.0.0.1:8080 # llama.cpp / LM Studio / vLLM / Colibri
# --ctx 4096 context the backend runs with (sets its RAM)
# --tokenizer ID the model's Hugging Face tokenizer (optional)
# --passthrough N chats up to N tokens are sent unchanged
# Native mode: Loft runs the model, full KV cache on the SSD (CUDA / Apple Silicon / CPU)
pip install "loft-llm[native] @ git+https://github.com/DaniyalBaluwala/loft"
loft serve --hf Qwen/Qwen3-1.7B-Base
Then use it like Ollama: POST /api/generate, POST /api/chat. GET /loft/stats shows what each chat
keeps in RAM. Chats are stored under ~/.loft.
Reproduce the benchmark
loft serve --ollama qwen3-1.7b-base-f16 --ctx 4096 --port 11437
python bench/bench.py loft_ollama # and: python bench/bench.py stock
python bench/make_charts.py # charts + bench/results/summary.json
The sealed test sets and their SHA-256 hashes are in bench/data/. Raw per-question results are in bench/results/.
License
Free and open source under the GNU AGPL-3.0: use it, study it, change it, share it. Companies that want to ship Loft in a closed-source product can buy a commercial license; see COMMERCIAL.md. The Colibri patch stays under Colibri's Apache-2.0 license.
Created by Daniyal Baluwala: the tiered-memory design, the checker, the SSD tier and the Colibri integration.
Explorer des projets similaires
Chargement…