Repository navigation
Conversation
|
Agent replay with this branch (same card and settings as above; 26-step agent session with tool calls, history growing to 82K tokens; temperature 0.7; one run per build):
Decode speed doesn't change; the gain is all in not re-reading the history. The engine logged 25 checkpoint resumes in 25 follow-up turns. One note: 26 turns with this branch hit |
|
Independently verified on Windows 11 with an RX 7900 XTX (gfx1100, 24 GB), Ryzen 9 7900X, and 64 GB RAM. I applied this PR to Strata v0.2.19 on top of the #6594 NaN fix. Both builds used Inkling 2 Mini SQ-15, FP8 KV, --draft off, --chunk 256, a 262,144-token context limit, and one slot. I replayed the same three-turn sequence through the OpenAI-compatible API, passing back the tool call and result without replaying hidden reasoning. Request | Before | With this PR | Cached tokens with this PR Times are server-reported prefill. Both builds called the tool with the expected arguments and returned the correct answers. The combined build also passed the 64-token NaN regression check. I tested normal follow-ups here. I didn’t test exact retries or regeneration. Thanks for the patch! |
|
Greedy output is now shown to be token-exact. The run-to-run variation I couldn't get around was a race in the HIP kernel
"Identical" compares the token ids of the reply after a checkpoint resume (changed previous reply) with the reply after the existing exact-prefix resume of the same prompt: 200 tokens, temperature 0. The engine logged a checkpoint resume for each. With the fix, the existing exact-prefix path gives the same tokens with and without this branch. I've moved the greedy comparison from "Failed" to "Passed" in the description. |
main added save_prompt_checkpoint / restore_prompt_checkpoint to InkBackend and the serve logic that uses them, with CPU and CUDA implementations. HIP kept the default (return false), so on AMD every follow-up turn whose previous reply is not a prefix of the new prompt still reads the whole conversation again. What the HIP side saves for the slot, at seq_len = prompt_len - 1: - SWA visits keep a ring of swa_win positions in 64-token pages. The slot's mapped ring pages are copied to pinned host memory, one hipMemcpyAsync per run of consecutive physical pages, queued on the backend stream with no host sync. About 160 MiB of host RAM per slot at BF16 KV and no VRAM. FP8 KV copies the per-token scales too. hipMemcpyDefault, because the pools can be host-mapped. - ShortConv state goes to small device buffers through k_sconv_snapshot_pair and comes back through k_sconv_rollback_pair at keep_steps = 0. - Global-visit KV and the DSpark context are indexed by absolute position, so a restore sets seq_len back and caps dspark_len; nothing is copied. Safety: - save returns false unless the slot's seq_len equals seq_len, so the ring holds exactly the positions before it. - restore returns false unless the checkpoint is valid for the same seq_len and the slot still maps the same physical SWA pages; the serve then falls back to a full read. - reset_slot and free_slot drop the checkpoint, as the CPU and CUDA backends do. forward_batch also drops it if a position below its seq_len is written again. - restore resets DSpark's adaptive draft state as reset_slot does. - Off above 8 slots, to bound pinned host RAM, as in the CUDA backend. State is per slot, so --parallel 2..8 works. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SG5G8VwxLyU5bwfggEz6AU
a6babf9 to
fe2ab3b
Compare
|
I've rebased this branch onto current
What changed in this PR:
What I dropped, because
I've updated the description. Its numbers are new runs on |
Problem and result
Fixes #6627 on AMD (HIP).
mainnow has the prompt checkpoint hooks (save_prompt_checkpoint/restore_prompt_checkpointinink_backend.h) and the serve logic that uses them, with CPU and CUDA implementations. The HIP backend still has the defaultreturn false. So on AMD, a follow-up turn whose previous reply is not a prefix of the new prompt reads the whole conversation again, and so does every exact repeat or regeneration.This PR implements the two hooks for HIP. On a Radeon AI PRO R9700 (gfx1201), with a chat of about 19,700 tokens, prompt read time:
mainRelated discussion
#6627. Earlier versions of this PR added their own hooks and serve change, starting from the patch martinshane posted in #6627.
mainnow has its own interface and serve logic, so this version is rebased ontomainand only adds the HIP side. None of the earlier serve or interface code is left.#6737 fixes a HIP race (#6736) that makes identical greedy requests differ. It is not needed for this PR. The greedy exactness checks below ran with it applied, because without it the reference runs don't repeat.
Approach
One commit,
engine/src/inkling2/hip/ink_hip_backend.hip.cpponly.main's serve saves the checkpoint after readingprompt_len - 1prompt tokens and restores it when a later prompt starts with exactly those tokens.seq_lenis that token count both times. The HIP side:hipMemcpyAsyncper run of consecutive physical pages, queued on the backend stream with no host sync. This uses about 160 MiB of host RAM per slot at BF16 KV and no VRAM. FP8 KV copies the per-token scales too. The copies usehipMemcpyDefault, because the KV pools can be host-mapped (UMA, or the fallback ingrow_poolwhen VRAM runs out).k_sconv_snapshot_pairand comes back throughk_sconv_rollback_pairatkeep_steps = 0.seq_lenback and capsdspark_len. Nothing is copied.seq_lenequalsseq_len, so the ring holds exactly the positions before it.seq_lenand the slot still maps the same physical SWA pages. The serve then reads the whole prompt, as before.reset_slotandfree_slotdrop the checkpoint, as in the CPU and CUDA backends.forward_batchalso drops it if a position below itsseq_lenis written again.reset_slotdoes.--parallel2 to 8 works. Off above 8 slots, to bound pinned host RAM, as in the CUDA backend.The default path changes on purpose: follow-up turns and repeats now resume. Every prompt of 16 tokens or more pays for the checkpoint copy at its end. On cold reads of about 19,700 tokens with
--draft off, the first turn took 17,883 to 18,092 ms onmainand 17,895 to 18,005 ms with this PR, so the copy cost is within the run-to-run spread.Validation
Environment: Strata
mainat73d4f4196plus this branch;strata-inklingbuilt for gfx1201 only, standalone CMake ofengine/src/inkling2with the clang in the Strata venv's ROCm SDK (-DSTRATA_ENABLE_HIP=ON -DSTRATA_HIP_ARCHS=gfx1201), the same flags for both builds; Radeon AI PRO R9700 32 GB; Linux x86_64; Inkling-2-Mini SQ-20; served bymain's own serve (terminal/at73d4f4196) with--ctx-size 131072 --parallel 1unless noted. Requests are greedy (temperature 0).Passed:
HIP build, gfx1201: no warnings, the same as
main(0 in both builds).Multi-turn chat, about 19,700-token first prompt, prompt read per turn:
main--draft off--draft off--kv fp8usage.prompt_tokens_details.cached_tokens, reply changed, DSparkOn this card
mainread the whole conversation again on the "sent back as written" turns too (cached_tokens0, noRESUMEline), so the checkpoint covers those turns as well.Exact repeat, the same request sent twice:
mainResume position: in every checkpoint resume above, the engine's
RESUMEline equals the previous prompt length minus 1, andcached_tokensequals it.--parallel 2, two conversations sent at the same time: all four follow-up turns resumed, with prompt reads of 190 to 195 ms against 8,899 and 19,448 ms for the two concurrent first turns.First requests, with [Engine] strata-inkling HIP: fix the k1_loop_ctrl_up3 race on SWA visits (#6736) #6737 applied to both builds: token-identical to
mainon 9 prompts, with--draft offand with DSpark (200 tokens).Greedy output, with [Engine] strata-inkling HIP: fix the k1_loop_ctrl_up3 race on SWA visits (#6736) #6737 applied: an exact repeat, which resumes from the checkpoint, gives the same token ids as the first request at about 5,000 and about 19,700 prompt tokens, with
--draft offand with DSpark (200 tokens). Without [Engine] strata-inkling HIP: fix the k1_loop_ctrl_up3 race on SWA visits (#6736) #6737 the repeat differs on both builds (from token 7 to 163), with or without the checkpoint.Failed: none.
Not identical, and why I don't count it against this PR: after a changed previous reply (about 5,000 and 19,700 prompt tokens, both modes, #6737 applied), three ways of reaching the same prompt give three different replies, first differing at token 4 to 33: the checkpoint resume,
main's existing exact-prefix resume, and a cold read. The exact-prefix resume and the cold read also differ from each other, from token 4, and neither uses this PR's code. Each of the three repeats exactly when run again. The three paths read the last prompt tokens in different chunks (the checkpoint resume continues fromprompt_len - 1of the previous prompt), and chunking changes rounding. In the earlier version of this PR, with the checkpoint atprompt_len, the checkpoint resume was token-identical to the exact-prefix resume.Not run:
hipMemcpyDefaultand theseq_lenchecks, and the greedy checks above cover the result onmain.main.Limits
main's hooks.🤖 Generated with Claude Code
https://claude.ai/code/session_01SG5G8VwxLyU5bwfggEz6AU