Repository navigation
model : support Kimi-K3 recurrent-state rollback - #28466
Conversation
c3cb7b5 to
9cafb4f
Compare
Enable Kimi-K3 in the recurrent-rollback allowlist. Save Q/K/V convolution windows for each rollback position. Reuse the recurrent-attention helper to snapshot KDA state. Refs: ggml-org#28461
9cafb4f to
03fe995
Compare
|
Thank you, reduce the comments though please. |
|
@ggerganov Could you review the latest fix and approve the pending CI runs when you have a chance? The Vulkan test failure is fixed in 1ffc6ac; targeted CPU and NVIDIA Vulkan checks pass (5/5 each). Thanks! |
A one-token cache-discovery decode made Vulkan reallocate during the larger multi-sequence prefill, triggering GGML_SCHED_NO_REALLOC. Decode a full runtime ubatch before collecting and filling cache buffers. CPU and NVIDIA Vulkan rollback checks pass (5/5 each) with the reallocation guard enabled. The nonzero-fill pass still catches the original missing-snapshot implementation.
|
@ggerganov Could you rerun the four failed CI jobs? Kimi-K3 passes in all four. The ROCm Qwen rollback and Apple thread-safety failures also occur on master; the other two are a backend-test timeout and TOPK mismatch. Logs and comparisons are in the PR description. Thanks! |
(cherry picked from commit 9dcf84e)
| #include "../src/llama-io.h" | ||
| #include "../src/llama-memory.h" |
There was a problem hiding this comment.
Any suggestions on how/what to move this to ext?
There was a problem hiding this comment.
Not sure yet - I haven't looked into the logic of the new test and why it needs the headers. I would first look to write a test that does not require internal headers at all.
There was a problem hiding this comment.
It didn't initially, but used an env-var instead.
b9341 API-compat shims against fb76955 Upstream b9341 reshaped several APIs; this commit keeps qvac building and running against those interfaces without a full per-arch migration yet. The only functional behaviour change is the Vulkan SSM_CONV dispatch fix — the rest restores or shims qvac-side surfaces the rebase dropped. ggml-vulkan: - SSM_CONV binds four buffers, with a dummy bias buffer (src0) at the bias slot, to match the fused BIAS+SILU shader's 4-binding layout. Previously the dispatch bound 3 buffers, leaving dst (binding 3) unbound, so the conv output was never written. (APPLY_BIAS/SILU stay false.) llama-model: - virtual load_*/build_arch_* methods get no-op defaults so the monolithic switch(arch) path keeps compiling against b9341's polymorphic interface without splitting every arch into a subclass yet. - load_arch() and the flat attention-bias fields (bq/bk/bv/bo/bqkv) are restored. - build_graph() aborts if an arch has no polymorphic build_arch_graph(). llama-io / llama-context: - adopt read(size)/read_to() and const write_tensor (b9341 zero-copy read + read-only IO); add a read(dst) shim and a base read_tensor so kv-cache/memory serialization callers need no mass rewrite (the host/device readers still override read_tensor, so it stays virtual). - declare llama_memory_breakdown_print; default get_opt_pars to ggml_opt_get_default_optimizer_params. common / include/llama.h: - restore qvac surfaces dropped in b9341: llama_params_fit (+ status enum), build-info macros/externs, the llama-common CMake alias, and generation_prompt in the chat auto-parser. mtmd/clip.h: - re-expose clip_get_mem_usage (behind __cplusplus) and declare clip_has_whisper_encoder for common/fit.cpp's memory heuristics; guard the <map> include behind __cplusplus. tools/cli: - string_starts_with takes a string literal, not a char (build fix). tests: - test-backend-ops.cpp: add trailing newline only (no functional change). b9840 rebase: - Drop dead build-info declarations from common.h: the `print_build_info()` macro, the `LLAMA_BUILD_NUMBER` / `LLAMA_COMMIT` / `LLAMA_COMPILER` / `LLAMA_BUILD_TARGET` externs, and the `build_info` string are never referenced anywhere in the tree. They duplicate the `llama_print_build_info()` / `llama_build_info()` provided by common/build-info.h, which is what the codebase actually uses. b9952 rebase: - Drop the `llama_params_fit` public API (the `llama_params_fit_status` enum and `llama_params_fit` declaration) from `llama.h`; it is unused in the fork. (cherry picked from commit 844ea96) (cherry picked from commit 33b9d49) (cherry picked from commit 162e707) Drop the const write_tensor shim: upstream un-consted it. Upstream d6e7b03 (ggml-org#22679, 2026-05-05) removed the const from llama_io_write_i::write_tensor for its device-buffer save path. The b9341-era shim here puts it back, which breaks b11018's new tests/test-recurrent-state-rollback.cpp: upstream 9dcf84e (ggml-org#28466) subclasses llama_io_write_i with the non-const signature. Restores the upstream declaration in llama-io.h and the four overriders in llama-context.cpp. Every write_tensor caller already passes a non-const ggml_tensor *. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_019TGJJYSGGMZ9oKk8L2zTJb Signed-off-by: Guilherme Gallo <[email protected]> Assisted-by: Codex
Overview
Enable bounded recurrent-state rollback for Kimi-K3 during speculative decoding. Kimi-K3 currently has rollback disabled and stores only the final KDA state and Q/K/V convolution windows. Enabling rollback without changing those stores would restore unwritten snapshot groups after rejecting draft tokens.
Save the convolution windows for each rollback position, use the existing
build_recurrent_attnhelper to save KDA state snapshots, and add Kimi-K3 tollm_arch_supports_rs_rollback.Closes #28461.
Related: #28019 reports multi-sequence rollback corruption for qwen4exp. The connection to Kimi-K3's missing snapshots is an inference, not a maintainer-confirmed diagnosis. This change is limited to Kimi-K3 and does not resolve that issue.
Additional information
Validation:
tests/CMakeLists.txtregisters the generated Kimi-K3 model with the existing rollback test. Each registered model runs both zero-filled and0x3e-filled cache passes in the test executable.GGML_SCHED_DEBUG_REALLOC=1 ctest --test-dir build-cpu -R 'recurrent-state-rollback' --output-on-failure: 5/5 passed, including model generation and the four rollback tests.GGML_SCHED_NO_REALLOC=ONand fatal warnings enabled.The nonzero pass uses the existing state-writing interface to collect and fill cache buffers entirely within the test. Buffer discovery decodes a full micro-batch to preserve Vulkan's prefill allocation sizes. Production cache initialization uses zeros; the
LLAMA_RS_DEBUG_FILLhook has been removed. With only the Kimi-K3 allowlist change, the zero pass succeeded but the nonzero pass failed split replay (max logit difference2.35e-6, tolerance1e-7). Both passes succeed with the snapshot writes.CI for
1ffc6ac3c: 22 checks passed and four failed. The Kimi-K3 rollback test passes in all four failed jobs; the earlier Vulkan allocation abort is resolved.test-thread-safetybus error; also seen on master.test-backend-opstimed out after 1505 seconds on Tesla T4.test-backend-opsfailed oneTOPK_MOEnumerical comparison.This PR does not change
test-backend-opsor the GGML backends. The causes of the timeout and TOPK mismatch have not been confirmed.Real-model measurements on September 5 used Kimi-K3 UD-IQ2_XXS on 8x RTX PRO 6000 Blackwell GPUs, with four server slots and seven draft tokens. The RadixArk DSpark draft shared GPU 7 with the target's output weights. These runs used a RelWithDebInfo build based on
4d91760; DSpark also required a separatet_layer_inpregistration patch, outside this PR. Throughput is in tok/s:The rollback configuration was 13-25% faster on rewrite, 27-32% on knowledge, and 44-53% on code than the recorded host-checkpoint ranges. However, fit margins and model placement differed: the target's host model buffer was 5419.75 MiB with host checkpoints and 11010.12 MiB with rollback. These gains are not from a placement-controlled A/B.
Host-checkpoint results are unavailable for the concurrency benchmarks, so those rows cannot isolate rollback's contribution. Compared with no speculation, the combined DSpark and rollback configuration reduced TPOT from 77.7 to 49.2 ms at concurrency 1, but increased it from 134.5 to 220.6 ms at concurrency 4. These runs used random token inputs, disabled prompt caching, and four requests per concurrency slot.
Greedy outputs matched between DSpark with host checkpoints and DSpark with rollback on the three probe prompts. The rewrite output differed from the no-speculation run; knowledge and code outputs matched all three configurations. This does not establish output equivalence between DSpark and no speculation.
Snapshot storage multiplies recurrent-state memory by
1 + n_rs_seq: the recorded four-slot cache grew from 1772.44 to 14179.50 MiB with seven rollback positions.Requirements