mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[PR #3288] [Engine] conversation snapshot: stage parked-state copies through pinned memory on Windows/WDDM #4549
Labels
No labels
needs-format
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
Niko1221/Strata#4549
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/Niko1221/Strata/pull/3288
Author: @denis-1337
Created: 10/19/2026
Status: 🔄 Open
Base:
main← Head:fix-checkpoint-copy📝 Commits (1)
b663eecconversation snapshot: stage synchronous host<->device copies through pinned memory📊 Changes
1 file changed (+86 additions, -0 deletions)
View changed files
📝
src/core/conversation_copy.hpp(+86 -0)📄 Description
Issue: Resolves #3036
Problem and result
On Windows/WDDM, parked-conversation snapshot copies at
--max-context 262144are refused or corrupted: the engine logscheckpoint save: conversation snapshot running-state copy: invalid argument, and every later request returns non-finite (NaN) output. After this change the synchronous host<->device snapshot copies are staged through a real pinned buffer, and the same workload runs clean on the same rig.Related discussion
#3036 (reproduced on 0.1.45, 0.2.0-beta, and again on the current 0.2.9 line). Bug fix, no defaults changed. Review feedback from @midhatn on #3037 is folded in. Rebased onto current
main: the fix moved fromconversation_state.cppto the singlecopy_nonblockingchokepoint inconversation_copy.hppthat the conversation-cache rework (#3779, #3712) routes both the running-state and the K/V snapshot copies through. An intermediate revision that staged only the running-state copies still went NaN in a second park round on currentmain(the ~238 MB/conversation K/V copies were unprotected); staging at the chokepoint fixed both. The new opt-in async paths (STRATA_CKPT_ASYNC,STRATA_PARK_ASYNC) do not change the default synchronous path this bug lives on.Approach
Every synchronous host<->device snapshot copy (running-state and K/V alike) is staged first through a pinned 16 MiB buffer (device->pinned via the copy engine, pinned->destination via memcpy, sync per chunk), because on Windows/WDDM the HIP runtime misclassifies C++ heap destinations as pinned host memory: the direct copy is refused, or when accepted it interleaves with expert H2D streaming on the copy engine and corrupts the bytes (decode then reads garbage as expert weights and the grouped GEMM writes NaN - the corruption survives dropping the conversation cache, which is how the K/V copies were pinned down as a second carrier). The copy direction is derived from pointer attributes (device allocations are always registered; the misclassified heap reads as "not device"), queried through the HIP API on HIP builds since the CUDA-shaped shim has no pointer query. A refused
Default-kind copy is consumed and retried once with the direction explicit, then the staged path is the safety net. Queued copies (ordered by the caller's event) and device-to-device copies (the VRAM-slot paths) keep the direct path.STRATA_CKPT_STAGE_FIRST=0restores the old path for A/B. Linux is unaffected (the direct path works there; staging is harmless). Cost: one memcpy hop per snapshot copy; measured decode unchanged (~55 tok/s).Validation
Tested on
main@c62d5e3a(0.2.9 line), Windows 11 Pro build 26300, AMD RX 9070 XT (gfx1201), driver 32.0.32015.2008, model IQ3_S,--kv int8 --max-context 262144 --expert-cache auto --spec 4, tuning tabletools/hip/gfx1201-hipblaslt-100500.txt. The branch files are byte-identical (SHA-256) to the files built and tested here.Passed:
main@c62d5e3a, unpatched, 11 unique ~1.5k-token prompts viaserve/server.py(park-unique script):OK=1 ERR=10, 49 non-finite events - bug reproduces on the 0.2.9 line.OK=11 ERR=0, 0 non-finite.main@e88ee39d, same rig and script): unpatchedOK=0 ERR=11, nf=43 (also on the official prebuilt install); patched 2/2 roundsOK=11 ERR=0, nf=0.Failed: none observed with the patch applied. (One intermediate revision - staging only the running-state copies in
conversation_state.cpp- went NaN in round 2 on currentmain; that is why the fix sits at the chokepoint. Noted for reviewers who saw #3037.)Not run: CUDA, SYCL and Metal builds - no CUDA/SYCL toolchain and no Apple hardware on this machine. The change uses only the CUDA-shaped API already used in these files (
cudaHostAlloc,cudaMemcpyAsync,cudaStreamSynchronize,cudaFreeHost) plus the pointer-attribute query, with the HIP/Metal branches mirroringconversation_snapshot.cpp's existingon_device(); it compiles and runs on hardware under HIP. CUDA compilation stays unverified. ThecudaHostAllocfailure path and the stream-sync failure path are inspection-only (no fault injection), as noted by @midhatn in review.Limits
Staging adds one memcpy hop per snapshot copy (a few ms per parked conversation).
STRATA_CKPT_STAGE_FIRST=0restores the old path for A/B. The misclassification itself lives in the WDDM/HIP layer; this PR avoids it on the snapshot path rather than fixing the classification.Note: this issue and the accompanying PR were prepared by an AI agent (Qwen3.8-Flash-Next IQ3_S, served by Strata itself) together with the account owner.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.