Skip to content

[Engine] inkling: reject --kv k8v4/k8v8 on the hip/metal/sycl pools (fp16-sized regardless; #6681); --kv typo no longer silently auto - #6692

Closed
Lomare wants to merge 1 commit into
Niko1221:mainfrom
Lomare:fix/6681-reject-unimplemented-kv-dtypes
Closed

Lomare wants to merge 1 commit into
Niko1221:mainfrom
Lomare:fix/6681-reject-unimplemented-kv-dtypes

Conversation

@Lomare

@Lomare Lomare commented Nov 22, 2026 •

Copy link
Copy Markdown

Problem and result

Triggered by #6681: on the HIP backend --kv k8v4 / --kv k8v8 are silently accepted while VisitKvPool allocates fp16-sized pages regardless of dtype (elem_b = is_fp8 ? 1 : 2, the scale buffers live under if (is_fp8), and alloc_slot's dtype parameter is commented out). Metal and SYCL have the identical pattern (dtype stored for stats() only, ignored in alloc_slot). Measured on an RX 7900 XTX at matched shapes (full table in #6681's correction comment): fp16 and k8v4 peak at byte-identical VRAM and OOM at the same context, while fp8 serves past 140k on the same card.

Before: a request for --kv k8v4|k8v8 on hip/metal/sycl pays the quantize/dequantize cost for fp16-class memory; the only evidence is a confusing OOM tens of thousands of tokens later. After: init rejects the two formats with a message naming the working alternatives (fp8, fp16). Also: an unknown --kv value (e.g. --kv k4v4) used to silently mean auto with no message; it is now a fatal unknown --kv value '...' exit(2), and auto becomes an explicitly accepted value.

Related discussion

#6681 — issue opened by us, root cause cited by line; the reject-at-init fix shape was proposed in its correction comment. No separate maintainer agreement on scope (bug fix, not a feature/default change). CUDA deliberately untouched: see Approach.

Approach

The real support matrix, read from the source:

backend k8v4/k8v8 status
CPU implemented — pool init takes the dtype; selfcheck verifies the K8V8/K8V4 round-trip (#6520)
CUDA implemented — own InkKvDtype path with per-format allocation (kv_bytes_per_visit_pos, half-width V for K8V4). #6645's SIGSEGV is a crash inside a real implementation; guarding it would mask the fix, so no CUDA change here
HIP / Metal / SYCL pools ignore the dtype → guarded

Compatibility: the only behavior change is that the unimplemented modes now fail instead of lying about memory. Auto-select is unaffected (it never picks an integer dtype).

Validation

Passed:

  • g++ -std=c++20 -Wall -Wextra -I engine/src/inkling2 engine/tests/core/kv_dtype_guard_test.cpp && ./kv_dtype_guard_test on branch 45e2f34 (base a34979f, g++/Linux, no GPU) → prints ok, exit 0. The test covers the guard's truth table (fp16/fp8 false, k8v8/k8v4 true) and the dtype-name strings the reject message prints.

Failed:

  • none observed.

Not run:

  • HIP / Metal / SYCL compilation of the three guarded files — no hipcc, no oneAPI/sycl, no macOS toolchain in the test environment. Each guard is 5 lines in an init() prologue referencing only symbols already visible in that TU (KvDtype is referenced by all three files today).
  • --bench / --serve runs of a patched binary, same reason. The reject rides the identical error path as the existing "[ink-hip] no HIP devices visible" abort, which the CLI already prints and exits non-zero on.

Limits

…) instead of silently allocating fp16-sized KV (Niko1221#6681)

The integer quantized KV formats are implemented on the CPU (pool init takes
the dtype, selfcheck verifies the round-trip, Niko1221#6520) and on CUDA (its own
InkKvDtype path). hip/metal/sycl ignore the dtype in alloc_slot and allocate
fp16-sized pages, so --kv k8v4/k8v8 there pays quantize overhead for fp16
memory and the user believes the depth win is real. Reject at init with the
working alternatives. Also: --kv stopped silently treating unknown strings as
'auto' (a typo'd mode became auto-select with no message).

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Thanks for the pull request. To keep the tracker readable, every item needs an area prefix in the title and the parts of the pull request template filled in. This one is missing:

  • Start the title with its area: [Engine], [GUI], [TUI], [Benchmark], [Docs] or [Other], then a short description. Example: "[Engine] fix decode stop on long prompts".
  • Fill in "Problem and result": what triggered the change, and how it behaves before and after.

Edit the pull request (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment /reopen.

Details: CONTRIBUTING.md

@Lomare Lomare changed the title inkling: reject --kv k8v4/k8v8 on the hip/metal/sycl pools (fp16-sized regardless; #6681); --kv typo no longer silently auto [Engine] inkling: reject --kv k8v4/k8v8 on the hip/metal/sycl pools (fp16-sized regardless; #6681); --kv typo no longer silently auto Nov 22, 2026
@github-actions github-actions Bot removed the needs-format Title or template does not follow CONTRIBUTING.md yet label Nov 22, 2026
@github-actions

Copy link
Copy Markdown

Thanks, this follows the format now.

@Lomare

Lomare commented Nov 23, 2026

Copy link
Copy Markdown
Author

Closing as superseded — commit 759ccf6 ("harden hy4 vcache headroom, inkling2 Metal/HIP/SYCL/CUDA guards, GGUF layout, and CMake checks") independently landed the same fix on main while this PR was open. Verified against current main:

  • HIP (ink_hip_backend.hip.cpp ~L567): --kv k8v4/k8v8 is not supported on the HIP backend (allocates fp16-sized pages); use --kv fp8 or fp16
  • Metal (ink_metal_backend.mm ~L94) and SYCL (ink_sycl_backend.cpp ~L67): equivalent guards.
  • --kv typo: ink_main.cpp now hard-errors on unknown values (unknown --kv value '%s' (expected: auto, fp8, fp16, k8v8, k8v4)) instead of silently falling through to auto.
  • Guard test: engine/tests/core/kv_dtype_guard_test.cpp exists and is wired into CMake (add_executable + add_test).

Nothing left in this PR that main doesn't already have — no rebase needed. Thanks for the fast turnaround on #6681.

@Lomare Lomare closed this Nov 23, 2026
@Lomare
Lomare deleted the fix/6681-reject-unimplemented-kv-dtypes branch November 23, 2026 02:38
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