Skip to content

cli: auto-size context window to the prompt (long-context usable end-to-end) - #60

Merged
geisten merged 1 commit into
mainfrom
cli-longctx-autosize
Jul 5, 2026
Merged

cli: auto-size context window to the prompt (long-context usable end-to-end)#60
geisten merged 1 commit into
mainfrom
cli-longctx-autosize

Conversation

@geisten

@geisten geisten commented Jul 5, 2026

Copy link
Copy Markdown
Owner

Summary

Follow-up to #59 (engine ctx≥4096 fix). That fix made the engine correct — a prefill past the session window is rejected with GEIST_E_TOO_MANY_TOKENS instead of the old silent decode no-op — but the completion CLI still hardcoded session_opts = {0}, so it always got the 4096 default and any longer prompt was rejected. This makes long context actually usable from the CLI, and corrects the now-stale README known-issue.

What changed

tools/geist.c — before creating the real session, tokenize the prompt through a throwaway default session (tokenize touches no KV cache, so it only pays the tokenizer pass) and, only when prompt + decode budget exceeds the 4096 default, rebuild the session sized to the workload. Short/medium prompts keep the single-session fast path untouched.

README.md — the Metal-status blurb still said "decode after a ≥4096-token prefill no-ops (RoPE table sizing, fix in progress)". #59 landed the engine fix but didn't update this; corrected to describe the working behavior.

Verification (on current main = #58 + #59)

  • Metal long-context, end-to-end: a 5235-token prompt (well past 4096) produces coherent greedy output — "…the profound shift in fundamental understanding of reality." — and is token-identical to the cpu_neon reference across the 4096 boundary. This is the first time the ctx≥4096 path is verified on Metal (fix(engine): honor session max_seq_len; stop decode no-op past ctx 4096 #59 was CPU-only-verified).
  • Decode past 4096 actually computes: 22 ms/tok at kv≈4640 (was 0.0 ms/tok = full no-op).
  • No short-prompt regression: "The capital of France is"Paris; 24-token greedy parity vs the cpu_scalar reference unchanged.
  • Full suite on the cpu_neon cpu_scalar metal build: 38 unit + 44 int, 0 failed; the fix(engine): honor session max_seq_len; stop decode no-op past ctx 4096 #59 oversized-prefill reject test passes on Metal too.

🤖 Generated with Claude Code

…text verified

The completion CLI hardcoded session_opts={0} → the 4096 state default, so
any prompt longer than that hit GEIST_E_TOO_MANY_TOKENS (after the engine
fix) or the silent decode no-op (before it). Now it tokenizes the prompt
through a throwaway default session (tokenize touches no KV cache) and, only
when prompt + decode budget exceeds 4096, rebuilds the session sized to the
workload. Short/medium prompts keep the single-session fast path.

Closes the ctx>=4096 issue end-to-end on Metal (the engine fix 541e442 was
CPU-only-verified): pp5235 greedy completion produces coherent text and is
token-identical to the cpu_neon reference across the 4096 boundary; decode
runs at 22 ms/tok (was 0.0 ms/tok = full no-op). README known-issue updated.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@geisten
geisten merged commit f3cd111 into main Jul 5, 2026
6 checks passed
@geisten
geisten deleted the cli-longctx-autosize branch July 5, 2026 07:23
geisten added a commit that referenced this pull request Jul 5, 2026
…72)

The metal-beat-llamacpp-plan.md close (987/81.2, 2026-07-04) predates the
#58/#60 Metal work and the #62/#63 dead-flag cleanup. Add a dated data point:
a fresh cool compare_metal.sh on main (1020d45) reads 1006 pp512 / 81.6 tg64 /
445 total vs llama same-run 1540/92.8 — within noise of the close. Confirms the
flag/kernel/replay removals did not regress Metal. No historical numbers changed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant