Skip to content

fix: size the curated coding-agent context from the model's actual KV geometry - #5915

Merged
atomantic merged 1 commit into
mainfrom
cos/task-mtkndbix/agent-c5a00cdd
Sep 2, 2026
Merged

fix: size the curated coding-agent context from the model's actual KV geometry#5915
atomantic merged 1 commit into
mainfrom
cos/task-mtkndbix/agent-c5a00cdd

Conversation

@atomantic

Copy link
Copy Markdown
Owner

Summary

The Recommended coding-agent setup card offered a 48 GB Apple Silicon machine a 64K launch context, justified only by a vague "practical unified-memory headroom" sentence. Double-checking that number against the model's real geometry showed it was too conservative — and that nothing in the code let a reader verify it either way.

Qwen3.8-27B holds a KV cache on only its 16 full-attention layers (the other 48 are Gated DeltaNet, whose state is constant in the window). That costs 65.5 KB/token at a bf16 cache — the same KV_KB_PER_TOKEN server/lib/sglangQwenRecipe.js sizes its pools from. MTPLX reserves the window up front (--context-window), so it is a memory reservation, not a free ceiling. macOS gives the GPU ~75% of unified memory; the MLX 4-bit weights are 15 GB.

Tier GPU budget Was Now Weights + KV Free
48 GB ~36 GiB 64K 128K 23.2 GiB 12.8 GiB
64 GB ~48 GiB 128K 256K 31.4 GiB 16.6 GiB
128 GB ~96 GiB 128K 256K 31.4 GiB 64.6 GiB

1M is not reachable on any of them. Its KV cache alone is 65.5 GiB — more than a 48 GB machine has in total, before the weights. And the catalog caps this checkpoint at 262,144 tokens regardless; the 1M-context local model there is Nemotron 3 Nano 30B-A3B, not this one. 256K at 48 GB would leave 4.6 GiB, which is why that tier stops at 128K.

Changes

  • HardwareLlmRecommendation.jsx — profiles carry contextTokens instead of a display string; the card renders the label from it. A header comment states the geometry, the budget, and where both numbers come from. Each tier's note now gives the arithmetic, and the --kv-quant q8 / --cache-type-k q8_0 lever that buys a longer window.
  • LocalLlmTab.test.jsx — a parameterized test pins weights + KV under each tier's GPU budget with an 8 GiB reserve, so a future edit cannot promise a window the machine will not load.

The RTX 3090 profile keeps its 64K (weights + KV already claim ~19 of 24 GB) and now says so.

Test plan

  • cd client && npx vitest run — 807 files, 10,002 tests, all green.

https://claude.ai/code/session_01FVBPGvC77m8KA6J4UwDRnv

… geometry

The "Recommended coding-agent setup" card offered a 48 GB Apple Silicon
machine a 64K launch context with only a vague headroom sentence to justify
it. The number was too small and nothing in the code let a reader check it.

Qwen3.8-27B holds a KV cache on only its 16 full-attention layers (the other
48 are Gated DeltaNet, whose state is constant in the window), which costs
65.5 KB per token at a bf16 cache — the same per-token figure the SGLang
recipe sizes its pools from. Against the ~75% of unified memory macOS gives
the GPU, and the 15 GB MLX 4-bit weights:

  48 GB -> 64K reserved 19 GiB of 36. 128K reserves 23 GiB, still leaving
           ~13 GiB for PortOS, the harness and local image/video work.
  64 GB -> 256K, the checkpoint's own ceiling, reserves 31 GiB of 48.
  128 GB -> the same 256K on the quality checkpoint, with budget to spare.

So each Apple tier moves up one step. A 1M-token window is not reachable on
any of them: its KV cache alone is 65.5 GiB, more than a 48 GB machine has in
total, and the catalog caps this checkpoint at 256K regardless (the
1M-context local model there is Nemotron 3 Nano 30B-A3B).

Profiles now carry contextTokens rather than a display string, the card
renders the label from it, and each note states the arithmetic and the
kv-quant lever that buys more. A parameterized test pins weights + KV under
each tier's GPU budget with an 8 GiB reserve, so the next edit cannot promise
a window the machine will not load.

Claude-Session: https://claude.ai/code/session_01FVBPGvC77m8KA6J4UwDRnv
@atomantic
atomantic merged commit efe1765 into main Sep 2, 2026
7 checks passed
@atomantic
atomantic deleted the cos/task-mtkndbix/agent-c5a00cdd branch September 2, 2026 22:16
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