Repository navigation
Conversation
Multi-turn chats never reuse the slot's KV in strata-inkling: the prefix match in ink_serve.h is all-or-nothing against cached_prefix, and cached_prefix holds the previous reply, including the hidden reasoning span that clients never send back. So every turn resets the slot and reads the whole conversation again. This adds three backend hooks with no-op defaults (checkpoint_slot, restore_checkpoint, drop_checkpoint) to InkBackend. The serve loop takes a checkpoint when a slot has read a whole prompt (no images), before any generated token enters the slot. On admission, when the new prompt diverges from cached_prefix inside the previous reply but still contains the whole previous prompt, it restores the checkpoint and resumes at ckpt_len instead of resetting to 0, and logs "INFO prompt-checkpoint resume N". Reset paths drop the checkpoint. Backends that do not override the hooks keep the old behaviour. Based on the diff by martinshane in Niko1221#6627 (ink_backend.h and ink_serve.h hunks, unchanged; the Metal backend part of that diff is not included here). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SG5G8VwxLyU5bwfggEz6AU
HIP side of checkpoint_slot / restore_checkpoint / drop_checkpoint, so the Niko1221#6627 serve-side resume also works on AMD GPUs. - SWA visits keep a ring of swa_win positions in 64-token pages (ensure_page: logical page (p % swa_win) >> 6). checkpoint_slot copies the slot's mapped ring pages of every SWA visit to pinned host memory, one hipMemcpyAsync per run of consecutive physical pages, K and V (and the per-token scales with FP8 KV). About 160 MiB of host RAM per slot at BF16 KV, no VRAM. - ShortConv state (n_visits x 3 lags) is copied to small device buffers with k_sconv_snapshot_pair and restored with k_sconv_rollback_pair at keep_steps = 0 (all three lags come from the snapshot argument). - Global-visit KV and the DSpark context / f_rnn are indexed by absolute position and only appended, so restore sets seq_len back (forward_batch only raises it with std::max) and caps dspark_len. - restore_checkpoint first checks that the slot still maps the same physical SWA pages (only free_slot unmaps them; grow_pool keeps page indices) and otherwise returns false, so the serve falls back to a full read. It resets DSpark's adaptive draft state as reset_slot does. - Every copy is queued on the backend stream, in order with the forward passes; no host sync is added. - Off when max_slots > 4, to bound pinned host RAM. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SG5G8VwxLyU5bwfggEz6AU
The serve reads fields 6-8 of DONE (drafts accepted, drafts offered, reused) into usage.prompt_tokens_details.cached_tokens, timings.cache_n, timings.draft_n / draft_n_accepted and the /metrics draft counters (serve/server.py StrataEngine._parse_done, server_parts/core.py request_timings). strata-inkling printed only 5 fields, so a prompt resumed from the slot (RESUME, or the Niko1221#6627 checkpoint) still showed cached_tokens 0, and DSpark acceptance was never visible (Niko1221#6633). Single slot: DONE now carries the request's draft counters and reuse. --batch admission: DONE carries 0 0 <reused>; the slot's drafts still arrive on BDONE (drafts=), which the serve sums onto them. The counters already existed in ActiveReq; rq.reused is set where RESUME is printed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SG5G8VwxLyU5bwfggEz6AU
Match SHA-256 image content and expanded token positions before resuming. Encode only the images in the fresh suffix and count expanded prompt tokens in the API and metrics.
kurtmj93
marked this pull request as ready for review
November 23, 2026 00:26
jbox5
force-pushed
the
fix/ink6627-hip-ckpt
branch
from
November 23, 2026 04:13
a6babf9 to
fe2ab3b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem and result
Image-bearing requests skip prompt checkpoints in the current draft, including text follow-ups that resend historical screenshots. This change lets Inkling resume when the images in the retained prefix have the same bytes and expanded token positions. A new image in the suffix is still encoded. Replacing an image forces a reread when it invalidates the checkpoint.
Related discussion
Follow-up for Niko1221#6665 and Niko1221#6627. This PR targets the branch behind Niko1221#6665.
Approach
Hash the image bytes with SHA-256 rather than comparing the per-request filenames or image placeholder tokens. Validate image positions and dimensions before resuming, and skip the vision encoder for images covered by the reused prefix. Use the engine's expanded prompt length when reporting multimodal usage.
Validation
Passed:
cmake --build pr6665-build --target strata-inkling -j 8on Windows. The build passed with two existing warnings.python -m unittest serve.test_request_accounting serve.test_yield_accountingpassed all 18 tests.Failed: None in the final runs.
Not run: GPU inference on this exact revision without Niko1221#6594, and CUDA, Metal or SYCL builds. Kept as a draft for that coverage.
Limits
This uses the parent PR's per-slot checkpoint. Its slot limits and fallback behavior still apply. An edit before the saved checkpoint can still require a full read.