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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Plan: 262K context on 6GB VRAM, matching Claude
|
| 2 |
+
|
| 3 |
+
**Goal.** `recursion + local model == frontier model`, under one hard constraint:
|
| 4 |
+
**6GB VRAM**. Parameter count is NOT constrained -- a 35B model whose experts stream
|
| 5 |
+
from system RAM is in scope, because only its resident footprint has to fit.
|
| 6 |
+
|
| 7 |
+
This was initially mis-scoped as "small model", which pushed everything toward 2-4B
|
| 8 |
+
models and made capability the bottleneck. The constraint is VRAM alone.
|
| 9 |
+
|
| 10 |
+
Two independent claims. Keeping them separate matters, because one is proven and
|
| 11 |
+
one is not:
|
| 12 |
+
|
| 13 |
+
| claim | status |
|
| 14 |
+
|---|---|
|
| 15 |
+
| A. 262K of context served within 6GB VRAM | **proven, reproduced 4x** |
|
| 16 |
+
| B. ...and it produces the correct answer | **MET** via ctxstream (2026-08-24) |
|
| 17 |
+
|
| 18 |
+
**Claim B was closed by removing the model from the aggregation step, not by a
|
| 19 |
+
bigger model.** See "How claim B was actually met" below. The MoE expert-offload
|
| 20 |
+
work is no longer on the critical path for correctness; it remains the route to
|
| 21 |
+
higher-quality *extraction* per fragment.
|
| 22 |
+
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
## Hardware
|
| 26 |
+
|
| 27 |
+
| machine | GPU | role |
|
| 28 |
+
|---|---|---|
|
| 29 |
+
| desktop | RTX 3080 20GB + Tesla P100 16GB | orchestration, Claude CLI, dev |
|
| 30 |
+
| `rickesh-Laptop` @ `10.147.20.104` | **RTX 3060 Laptop, 6144 MiB**, 62GB RAM | the constraint; all VRAM claims measured here |
|
| 31 |
+
|
| 32 |
+
The laptop runs Ollama 0.32.15 in a container (`ollama-bench`, reversible, no
|
| 33 |
+
system install). The desktop reaches it via
|
| 34 |
+
`ssh -f -N -L 11436:127.0.0.1:11434 rickesh@10.147.20.104`, so candidate runs use
|
| 35 |
+
the 3060 while the desktop GPU stays free. Set
|
| 36 |
+
`RLM_TEST_OLLAMA_URL=http://127.0.0.1:11436`.
|
| 37 |
+
|
| 38 |
+
---
|
| 39 |
+
|
| 40 |
+
## What is measured
|
| 41 |
+
|
| 42 |
+
**VRAM vs context on the 6GB card** (flash-attn + `q8_0` KV, matching the desktop
|
| 43 |
+
service config — without those the KV blows up and the direct arm is unfairly
|
| 44 |
+
handicapped):
|
| 45 |
+
|
| 46 |
+
| `num_ctx` | footprint | fits 5.5GB usable |
|
| 47 |
+
|---:|---:|:---:|
|
| 48 |
+
| 8,192 | 3.2 GB | yes |
|
| 49 |
+
| 16,384 | 3.3 GB | yes |
|
| 50 |
+
| **32,768** | **3.3 GB** | **yes — the ceiling** |
|
| 51 |
+
| 65,536 | 10.4 GB | no (31% GPU) |
|
| 52 |
+
| 131,072 | 10.9 GB | no (28% GPU) |
|
| 53 |
+
|
| 54 |
+
KV is nearly free to 32k, then the allocator falls off a cliff. **Direct maxes at
|
| 55 |
+
32,768 tokens.**
|
| 56 |
+
|
| 57 |
+
**RLM at 261,226 tokens on that card:** peak **4.23 / 4.24 / 4.25 GB** across three
|
| 58 |
+
runs. Fits, with ~1.2GB headroom. VRAM is flat in total context because the corpus
|
| 59 |
+
lives in CPU RAM as a REPL string and only chunk-sized slices reach the KV cache.
|
| 60 |
+
That is an **8x context multiple at constant VRAM**.
|
| 61 |
+
|
| 62 |
+
**Model ceilings.** `gemma4:e4b` = 131,072; `qwen3:4b` = 262,144 trained context.
|
| 63 |
+
1M is not reachable with these weights — that was the Claude `[1m]` variants, not
|
| 64 |
+
local GGUF.
|
| 65 |
+
|
| 66 |
+
**6GB-class candidates** (32k ctx, measured):
|
| 67 |
+
|
| 68 |
+
| model | footprint | fits 6GB | tool_ok |
|
| 69 |
+
|---|---:|:---:|---:|
|
| 70 |
+
| Gemma 4 E2B q4_0 | 1.8 GB | yes | 0.95 |
|
| 71 |
+
| **Gemma 4 E4B** | **3.5 GB** | yes | 0.90 |
|
| 72 |
+
| Qwen3 4B | 5.3 GB | marginal | 0.65 |
|
| 73 |
+
| Ornith 1.5 9B Q4_K_M | 6.2 GB | **no** | 0.95 |
|
| 74 |
+
|
| 75 |
+
E4B's 9.6GB GGUF is only 3.5GB resident (MatFormer / per-layer embeddings) — file
|
| 76 |
+
size badly overestimates VRAM here.
|
| 77 |
+
|
| 78 |
+
---
|
| 79 |
+
|
| 80 |
+
## What failed, and why it matters
|
| 81 |
+
|
| 82 |
+
**The reference is not a reliable oracle at this size.** Opus 4.8 [1m] over 439,742
|
| 83 |
+
tokens answered the *same* question two different ways on byte-identical input
|
| 84 |
+
(`Spatial Relationship` correct, `Normal scene Understanding` wrong), and is 2/3
|
| 85 |
+
across three samples. Ground truth must come from Python, with Opus scored as a
|
| 86 |
+
candidate. `bench/reference_reliability.py` quantifies this; it is cost-capped
|
| 87 |
+
because a call is $0.26 warm and $4.79 cold.
|
| 88 |
+
|
| 89 |
+
**The candidate's failure moved three times as plumbing was fixed:**
|
| 90 |
+
|
| 91 |
+
| attempt | calls | answer | defect |
|
| 92 |
+
|---|---:|---|---|
|
| 93 |
+
| 1 | 7 | prose | read ~33% of corpus |
|
| 94 |
+
| 2 | 11 | `Category: Spatial` | correct arithmetic, truncated label |
|
| 95 |
+
| 3 | **65** | `Category: Counterfactual` | swept corpus, well-formed, **wrong** |
|
| 96 |
+
|
| 97 |
+
Attempt 3 consumed 425,054 input tokens — it genuinely read everything and answered
|
| 98 |
+
in the required format. **The remaining gap is aggregation accuracy: a 4B correctly
|
| 99 |
+
combining 65 chunk-level counts.** That is a capability question, not plumbing.
|
| 100 |
+
|
| 101 |
+
### Guards added (none leak the answer)
|
| 102 |
+
|
| 103 |
+
| guard | catches |
|
| 104 |
+
|---|---|
|
| 105 |
+
| `require_repl` | answering from an empty REPL (measured: 1 call, pure guess) |
|
| 106 |
+
| `min_coverage=0.8` | answering from a partial read |
|
| 107 |
+
| `max_answer_chars` | returning the corpus instead of an answer |
|
| 108 |
+
| placeholder check | returning `Label: [least_common_status]` unsubstituted |
|
| 109 |
+
| `ContextTruncated` | Ollama silently clipping 50k→16,387 tokens |
|
| 110 |
+
| `QuotaExhausted` | rate limits scored as wrong answers |
|
| 111 |
+
|
| 112 |
+
`map_chunks(question)` was added to the REPL: it splits the entire context and
|
| 113 |
+
queries every chunk concurrently, collapsing the chunk-and-loop code a 4B fails to
|
| 114 |
+
write. It moved sub-calls from 17 → 75 and *reduced* wall-clock 16.6m → 7.8m.
|
| 115 |
+
|
| 116 |
+
### Scoring traps hit (both fixed)
|
| 117 |
+
|
| 118 |
+
- `gold in answer` passed a raw corpus dump because the dump contained the gold
|
| 119 |
+
label. Strict scorers now reject replies with >2 ` || ` separators or over a
|
| 120 |
+
length bound; the dump is a regression test.
|
| 121 |
+
- Caching a single sample of a non-deterministic reference froze a *wrong* answer
|
| 122 |
+
as the oracle. The cache is now keyed on
|
| 123 |
+
`sha256(model + instruction + context)`, so any change invalidates it.
|
| 124 |
+
|
| 125 |
+
---
|
| 126 |
+
|
| 127 |
+
## Remaining work
|
| 128 |
+
|
| 129 |
+
1. **Close claim B.** The candidate sweeps correctly but aggregates wrong. Options,
|
| 130 |
+
cheapest first:
|
| 131 |
+
- Make chunk-level output machine-parseable (ask each chunk for strict
|
| 132 |
+
`label<TAB>count` lines) and aggregate in Python rather than trusting the
|
| 133 |
+
model to combine 65 prose summaries.
|
| 134 |
+
- Try E2B and Ornith 9B as the *root* (both scored 0.95 on tool behaviour vs
|
| 135 |
+
E4B's 0.90); Ornith needs a card above 6GB or a smaller quant.
|
| 136 |
+
- Root = Sonnet/Opus with sub-calls on the local 4B — the paper's own
|
| 137 |
+
BrowseComp arrangement, untested here.
|
| 138 |
+
2. **Terminal-Bench baselines** — never produced a valid run. The ufw rule
|
| 139 |
+
(`sudo ufw allow from 172.16.0.0/12 to any port 11435 proto tcp`) is in place and
|
| 140 |
+
the bridge works; the suite needs re-running for E2B / E4B / Qwen3-4B.
|
| 141 |
+
3. **Quantify reference reliability** — run `bench/reference_reliability.py` for N
|
| 142 |
+
samples to put a number on Opus's instability at 440k.
|
| 143 |
+
4. **Decide the finetune** — nothing is trained yet. Base and training data are
|
| 144 |
+
both open (see below).
|
| 145 |
+
5. **MoE expert-offload — see the dedicated section below. This is the main line.**
|
| 146 |
+
|
| 147 |
+
---
|
| 148 |
+
|
| 149 |
+
## How claim B was actually met
|
| 150 |
+
|
| 151 |
+
`~/Projects/ctxstream` (C++17, zero third-party deps). The corpus is treated like
|
| 152 |
+
a video stream, and the model is removed from every step it was failing:
|
| 153 |
+
|
| 154 |
+
| video | ctxstream |
|
| 155 |
+
|---|---|
|
| 156 |
+
| manifest | segment plan, computed in code before any model call |
|
| 157 |
+
| buffer | N segments in flight |
|
| 158 |
+
| decoder | model sees ONE segment, emits `key<TAB>number`, never prose |
|
| 159 |
+
| playback | reduce — aggregation in code, strategy chosen explicitly |
|
| 160 |
+
|
| 161 |
+
Result on the 957,493-char imagined-risk corpus — the exact task that defeated
|
| 162 |
+
every earlier attempt, same 4B, same RTX 3060:
|
| 163 |
+
|
| 164 |
+
17 segments · failed=0 · records=611 · unparsed_lines=3 · keys=15 · 641s
|
| 165 |
+
Category: Spatial Relationship <- gold, correct
|
| 166 |
+
|
| 167 |
+
Opus 4.8 [1m] on the same corpus: 2/3 correct, self-inconsistent on byte-identical
|
| 168 |
+
input, $4.79/call. The 4B on a 6GB laptop: correct, $0.00.
|
| 169 |
+
|
| 170 |
+
Still to confirm: the same pipeline against the full 262,144-token synthetic
|
| 171 |
+
ledger used by `bench/rlm_262k.py`, to show it holds at that size too.
|
| 172 |
+
|
| 173 |
+
---
|
| 174 |
+
|
| 175 |
+
## Main line: frontier-class quality inside 6GB via MoE expert-offload
|
| 176 |
+
|
| 177 |
+
The constraint is VRAM, not parameters. A Mixture-of-Experts model can put nearly
|
| 178 |
+
all of its weight in system RAM and keep only the always-active tensors resident,
|
| 179 |
+
so **35B-class quality is reachable inside 6GB**. This attacks the actual blocker
|
| 180 |
+
directly: a 4B cannot aggregate 65 chunk-level summaries; a 35B-A3B plausibly can.
|
| 181 |
+
|
| 182 |
+
### The candidate
|
| 183 |
+
|
| 184 |
+
`ornith-ai/Ornith-1.5-35B-A3B` (`Qwen3_5MoeForConditionalGeneration`), Q4_K_M =
|
| 185 |
+
21.7GB on disk. From its config: **40 layers, 256 experts, top-8 per token**,
|
| 186 |
+
`moe_intermediate_size` 512, and **30 of 40 layers use linear attention** (only 10
|
| 187 |
+
are full attention).
|
| 188 |
+
|
| 189 |
+
| component | params | ~Q4 size | placement |
|
| 190 |
+
|---|---:|---:|---|
|
| 191 |
+
| experts (256 x 3 x 2048 x 512 x 40) | ~32.2B | ~19.3 GB | **CPU RAM** |
|
| 192 |
+
| attention + embeddings + router + shared experts | ~1.7B | **~1.2 GB** | **GPU** |
|
| 193 |
+
|
| 194 |
+
Two properties make this unusually favourable: experts are tiny and fine-grained
|
| 195 |
+
(~1.9 MB each), and the 3:1 linear-attention ratio makes the KV cache far smaller
|
| 196 |
+
than a normal 35B — so long contexts cost little VRAM.
|
| 197 |
+
|
| 198 |
+
Laptop capacity as measured: **51 GB RAM available, 483 GB disk, 5.8 GB free VRAM.**
|
| 199 |
+
The 21.7 GB of experts fit in RAM with room to spare.
|
| 200 |
+
|
| 201 |
+
### Tooling
|
| 202 |
+
|
| 203 |
+
**Ollama cannot do this** — it exposes only `num_gpu` (a layer count), which would
|
| 204 |
+
naively push ~75% of layers to CPU including attention. The local llama.cpp build
|
| 205 |
+
already has the right flags:
|
| 206 |
+
|
| 207 |
+
-cmoe, --cpu-moe keep ALL MoE weights on CPU
|
| 208 |
+
-ncmoe, --n-cpu-moe N keep MoE weights of the first N layers on CPU
|
| 209 |
+
-ot, --override-tensor per-tensor placement by regex
|
| 210 |
+
|
| 211 |
+
`ghcr.io/ggml-org/llama.cpp:server-cuda` avoids building on the laptop.
|
| 212 |
+
|
| 213 |
+
### Steps
|
| 214 |
+
|
| 215 |
+
1. Pull `Ornith-1.5-35B-Q4_K_M.gguf` (21.7GB) to the laptop.
|
| 216 |
+
2. Run `llama-server` with `--n-gpu-layers 99 -cmoe`, so every layer's attention is
|
| 217 |
+
on GPU and every expert FFN is on CPU. Measure resident VRAM; tune with
|
| 218 |
+
`-ncmoe N` if there is headroom left under 6GB.
|
| 219 |
+
3. Add an OpenAI-compatible backend to `rlm_haiku/utils/llm.py` — llama-server
|
| 220 |
+
serves `/v1/chat/completions`, not Ollama's `/api/chat`. Keep the
|
| 221 |
+
`ContextTruncated` check: it needs a processed-token count from the response.
|
| 222 |
+
4. Re-run the equivalence test with this as the RLM **root** (sub-calls can stay on
|
| 223 |
+
a cheap fast model, which is the paper's own BrowseComp arrangement).
|
| 224 |
+
|
| 225 |
+
### Known cost, stated up front
|
| 226 |
+
|
| 227 |
+
Expert streaming is memory-bandwidth-bound. Only ~3B params are active per token,
|
| 228 |
+
but a *different* ~600 MB of experts is touched every token, so throughput is set
|
| 229 |
+
by RAM bandwidth rather than compute — expect single-digit to low-double-digit
|
| 230 |
+
tokens/sec on a laptop. RLM multiplies that by ~65 sub-calls plus ~325k tokens of
|
| 231 |
+
prefill across chunks. **Minutes becomes tens of minutes to hours.** If quality
|
| 232 |
+
parity lands, that is the trade: VRAM and quality bought with wall-clock.
|
| 233 |
+
|
| 234 |
+
Fallbacks if throughput is unusable: `-ncmoe N` to pin as many expert layers on GPU
|
| 235 |
+
as fit (~4 GB spare / 1.9 MB per expert ~= 2,100 of 10,240 slots, so roughly 20%
|
| 236 |
+
resident); or a smaller MoE. True per-token LRU expert paging is what would help
|
| 237 |
+
most, and llama.cpp does not implement it (ktransformers, MoE-Infinity do).
|
| 238 |
+
|
| 239 |
+
## Open decisions
|
| 240 |
+
|
| 241 |
+
- **Finetune base and data.** Deferred pending baselines. Worth knowing:
|
| 242 |
+
`empero-ai/Qwable-9B-Claude-Fable-5` already exists — Qwen3.5-9B fully fine-tuned
|
| 243 |
+
on Fable-5 traces + `gpt5.5-terminal`, tagged `agentic-coding`. That is close to
|
| 244 |
+
what we were going to build; evaluate it before training anything.
|
| 245 |
+
- **Release scope.** `Rickesh/rlm-oolong-reproduction` is published (harness +
|
| 246 |
+
results, MIT, no weights). Nothing is trained, so there is no model release yet.
|
| 247 |
+
Ollama.com namespace is separate from HF and needs your handle.
|
| 248 |
+
|
| 249 |
+
## Non-obvious findings worth keeping
|
| 250 |
+
|
| 251 |
+
- Ollama auto-sizes context to the prompt up to a ceiling, then **silently** falls
|
| 252 |
+
back: 30,021 tokens pass intact, 50k and 70k both clip to exactly 16,387, with no
|
| 253 |
+
error. `num_ctx` is **ignored** on the Anthropic-compatible `/v1/messages` and
|
| 254 |
+
honoured on native `/api/chat`, which is also the only route reporting
|
| 255 |
+
`prompt_eval_count` — the thing that makes truncation detectable.
|
| 256 |
+
- Terminal-Bench puts each task on its own compose network, so firewall rules
|
| 257 |
+
scoped to `docker0` do not match. Scope by source subnet.
|
| 258 |
+
- RLM *hurts* when the context fits the window: OOLONG-131k, Haiku, 0.269 recursive
|
| 259 |
+
vs 0.428 direct. It only pays when the context does not fit.
|
| 260 |
+
- The "behave like Claude" system prompt bought **zero** tool-selection accuracy
|
| 261 |
+
across 4 models (deltas 0.00 / 0.00 / -0.05 / -0.05) while halving output tokens.
|
| 262 |
+
|
| 263 |
+
## Running things
|
| 264 |
+
|
| 265 |
+
```bash
|
| 266 |
+
# fast checks, no model calls
|
| 267 |
+
python -m pytest tests/test_equivalence.py -v
|
| 268 |
+
|
| 269 |
+
# equivalence, candidate on the 3060 (reference is cached; $0)
|
| 270 |
+
RLM_TEST_OLLAMA_URL=http://127.0.0.1:11436 \
|
| 271 |
+
python -m pytest tests/test_equivalence.py -v -m integration -s
|
| 272 |
+
|
| 273 |
+
# 262k on the 6GB card (run ON the laptop)
|
| 274 |
+
python3 bench/rlm_262k.py --model gemma4:e4b --target-tokens 262144 \
|
| 275 |
+
--num-ctx 8192 --max-prompt-chars 20000 --workers 2
|
| 276 |
+
|
| 277 |
+
# VRAM curve
|
| 278 |
+
python3 bench/vram_curve.py --model gemma4:e4b --budget-gb 5.5
|
| 279 |
+
|
| 280 |
+
# ask a question about an oversized file with a local model
|
| 281 |
+
python3 rlm_ask.py --file huge.log --query "which error appears most often?"
|
| 282 |
+
```
|