Skip to content

feat(studio): expose full KV cache dtype list in model config UI - #7348

Merged
danielhanchen merged 2 commits into
unslothai:mainfrom
Souravrajvi0:feat/kv-cache-dtype-options-4af7
Jul 24, 2026
Merged

danielhanchen merged 2 commits into
unslothai:mainfrom
Souravrajvi0:feat/kv-cache-dtype-options-4af7

Conversation

@Souravrajvi0

@Souravrajvi0 Souravrajvi0 commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #7244

Problem

The Studio per-model KV Cache Dtype dropdown only exposed bf16, q8_0, q5_1, and q4_1, even though studio/backend/core/inference/llama_cpp.py already accepts the full llama.cpp cache-type set (q4_0, q5_0, iq4_nl, f32, …) and the VRAM estimator already handles them (test_kv_cache_estimation.py).

Users who wanted lower KV memory (especially q4_0) had no UI path to select it; the value was also dropped on reload because VALID_KV_CACHE_DTYPES in the frontend did not include the missing entries.

The issue referenced chat-settings-sheet.tsx; on current main this control lives in the per-model config page (model-config-page.tsx).

Fix

  • studio/frontend/src/features/model-picker/model-config/per-model-config.ts: expand KV_CACHE_DTYPES to bf16, q8_0, q4_0, q4_1, q5_0, q5_1, iq4_nl, f32 (matches backend _valid_cache_types; f16 stays the default menu item).
  • studio/frontend/src/features/model-picker/components/model-config-page.tsx: update the KV cache dtype help text.
  • studio/backend/models/inference.py: document all supported dtypes on cache_type_kv fields.
  • studio/backend/routes/models.py: broaden the VRAM-estimate query param description.

No backend load-path changes — this is UI exposure + docs for types llama-server already understands.

Verification

cd studio/backend && python -m pytest tests/test_kv_cache_estimation.py -q
cd studio/frontend && npm run typecheck
  • pytest tests/test_kv_cache_estimation.py — 143 passed
  • npm run typecheck — clean
  • Frontend dtype list is a subset of backend _valid_cache_types (parity script checked locally)
  • Manual Studio check: On Device model picker → per-model config → Advanced → KV Cache Dtype shows q4_0 / q5_0 / iq4_nl / f32; selecting q4_0 with "Remember for this model" persists through page reload (Playwright, CPU-only; model load not GPU-verified end-to-end)

Fixes unslothai#7244

The Studio per-model config dropdown only surfaced bf16, q8_0, q5_1,
and q4_1 even though llama.cpp already accepts q4_0, q5_0, iq4_nl, and
f32. Add the missing options to KV_CACHE_DTYPES and align API field
descriptions with the backend _valid_cache_types set.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@Souravrajvi0

Copy link
Copy Markdown
Contributor Author

Manual UI verification completed locally (CPU-only, no GPU inference):

  1. Started Studio backend (run.py on :8888) and frontend dev server (npm run dev on :5173).
  2. Used a local GGUF symlink (test-manual-kv.gguf) so the On Device tab had a selectable model.
  3. Playwright flow: login → model picker → On Device → Inference settings for test-manual-kv → Show advanced settings → KV Cache Dtype dropdown.

Results:

  • Dropdown options: f16, bf16, q8_0, q4_0, q4_1, q5_0, q5_1, iq4_nl, f32
  • Selected q4_0, checked Remember for this model, clicked Load model
  • localStorage.unsloth_model_configs stored kvCacheDtype: "q4_0"
  • After full page reload, reopening config still shows q4_0 and the remembered checkbox is checked

Model load itself was not GPU-verified end-to-end; this check only covers UI exposure and per-model persistence.

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Hooray!

Reviewed commit: 76e3f14d18

ℹ️ 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

Copy link
Copy Markdown
Member

Reviewed and verified. The model config UI exposed only a partial KV cache dtype list, so valid options were unreachable. This exposes the full KV cache dtype list in the config UI. Confirmed the options render and map to valid backend values. Codex review has no open items. The remaining red CI is pre-existing upstream breakage unrelated to this change. Good to merge.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 20ce58d0c5

ℹ️ 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".

export const KV_CACHE_DTYPES = [
"bf16",
"q8_0",
"q4_0",

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Disable quantized cache types when tensor parallelism is selected

When a user selects the newly exposed q4_0 option (and likewise q5_0 or iq4_nl) together with Tensor Parallelism, the load path detects that tensor mode cannot use quantized KV caches and silently clears the selected dtype before launching (llama_cpp.py:6596-6612). The model therefore loads with the default non-quantized cache while the saved per-model configuration still says q4_0, defeating the VRAM-saving setting and making the UI misleading for this supported configuration combination. Disable these choices while tensor parallelism is enabled, or surface that tensor parallelism will override them.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Confirmed the llama.cpp limitation (--split-mode tensor aborts on a quantized KV cache), but disabling the quantized dtypes whenever the tensor-parallel toggle is on would block configurations the backend does support. Manual mode with fewer than 2 effective GPUs, manual mode with Auto layers, and the layer-split fallback all turn tensor parallelism off and preserve the requested quantized cache (llama_cpp.py restores _tensor_dropped_cache_type_kv on those paths). The incompatibility is only real when tensor split genuinely engages (auto mode, >= 2 GPUs), and the load path already resolves it there by dropping the quantized cache for the tensor attempt. Coupling the dropdown to the toggle would strip valid quantized + TP-requested combinations, so keeping the runtime resolution in the backend is intentional. Leaving the option list as-is.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Disable quantized cache types when tensor parallelism is selected

When a user selects the newly exposed q4_0 option (and likewise q5_0 or iq4_nl) together with Tensor Parallelism, the load path detects that tensor mode cannot use quantized KV caches and silently clears the selected dtype before launching (llama_cpp.py:6596-6612). The model therefore loads with the default non-quantized cache while the saved per-model configuration still says q4_0, defeating the VRAM-saving setting and making the UI misleading for this supported configuration combination. Disable these choices while tensor parallelism is enabled, or surface that tensor parallelism will override them.

Useful? React with 👍 / 👎.

Instead of disabling the choices, showing a warning message in the interface would be sufficient

@danielhanchen

Copy link
Copy Markdown
Member

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

Reviewed commit: 20ce58d0c5

ℹ️ 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 330586d into unslothai:main Jul 24, 2026
44 of 45 checks passed
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.

[Feature] Expose Q4_0 as a KV Cache Dtype option in Studio UI

3 participants