Skip to content

fix(studio): explain why quantized KV enlarges Inkling's compute buffer - #18849

Open
InfoSage05 wants to merge 9 commits into
unslothai:mainfrom
InfoSage05:fix/inkling-quant-kv-compute-note
Open

InfoSage05 wants to merge 9 commits into
unslothai:mainfrom
InfoSage05:fix/inkling-quant-kv-compute-note

Conversation

@InfoSage05

Copy link
Copy Markdown
Contributor

Summary

In Studio's memory estimate for Inkling, a quantized KV cache (q8_0/q4_0) shows a larger total than f16/bf16, even though the KV cache itself is smaller. The numbers are correct: quantized KV disables llama.cpp's banded relative-bias attention path, so the dense fallback needs a much larger compute scratch buffer. But the UI never said so, and the KV Cache Dtype hint claimed lower precision saves VRAM. This PR surfaces the reason; no estimate values change.

Classification: Bug (misleading UX), no behaviour change in the math.

Root Cause

The root cause is the dense relative-bias branch in LlamaCppBackend._compute_buffer_ctx_bytes (studio/backend/core/inference/llama_cpp.py, Inkling and Inkling 2 branches) taken for any quantized KV cache, whose scratch (e.g. ~402 KiB/token on Inkling, ~99 KiB/token on Inkling 2 at ub=512) outweighs the KV savings, while the UI shows only the whole-model total with no explanation.

Estimates for an Inkling 2 Mini-like config (MiB; KV / compute / total), 128k ctx, ub=512: f16 4336 / 1176 / 5512; q8_0 2304 / 12672 / 14976; q4_0 1220 / 12672 / 13892. This matches the measured llama.cpp buffers recorded in tests/test_compute_buffer.py.

Changes

  • studio/backend/core/inference/llama_cpp.py: new _quantized_kv_dense_bias_fallback() helper; Inkling v1 branch reuses it (behaviour-identical).
  • studio/backend/routes/inference.py, core/inference/memory_contract.py, models/inference.py: carry a new compute_dense_fallback bool through the estimate-memory response (default False, so older clients and other architectures are unaffected).
  • studio/frontend/.../memory-estimate.ts, memory-estimate-row.tsx: map the flag and show a note on the "Compute buffers" line.
  • studio/frontend/.../model-config-page.tsx: the KV Cache Dtype hint now notes the Inkling exception.
  • Tests: TestQuantizedKvDenseBiasFallback in tests/test_compute_buffer.py; flag present/absent/non-boolean cases in tests/memory-estimate-skew.test.ts.

Reproduction

Load an Inkling / Inkling 2 GGUF in Studio, open the memory estimate panel and switch KV Cache Dtype between f16 and q8_0: the Total/GPU figure rises sharply for q8_0.

Testing

cd studio/backend && python -m pytest tests/test_compute_buffer.py tests/test_memory_estimate_contract_freeze.py tests/test_memory_contract.py tests/test_memory_contract_platforms.py tests/test_memory_estimate.py -q
cd studio/frontend && node --experimental-strip-types --test tests/memory-estimate-skew.test.ts

Backend: 718 passed, 134 skipped. Two unrelated Windows symlink-privilege tests in test_compute_buffer.py fail identically without this change. Frontend skew test passes; memory-estimate-narrow-panel.test.ts fails on a missing dev dependency (@typescript/typescript6) with or without this change. ruff and tsc were not available locally and the .tsx note was not rendered.

Known limitation: for Inkling 2 the flag keys on cache type only; f16 can also go dense without flash attention or at tiny ubatch, which is not flagged.

Checklist

  • Tests added / updated
  • All existing tests pass (see Windows/dev-dependency exceptions above)
  • Linting passes (ruff check .) not run locally
  • Linked to the issue

Fixes #18833

InfoSage05 and others added 9 commits June 27, 2026 00:47
…etuning example with WER/CER metrics

Adds explicit model routing for PaddlePaddle/PaddleOCR-VL-1.6 in the unsloth registry (org=PaddlePaddle, base_name=PaddleOCR, multimodal), disables compile optimization for this trust_remote_code model in loader.py, and provides a comprehensive finetuning example with WER/CER OCR benchmark evaluation via jiwer.
Add PaddleOCR-VL-1.6 registry entry, loader routing, and finetuning example with WER/CER evaluation
For Inkling, a quantized KV cache turns off llama.cpp's banded attention and falls back to a dense relative-bias scratch buffer, so q8_0/q4_0 show a larger total than f16/bf16 even though the KV cache itself shrinks. The numbers are correct, but the UI never said why, and the KV Cache Dtype hint claimed quantizing saves VRAM.

Expose compute_dense_fallback on the estimate-memory response, show it as a note on the Compute buffers line, and add an Inkling exception to the KV Cache Dtype hint. No estimate values change.

Fixes unslothai#18833

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Inkling kv quant calculation is odd

2 participants