Skip to content

Planner: tight-VRAM context expansion for --cache-disk - #102

Open
Banan412 wants to merge 2 commits into
cobanov:mainfrom
Banan412:split/5-planner
Open

Banan412 wants to merge 2 commits into
cobanov:mainfrom
Banan412:split/5-planner

Conversation

@Banan412

@Banan412 Banan412 commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #101 (7d1375a) — only the top commit af921c3 belongs to this PR; rebase onto main once #101 merges.

Tight-VRAM context expansion and explicit kv_type preservation for --cache-disk, split out of #89.

Changes (ps5/app/model_plan.cpp, ps5/app/model_plan_test.cpp, ps5/app/dashboard.cpp)

  • Off == main parity & LLAMA_INTROSPECT untouched:
    • Removed all LLAMA_INTROSPECT toggling/budgeting (main.cpp and the 0.25 GiB reserve are completely untouched — the console's Developer setting stays in control).
    • Normalized unknown disk_cache_mode values to "off".
    • Gated min_batch = 128 and tight -ub 32 compaction strictly on dmode != "off". When disk_cache == "off" (or invalid), plan_model produces the exact same Plan (fits, ctx, ubatch, kv_type, reserve_gib, total_gib, why, args) as origin/main.
  • Always preserves -ctxcp 1 (never emits -ctxcp 0 or -ctxcp 4):
    • Benchmark 2 on the console proved that dropping -ctxcp 1 to -ctxcp 0 breaks intra-chat prefix reuse on hybrid recurrent models (Qwen3.5), forcing full prompt re-prefill on every follow-up turn. model_plan.cpp now always keeps -ctxcp 1 and -cram 0.
  • Calibrated tight -ub 32 compaction (~0.05 GiB compute scratch):
    • When dmode != "off" and VRAM is tight (!fits or ctx < ctx_cap), tries -ub 32 (tight_reclaim = 0.05 GiB) and accepts it only when it rescues !p.fits or unlocks a strictly longer context (tight_plan.ctx > p.ctx) — never downgrading a working -ub 64 plan at the same context length.
    • Auto vs Always on: Auto enables -b 128 --cache-disk when near full (< 0.75 GiB headroom or compacting) and honors an explicit kv_type across >= 8k before stepping down to q4_0; Always on enables --cache-disk and expands to q4_0 (expanded) when it unlocks a longer context.
  • Tests (ps5/app/model_plan_test.cpp): Covers exact Off == main equal_plans parity (c, d, moe18, iq2_27b, invalid "bogus"), -ctxcp 1 invariant (never -ctxcp 0 or -ctxcp 4), 2 * state_gib accounting, 18B MoE (11.74 unlock 8k->16k, 11.80 keeping -ub 64), 27B IQ2_M (11.66 unlock 16k->32k, 11.30 q4_0 (expanded)), 0 MiB --cache-disk omission, and strict ctx_cap.

Verification

  • Host tests: model_plan_test: ok (synthetic only), log_sink_test: all passed, bash -n, tests/test_build_app.py (7/7 OK).
  • Live PS5 Off + LLAMA_INTROSPECT=1 check (18B MoE, kv_type=q8_0):
    • Planned -c 16384 -ctk q8_0 -b 256 -ub 64 -ctxcp 1 -cram 0 (no --cache-disk), llama.log confirmed introspection: enabled (POST /v1/introspect) (activation budget 256 MiB), and nested character_sheet json_schema returned HTTP 200 + /health 200.

Benchmark 1: Long Prompt Speed at -ub 32 vs -ub 64 (18B MoE, -c 16384 -ctk q8_0 -b 128 -ctxcp 0)

3 identical cold documents per ubatch (8,249, 7,599, 7,859 tokens; all cached_tokens == 0, enable_thinking: false):

Setting Trial 1 (8,249 tok) Trial 2 (7,599 tok) Trial 3 (7,859 tok) Median Speed Mean Speed Median TTFT Lowest pool free
-ub 32 242.62 tok/s (34,031.3 ms) 239.04 tok/s (31,823.0 ms) 239.15 tok/s (32,896.3 ms) 239.15 tok/s 240.27 tok/s 32,896.3 ms 0.22 GiB
-ub 64 267.40 tok/s (30,880.2 ms) 264.90 tok/s (28,720.9 ms) 263.74 tok/s (29,832.9 ms) 264.90 tok/s 265.35 tok/s 29,832.9 ms 0.18 GiB

-ub 32 trades -9.7% prompt throughput (-25.75 tok/s) for +0.04 GiB compute headroom, so keeping -ub 64 unless -ub 32 unlocks a longer context (or rescues fit) is the right trade-off.

Benchmark 2: 10-Turn Single-Chat TTFT on 18B MoE (3 Separate 10-Turn Chats / 30 Turns per Mode)

Identical ~1,895–2,055-token Turn 1 + 9 follow-up turns (~2,364–2,526 tokens at Turn 10; kv_type=q8_0, enable_thinking: false, max_tokens=64, temperature=0.0):

Configuration Turn 1 TTFT Median Turns 2–10 (27 turns) cached_tokens Avg Turns 2–10 TTFT Min Turns 2–10 TTFT Median Turns 2–10 TTFT Mean Turns 2–10 TTFT Max Lowest pool free
Off (-b 256 -ub 64 -ctxcp 1) 7,060.9 ms 2,216.1 272.3 ms 303.1 ms 324.8 ms 427.7 ms 0.12 GiB
Auto (before fix: -ub 32 -ctxcp 0) 8,602.2 ms 0 (full re-prefill every turn) 7,745.7 ms 8,810.5 ms 8,825.7 ms 9,808.1 ms 0.20 GiB
Auto (fixed: -b 128 -ub 64 -ctxcp 1 --cache-disk) 8,737.9 ms (incl. ~1.6s SSD save of prev chat) 2,216.1 (identical prefix reuse) 268.7 ms 297.9 ms 325.7 ms 420.2 ms 0.10 GiB

Multi-Model Live PS5 Planner & Chat Matrix (192.168.10.6, kv_type=q8_0, ctx_cap=65536)

Model (Size on Disk) Off Plan Auto Plan On Plan Live Follow-Up Med (Auto / On) Min pool free (Auto / On)
Qwen3.5-2B Q8_0 (2.01 GB) 64k q8_0 (3.1 GiB, -b 256 -ub 64) Identical to Off (no disk) 64k q8_0 + disk (3.1 GiB, -b 256) 1,087.8 ms (Off) / 1,133.9 ms (template cached=0) 8.51 / 8.51 GiB
Qwen3.5-9B Q6_K (8.56 GB) 64k q8_0 (9.9 GiB, -b 256 -ub 64) Identical to Off (no disk) 64k q8_0 + disk (9.9 GiB, -b 256) 242.3 ms / 247.6 ms (~1,656 / 1,619 cached) 2.06 / 2.01 GiB
Qwen3.6-12B IQ-Q5_K_M (8.42 GB) 64k q8_0 (9.5 GiB, -b 256 -ub 64) Identical to Off (no disk) 64k q8_0 + disk (9.5 GiB, -b 256) 203.3 ms / 202.8 ms (~1,648 / 1,681 cached) 2.51 / 2.46 GiB
qwen3.5-14b-a3b Q4_K_M (8.70 GB) 64k q8_0 (9.6 GiB, -b 256 -ub 64) Identical to Off (no disk) 64k q8_0 + disk (9.6 GiB, -b 256) 171.4 ms / 169.7 ms (~1,593 / 1,676 cached) 2.11 / 2.05 GiB
qwen3.5-18b-a3b Q4_K_M (11.38 GB) 16k q8_0 (11.6 GiB, -b 256 -ub 64) 16k q8_0 + disk (-b 128 -ub 64) 32k q4_0 (expanded) + disk (-b 128 -ub 64) 297.9 ms (2,216.1 cached in Auto) 0.10 / 0.21 GiB
Qwen3.8-27B IQ2_M (10.24 GB) 32k q8_0 (11.6 GiB, -b 256 -ub 64) 32k q8_0 + disk (-b 128 -ub 64) 64k q4_0 (expanded) + disk (-b 128 -ub 64) 502.6 ms / 513.7 ms (1,676 / 1,681 cached) 0.12 / 0.12 GiB
  • All non-tight models (2B, 9B, 12B, 14B-A3B) keep -b 256 -ub 64 -ctxcp 1 and disable --cache-disk in Auto, matching Off identically.
  • Both tight models (18B-A3B, 27B) drop -b 256 -> 128 + enable --cache-disk in Auto, and expand context in On (18B: 16k -> 32k, 27B: 32k -> 64k) while keeping -ctxcp 1 and full multi-turn KV reuse.

Refs #89.

Console Screenshot

Live PS5 TV Settings -> Model showing Off-default tight-VRAM expansion description and 8 GB limit
Live PS5 TV Settings → Model showing Disk cache spillover (Off default) and the tight-VRAM subtitle.


Generated with Google's Antigravity

@cobanov cobanov left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the tests and the console matrix.

  • Off should plan exactly as main does today, but min_batch = near_full_vram ? 128 : 256 and the 0.25 GiB introspect reserve in model_plan.cpp apply in Off too. Please gate both on the disk setting and add a test that Off matches main.
  • Please don't turn introspection off while its settings row says On: show it there, or leave the setting alone.
  • Since Auto moves tight models to -ub 32 -ctxcp 0, I'd like two measurements: prompt speed on a long prompt at -ub 32 vs 64, and time to first token over about 10 turns of one chat on the 18B in Auto vs Off.

Please rebase once #101 is in. #104 also touches model_plan.cpp, so expect a small conflict there.

@Banan412 Banan412 changed the title Planner: tight-VRAM context expansion and introspect budgeting for --cache-disk Planner: tight-VRAM context expansion for --cache-disk Nov 23, 2026
@Banan412

Copy link
Copy Markdown
Contributor Author

@cobanov Updated split/5-planner (43a7d63, stacked on #101 9df6910) — thank you for catching the -ctxcp 0 hazard and requesting both console measurements; running the 10-turn test caught the exact issue before merge:

Fixes Applied

  1. Left LLAMA_INTROSPECT completely alone: Removed disable_introspect and the 0.25 GiB introspect reserve from model_plan.*. Verified on live PS5 (18B Off + introspect=True): planned -b 256 -ub 64 -ctxcp 1 (no --cache-disk) and llama.log printed introspection: enabled (POST /v1/introspect) (activation budget 256 MiB).
  2. Off == main exact parity & gated min_batch: Gated min_batch = 128 and tight compaction on dmode != "off", normalized invalid modes to "off", and added equal_plans parity tests in ps5/app/model_plan_test.cpp verifying Off (and invalid mode) match origin/main verbatim across all models.
  3. Always keep -ctxcp 1 (never emit -ctxcp 0 or -ctxcp 4) & no needless -ub 32 downgrade: Calibrated tight -ub 32 reclaim to 0.05 GiB (matching Benchmark 1's 0.04 GiB live delta) and accept -ub 32 only when it rescues fit or unlocks a strictly longer context (tight_plan.ctx > p.ctx). Host tests (model_plan_test, log_sink_test, bash -n, tests/test_build_app.py) all pass.

Live PS5 Benchmark 1: -ub 32 vs -ub 64 (18B MoE, -c 16384 -ctk q8_0 -b 128 -ctxcp 0)

3 identical cold prompts each (8,249, 7,599, 7,859 tokens; cached_tokens == 0, enable_thinking: false):

Setting Trials (tok/s) Median (tok/s) Mean (tok/s) Median TTFT Lowest pool free
-ub 32 242.62, 239.04, 239.15 239.15 240.27 32,896.3 ms 0.22 GiB
-ub 64 267.40, 264.90, 263.74 264.90 265.35 29,832.9 ms 0.18 GiB

Result: -ub 32 costs 9.7% prompt speed for 0.04 GiB headroom, confirming we should only drop -ub 64 -> 32 when it actually unlocks a longer context.


Live PS5 Benchmark 2: 10-Turn Single-Chat TTFT on 18B MoE (3 Chats / 30 Turns per Mode)

Your hypothesis about dropping the single checkpoint on a recurrent/hybrid model (Qwen3.5) reproduced 100% on the PS5:

Mode (on 18B MoE, q8_0) Turn 1 TTFT Med Turns 2–10 (27 turns) cached_tokens Avg Turns 2–10 TTFT Med (Min–Max) Lowest pool free
Off (-b 256 -ub 64 -ctxcp 1) 7,060.9 ms 2,216.1 303.1 ms (272.3–427.7) 0.12 GiB
Auto (before fix: -ub 32 -ctxcp 0) 8,602.2 ms 0 (wiped every turn) 8,810.5 ms (7,745.7–9,808.1) 0.20 GiB
Auto (fixed: -b 128 -ub 64 -ctxcp 1 --cache-disk) 8,737.9 ms 2,216.1 (matched Off) 297.9 ms (268.7–420.2) 0.10 GiB
  • With -ctxcp 1 preserved, switched-chat SSD restore (Chat 3 -> Chat 1) in Auto also worked cleanly (cached_tokens = 2,360 / 2,421, 0.31 s @ 516 MB/s loading 87.8 MiB + 62.8 MiB chk, HTTP 200), and Always on expanded 18B to 32k q4_0 (HTTP 200, 143.9 ms, 0.21 GiB free).

Rebased on updated #101 (9df6910), and I'll handle the small rebase once #101/#104 settle.

@Banan412

Copy link
Copy Markdown
Contributor Author

@cobanov Rebased split/5-planner (af921c3) cleanly onto updated #101 (7d1375a), and verified the planner + chat behavior across all 6 models installed on PS5 (192.168.10.6, kv_type=q8_0, ctx_cap=65536):

  • Non-tight models (2B, 9B, 12B, 14B-A3B): Auto keeps -b 256 -ub 64 -ctxcp 1 and disables --cache-disk, matching Off identically (9B/12B/14B-A3B follow-up TTFT 171.4–242.3 ms in Auto, 2.06–2.51 GiB min free).
  • Tight models (18B-A3B, 27B):
    • Auto drops -b 256 -> 128 + enables --cache-disk at q8_0 (18B: 16k, 27B: 32k at 0.12 GiB free, follow-up 502.6 ms, 1,676.1 cached).
    • On expands both to the next context tier (18B: 16k -> 32k q4_0; 27B: 32k -> 64k q4_0 at 0.12 GiB free, follow-up 513.7 ms, 1,681.2 cached).

@cobanov

cobanov commented Nov 25, 2026

Copy link
Copy Markdown
Owner

@Banan412 thanks for the two measurements, and for keeping -ctxcp 1 after the 10-turn run turned up the problem. Off now matches main, with a test for it. #104 was closed, so its conflict won't come up. Please rebase onto #101 once that's on the new pin.

@Banan412

Banan412 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor Author

@cobanov Rebased split/5-planner (9100a56) cleanly onto the updated #101 (36fc8af on main 5e96235 / llama.cpp@d2bceda3d).

  • Verified scripts/apply-patches.sh (zero warnings), model_plan_test (including Off == main parity), log_sink_test, test_build_app.py (7/7), and PS5 cross-build on the new pin.

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.

2 participants