Datasets:
Download PLAN-262k-on-6gb.md from Rickesh/rlm-oolong-reproduction: direct link, hf CLI and curl.
- Browser
- Download file 12.8 kB
-
https://huggingface.co/datasets/Rickesh/rlm-oolong-reproduction/resolve/main/PLAN-262k-on-6gb.md
- Command line
-
hf download hf://datasets/Rickesh/rlm-oolong-reproduction/PLAN-262k-on-6gb.md
-
curl -L -o PLAN-262k-on-6gb.md https://huggingface.co/datasets/Rickesh/rlm-oolong-reproduction/resolve/main/PLAN-262k-on-6gb.md
Plan: 262K context on 6GB VRAM, matching Claude
Goal. recursion + local model == frontier model, under one hard constraint:
6GB VRAM. Parameter count is NOT constrained -- a 35B model whose experts stream
from system RAM is in scope, because only its resident footprint has to fit.
This was initially mis-scoped as "small model", which pushed everything toward 2-4B models and made capability the bottleneck. The constraint is VRAM alone.
Two independent claims. Keeping them separate matters, because one is proven and one is not:
| claim | status |
|---|---|
| A. 262K of context served within 6GB VRAM | proven, reproduced 4x |
| B. ...and it produces the correct answer | MET via ctxstream (2026-08-24) |
Claim B was closed by removing the model from the aggregation step, not by a bigger model. See "How claim B was actually met" below. The MoE expert-offload work is no longer on the critical path for correctness; it remains the route to higher-quality extraction per fragment.
Hardware
| machine | GPU | role |
|---|---|---|
| desktop | RTX 3080 20GB + Tesla P100 16GB | orchestration, Claude CLI, dev |
rickesh-Laptop @ 10.147.20.104 |
RTX 3060 Laptop, 6144 MiB, 62GB RAM | the constraint; all VRAM claims measured here |
The laptop runs Ollama 0.32.15 in a container (ollama-bench, reversible, no
system install). The desktop reaches it via
ssh -f -N -L 11436:127.0.0.1:11434 rickesh@10.147.20.104, so candidate runs use
the 3060 while the desktop GPU stays free. Set
RLM_TEST_OLLAMA_URL=http://127.0.0.1:11436.
What is measured
VRAM vs context on the 6GB card (flash-attn + q8_0 KV, matching the desktop
service config — without those the KV blows up and the direct arm is unfairly
handicapped):
num_ctx |
footprint | fits 5.5GB usable |
|---|---|---|
| 8,192 | 3.2 GB | yes |
| 16,384 | 3.3 GB | yes |
| 32,768 | 3.3 GB | yes — the ceiling |
| 65,536 | 10.4 GB | no (31% GPU) |
| 131,072 | 10.9 GB | no (28% GPU) |
KV is nearly free to 32k, then the allocator falls off a cliff. Direct maxes at 32,768 tokens.
RLM at 261,226 tokens on that card: peak 4.23 / 4.24 / 4.25 GB across three runs. Fits, with ~1.2GB headroom. VRAM is flat in total context because the corpus lives in CPU RAM as a REPL string and only chunk-sized slices reach the KV cache. That is an 8x context multiple at constant VRAM.
Model ceilings. gemma4:e4b = 131,072; qwen3:4b = 262,144 trained context.
1M is not reachable with these weights — that was the Claude [1m] variants, not
local GGUF.
6GB-class candidates (32k ctx, measured):
| model | footprint | fits 6GB | tool_ok |
|---|---|---|---|
| Gemma 4 E2B q4_0 | 1.8 GB | yes | 0.95 |
| Gemma 4 E4B | 3.5 GB | yes | 0.90 |
| Qwen3 4B | 5.3 GB | marginal | 0.65 |
| Ornith 1.5 9B Q4_K_M | 6.2 GB | no | 0.95 |
E4B's 9.6GB GGUF is only 3.5GB resident (MatFormer / per-layer embeddings) — file size badly overestimates VRAM here.
What failed, and why it matters
The reference is not a reliable oracle at this size. Opus 4.8 [1m] over 439,742
tokens answered the same question two different ways on byte-identical input
(Spatial Relationship correct, Normal scene Understanding wrong), and is 2/3
across three samples. Ground truth must come from Python, with Opus scored as a
candidate. bench/reference_reliability.py quantifies this; it is cost-capped
because a call is $0.26 warm and $4.79 cold.
The candidate's failure moved three times as plumbing was fixed:
| attempt | calls | answer | defect |
|---|---|---|---|
| 1 | 7 | prose | read ~33% of corpus |
| 2 | 11 | Category: Spatial |
correct arithmetic, truncated label |
| 3 | 65 | Category: Counterfactual |
swept corpus, well-formed, wrong |
Attempt 3 consumed 425,054 input tokens — it genuinely read everything and answered in the required format. The remaining gap is aggregation accuracy: a 4B correctly combining 65 chunk-level counts. That is a capability question, not plumbing.
Guards added (none leak the answer)
| guard | catches |
|---|---|
require_repl |
answering from an empty REPL (measured: 1 call, pure guess) |
min_coverage=0.8 |
answering from a partial read |
max_answer_chars |
returning the corpus instead of an answer |
| placeholder check | returning Label: [least_common_status] unsubstituted |
ContextTruncated |
Ollama silently clipping 50k→16,387 tokens |
QuotaExhausted |
rate limits scored as wrong answers |
map_chunks(question) was added to the REPL: it splits the entire context and
queries every chunk concurrently, collapsing the chunk-and-loop code a 4B fails to
write. It moved sub-calls from 17 → 75 and reduced wall-clock 16.6m → 7.8m.
Scoring traps hit (both fixed)
gold in answerpassed a raw corpus dump because the dump contained the gold label. Strict scorers now reject replies with >2||separators or over a length bound; the dump is a regression test.- Caching a single sample of a non-deterministic reference froze a wrong answer
as the oracle. The cache is now keyed on
sha256(model + instruction + context), so any change invalidates it.
Remaining work
- Close claim B. The candidate sweeps correctly but aggregates wrong. Options,
cheapest first:
- Make chunk-level output machine-parseable (ask each chunk for strict
label<TAB>countlines) and aggregate in Python rather than trusting the model to combine 65 prose summaries. - Try E2B and Ornith 9B as the root (both scored 0.95 on tool behaviour vs E4B's 0.90); Ornith needs a card above 6GB or a smaller quant.
- Root = Sonnet/Opus with sub-calls on the local 4B — the paper's own BrowseComp arrangement, untested here.
- Make chunk-level output machine-parseable (ask each chunk for strict
- Terminal-Bench baselines — never produced a valid run. The ufw rule
(
sudo ufw allow from 172.16.0.0/12 to any port 11435 proto tcp) is in place and the bridge works; the suite needs re-running for E2B / E4B / Qwen3-4B. - Quantify reference reliability — run
bench/reference_reliability.pyfor N samples to put a number on Opus's instability at 440k. - Decide the finetune — nothing is trained yet. Base and training data are both open (see below).
- MoE expert-offload — see the dedicated section below. This is the main line.
How claim B was actually met
~/Projects/ctxstream (C++17, zero third-party deps). The corpus is treated like
a video stream, and the model is removed from every step it was failing:
| video | ctxstream |
|---|---|
| manifest | segment plan, computed in code before any model call |
| buffer | N segments in flight |
| decoder | model sees ONE segment, emits key<TAB>number, never prose |
| playback | reduce — aggregation in code, strategy chosen explicitly |
Result on the 957,493-char imagined-risk corpus — the exact task that defeated every earlier attempt, same 4B, same RTX 3060:
17 segments · failed=0 · records=611 · unparsed_lines=3 · keys=15 · 641s
Category: Spatial Relationship <- gold, correct
Opus 4.8 [1m] on the same corpus: 2/3 correct, self-inconsistent on byte-identical input, $4.79/call. The 4B on a 6GB laptop: correct, $0.00.
Still to confirm: the same pipeline against the full 262,144-token synthetic
ledger used by bench/rlm_262k.py, to show it holds at that size too.
Main line: frontier-class quality inside 6GB via MoE expert-offload
The constraint is VRAM, not parameters. A Mixture-of-Experts model can put nearly all of its weight in system RAM and keep only the always-active tensors resident, so 35B-class quality is reachable inside 6GB. This attacks the actual blocker directly: a 4B cannot aggregate 65 chunk-level summaries; a 35B-A3B plausibly can.
The candidate
ornith-ai/Ornith-1.5-35B-A3B (Qwen3_5MoeForConditionalGeneration), Q4_K_M =
21.7GB on disk. From its config: 40 layers, 256 experts, top-8 per token,
moe_intermediate_size 512, and 30 of 40 layers use linear attention (only 10
are full attention).
| component | params | ~Q4 size | placement |
|---|---|---|---|
| experts (256 x 3 x 2048 x 512 x 40) | ~32.2B | ~19.3 GB | CPU RAM |
| attention + embeddings + router + shared experts | ~1.7B | ~1.2 GB | GPU |
Two properties make this unusually favourable: experts are tiny and fine-grained (~1.9 MB each), and the 3:1 linear-attention ratio makes the KV cache far smaller than a normal 35B — so long contexts cost little VRAM.
Laptop capacity as measured: 51 GB RAM available, 483 GB disk, 5.8 GB free VRAM. The 21.7 GB of experts fit in RAM with room to spare.
Tooling
Ollama cannot do this — it exposes only num_gpu (a layer count), which would
naively push ~75% of layers to CPU including attention. The local llama.cpp build
already has the right flags:
-cmoe, --cpu-moe keep ALL MoE weights on CPU
-ncmoe, --n-cpu-moe N keep MoE weights of the first N layers on CPU
-ot, --override-tensor per-tensor placement by regex
ghcr.io/ggml-org/llama.cpp:server-cuda avoids building on the laptop.
Steps
- Pull
Ornith-1.5-35B-Q4_K_M.gguf(21.7GB) to the laptop. - Run
llama-serverwith--n-gpu-layers 99 -cmoe, so every layer's attention is on GPU and every expert FFN is on CPU. Measure resident VRAM; tune with-ncmoe Nif there is headroom left under 6GB. - Add an OpenAI-compatible backend to
rlm_haiku/utils/llm.py— llama-server serves/v1/chat/completions, not Ollama's/api/chat. Keep theContextTruncatedcheck: it needs a processed-token count from the response. - Re-run the equivalence test with this as the RLM root (sub-calls can stay on a cheap fast model, which is the paper's own BrowseComp arrangement).
Known cost, stated up front
Expert streaming is memory-bandwidth-bound. Only ~3B params are active per token, but a different ~600 MB of experts is touched every token, so throughput is set by RAM bandwidth rather than compute — expect single-digit to low-double-digit tokens/sec on a laptop. RLM multiplies that by ~65 sub-calls plus ~325k tokens of prefill across chunks. Minutes becomes tens of minutes to hours. If quality parity lands, that is the trade: VRAM and quality bought with wall-clock.
Fallbacks if throughput is unusable: -ncmoe N to pin as many expert layers on GPU
as fit (~4 GB spare / 1.9 MB per expert ~= 2,100 of 10,240 slots, so roughly 20%
resident); or a smaller MoE. True per-token LRU expert paging is what would help
most, and llama.cpp does not implement it (ktransformers, MoE-Infinity do).
Open decisions
- Finetune base and data. Deferred pending baselines. Worth knowing:
empero-ai/Qwable-9B-Claude-Fable-5already exists — Qwen3.5-9B fully fine-tuned on Fable-5 traces +gpt5.5-terminal, taggedagentic-coding. That is close to what we were going to build; evaluate it before training anything. - Release scope.
Rickesh/rlm-oolong-reproductionis published (harness + results, MIT, no weights). Nothing is trained, so there is no model release yet. Ollama.com namespace is separate from HF and needs your handle.
Non-obvious findings worth keeping
- Ollama auto-sizes context to the prompt up to a ceiling, then silently falls
back: 30,021 tokens pass intact, 50k and 70k both clip to exactly 16,387, with no
error.
num_ctxis ignored on the Anthropic-compatible/v1/messagesand honoured on native/api/chat, which is also the only route reportingprompt_eval_count— the thing that makes truncation detectable. - Terminal-Bench puts each task on its own compose network, so firewall rules
scoped to
docker0do not match. Scope by source subnet. - RLM hurts when the context fits the window: OOLONG-131k, Haiku, 0.269 recursive vs 0.428 direct. It only pays when the context does not fit.
- The "behave like Claude" system prompt bought zero tool-selection accuracy across 4 models (deltas 0.00 / 0.00 / -0.05 / -0.05) while halving output tokens.
Running things
# fast checks, no model calls
python -m pytest tests/test_equivalence.py -v
# equivalence, candidate on the 3060 (reference is cached; $0)
RLM_TEST_OLLAMA_URL=http://127.0.0.1:11436 \
python -m pytest tests/test_equivalence.py -v -m integration -s
# 262k on the 6GB card (run ON the laptop)
python3 bench/rlm_262k.py --model gemma4:e4b --target-tokens 262144 \
--num-ctx 8192 --max-prompt-chars 20000 --workers 2
# VRAM curve
python3 bench/vram_curve.py --model gemma4:e4b --budget-gb 5.5
# ask a question about an oversized file with a local model
python3 rlm_ask.py --file huge.log --query "which error appears most often?"