Skip to content

Studio (Windows): keep prompt caching on full GPU offload - #7260

Merged
danielhanchen merged 3 commits into
mainfrom
fix/studio-windows-full-offload-keep-prompt-cache
Jul 20, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
fix/studio-windows-full-offload-keep-prompt-cache

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

The Windows full-offload tuning from #5692 disables host-RAM KV checkpoints (--cache-ram 0, --ctx-checkpoints 0) to avoid WDDM/PCI-E overhead, which is correct. It also adds --no-cache-prompt, and that one is an overreach: it turns off in-VRAM prompt-prefix reuse, a different feature. For a fully offloaded model the KV cache lives in VRAM, so reusing a common prefix does not copy anything to system RAM and does not cause the PCI-E overhead #5692 was about.

The side effect is that llama-server re-prefills the entire prompt on every request. It is barely noticeable for short single-turn chats, but severe for a large, stable system prompt reused across many calls (coding agents via unsloth start, long multi-turn chats). In testing, one short turn re-prefilled about 79k prompt tokens.

This affects all Windows full-offload GGUF inference (Studio UI chat, unsloth start agents, direct API), so it is not agent-specific.

Change

Drop --no-cache-prompt from the win32 and full_offload_tuning_active branch in studio/backend/core/inference/llama_cpp.py. Keep --cache-ram 0 and --ctx-checkpoints 0 (the flags that actually address #5692) and the OMP / thread tuning. _prompt_cache_disabled therefore stays False (its default), so slot save/restore continues to work.

Verification

Fully offloaded gemma GGUF, the same prompt sent twice with prompt caching on, then once with it off:

request cache_prompt prompt tokens prefilled
1 (cold) on 2220
2 (repeat) on 1
3 (repeat) off 2220

A repeated prompt is reused (2220 to 1) instead of fully re-prefilled. Backend tests pass (studio/backend/tests: 404 passed, 13 skipped), including the updated test_windows_full_offload_flags_use_current_llama_server_args, which now asserts --no-cache-prompt is not added.

…ow-up)

The #5692 full-offload tuning also added --no-cache-prompt, which disables
in-VRAM prompt-prefix reuse. That is unrelated to the host-RAM KV checkpoints
#5692 fixed (--cache-ram 0 / --ctx-checkpoints 0): a fully offloaded model keeps
its KV cache in VRAM, so reusing a common prefix does not copy to system RAM and
does not cause the PCI-E overhead. --no-cache-prompt only forces every request to
re-prefill the whole prompt, which is small for short chats but severe for large
stable system prompts reused across calls (coding agents, long multi-turn chats).

Remove --no-cache-prompt; keep the checkpoint disables and the thread/OMP tuning.
_prompt_cache_disabled stays False (its default), so slot save/restore is intact.
Verified on a fully offloaded gemma GGUF: an identical repeated prompt reprefills
1 token instead of 2220.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request modifies the Windows full offload tuning logic for llama-server to keep prompt caching enabled (in-VRAM prefix reuse) while still disabling host-RAM KV checkpoints to avoid WDDM/PCI-E overhead. This prevents repeated prompts from being re-prefilled on every request. The corresponding test in test_llama_cpp_mtp_detection.py has been updated to reflect this change. There are no review comments, so I have no feedback to provide.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

danielhanchen and others added 2 commits July 20, 2026 13:32
Add a backend-wide test that AST-scans studio/backend and fails if
--no-cache-prompt is appended/extended/+= into a command. This locks in
the #7260 fix across every code path, not just load_model. Detecting the
flag or honouring a user-supplied one stays allowed.
@danielhanchen

Copy link
Copy Markdown
Member Author

Added a backend-wide regression guard in a follow-up commit so this cannot creep back in.

test_unsloth_never_injects_no_cache_prompt_into_any_command AST-scans every non-test file under studio/backend and fails if --no-cache-prompt is ever added to a command via append, extend, insert, or +=. It covers all code paths, not just load_model.

Still allowed, so nothing legitimate is blocked:

  • detecting the flag: _is_real("--no-cache-prompt") in probe_server_capabilities
  • honouring a user-supplied one: the comparisons in _prompt_cache_off (user pass-through via extra args keeps working)

Verified: full file green (246 passed), and a temporary re-injection of both cmd.append("--no-cache-prompt") and cmd += ["--no-cache-prompt"] makes the guard fail with the exact file and line.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 88fb769173

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit 796f849 into main Jul 20, 2026
45 of 48 checks passed
@danielhanchen
danielhanchen deleted the fix/studio-windows-full-offload-keep-prompt-cache branch July 20, 2026 13:47
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