Skip to content

model : support Kimi-K3 recurrent-state rollback - #28466

Merged
am17an merged 5 commits into
ggml-org:masterfrom
soulmachine:kimi-k3-rs-rollback
Sep 8, 2026
Merged

am17an merged 5 commits into
ggml-org:masterfrom
soulmachine:kimi-k3-rs-rollback

Conversation

@soulmachine

@soulmachine soulmachine commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

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_attn helper to save KDA state snapshots, and add Kimi-K3 to llm_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.txt registers the generated Kimi-K3 model with the existing rollback test. Each registered model runs both zero-filled and 0x3e-filled cache passes in the test executable.
  • CPU Release build on macOS with Apple clang passed. 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.
  • NVIDIA Vulkan Debug build on RTX PRO 6000 Blackwell passed the same 5/5 checks with GGML_SCHED_NO_REALLOC=ON and fatal warnings enabled.
  • Both passes passed checkpoint restoration, multi-sequence split replay, and sequence-isolation checks for Qwen3.5, Nemotron-H, DeepSeek-V4, and Kimi-K3. Logit comparisons reject NaN and infinity; sequence-isolation checks matched exactly.

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_FILL hook has been removed. With only the Kimi-K3 allowlist change, the zero pass succeeded but the nonzero pass failed split replay (max logit difference 2.35e-6, tolerance 1e-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.

Failed job Failure
ROCm Qwen3.5 split-replay mismatch in the zero-fill pass; also seen on master.
Vulkan Apple test-thread-safety bus error; also seen on master.
Vulkan NVIDIA CM test-backend-ops timed out after 1505 seconds on Tesla T4.
Vulkan Intel Linux test-backend-ops failed one TOPK_MOE numerical comparison.

This PR does not change test-backend-ops or 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 separate t_layer_inp registration patch, outside this PR. Throughput is in tok/s:

Workload No speculation DSpark + host checkpoints DSpark + rollback
Rewrite 12.88 17.7-19.6 22.19
Knowledge 12.81 11.9-12.4 15.75
Code 12.62 10.2-10.9 15.65
Benchmark, concurrency 1 (1024 input / 256 output tokens) 10.14 Unavailable 13.98
Benchmark, concurrency 4 18.30 Unavailable 14.92

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

  • I have read and agree with the contributing guidelines
  • AI usage disclosure: YES - AI assisted with implementation, investigation, and validation. Codex drafted the commit message and this description from the patch and recorded results.

@github-actions github-actions Bot added model Model specific testing Everything test related labels Sep 6, 2026
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
@CISC

CISC commented Sep 6, 2026

Copy link
Copy Markdown
Member

Thank you, reduce the comments though please.

Comment thread tests/CMakeLists.txt Resolved
@soulmachine

Copy link
Copy Markdown
Contributor Author

@CISC Shortened the code comments in eff6894, keeping the rollback invariant and test rationale.

Comment thread src/llama-memory-recurrent.cpp Resolved
@soulmachine

soulmachine commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor Author

@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.
@soulmachine

Copy link
Copy Markdown
Contributor Author

@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!

@am17an
am17an merged commit 9dcf84e into ggml-org:master Sep 8, 2026
22 of 26 checks passed
@soulmachine
soulmachine deleted the kimi-k3-rs-rollback branch September 8, 2026 04:41
SteelPh0enix pushed a commit to SteelPh0enix/llama.cpp-qwen4exp that referenced this pull request Sep 8, 2026
x1250 pushed a commit to x1250/llama.cpp that referenced this pull request Sep 9, 2026
Comment on lines +6 to +7
#include "../src/llama-io.h"
#include "../src/llama-memory.h"

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.

Including internal headers should be avoided. At best, we can include llama-ext.h, but eventually it should also not be included. fyi @am17an @CISC

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.

Any suggestions on how/what to move this to ext?

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.

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.

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.

It didn't initially, but used an env-var instead.

zbrad pushed a commit to zbrad/llama.cpp that referenced this pull request Sep 10, 2026
gianni-cor pushed a commit to tetherto/qvac-fabric-llm.cpp that referenced this pull request Oct 1, 2026
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

model Model specific testing Everything test related

Projects

None yet

Development

Successfully merging this pull request may close these issues.

model: support bounded recurrent-state rollback for Kimi-K3

4 participants