[PR #3288] [Engine] conversation snapshot: stage parked-state copies through pinned memory on Windows/WDDM #4549

Open
opened 2026-11-07 15:37:18 +07:00 by bsakaguchi · 0 comments
Owner

📋 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)

  • b663eec conversation 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 262144 are refused or corrupted: the engine logs checkpoint 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.

#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 from conversation_state.cpp to the single copy_nonblocking chokepoint in conversation_copy.hpp that 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 current main (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=0 restores 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 table tools/hip/gfx1201-hipblaslt-100500.txt. The branch files are byte-identical (SHA-256) to the files built and tested here.

Passed:

  • HIP build of main @ c62d5e3a, unpatched, 11 unique ~1.5k-token prompts via serve/server.py (park-unique script): OK=1 ERR=10, 49 non-finite events - bug reproduces on the 0.2.9 line.
  • Same build + this patch: 2/2 rounds OK=11 ERR=0, 0 non-finite.
  • On 0.2.0-beta (main @ e88ee39d, same rig and script): unpatched OK=0 ERR=11, nf=43 (also on the official prebuilt install); patched 2/2 rounds OK=11 ERR=0, nf=0.
  • On 0.1.45 (same rig, same scripts): baseline rounds nf=35/41/17 -> patched 5/5 rounds nf=0; production constellation 22/22 requests OK, 0 non-finite, decode ~55 tok/s.

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 current main; 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 mirroring conversation_snapshot.cpp's existing on_device(); it compiles and runs on hardware under HIP. CUDA compilation stays unverified. The cudaHostAlloc failure 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=0 restores 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.

## 📋 Pull Request Information **Original PR:** https://github.com/Niko1221/Strata/pull/3288 **Author:** [@denis-1337](https://github.com/denis-1337) **Created:** 10/19/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix-checkpoint-copy` --- ### 📝 Commits (1) - [`b663eec`](https://github.com/Niko1221/Strata/commit/b663eec20c42796236e6c4681e1327030734d196) conversation snapshot: stage synchronous host<->device copies through pinned memory ### 📊 Changes **1 file changed** (+86 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `src/core/conversation_copy.hpp` (+86 -0) </details> ### 📄 Description Issue: Resolves #3036 ## Problem and result On Windows/WDDM, parked-conversation snapshot copies at `--max-context 262144` are refused or corrupted: the engine logs `checkpoint 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 from `conversation_state.cpp` to the single `copy_nonblocking` chokepoint in `conversation_copy.hpp` that 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 current `main` (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=0` restores 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 table `tools/hip/gfx1201-hipblaslt-100500.txt`. The branch files are byte-identical (SHA-256) to the files built and tested here. **Passed:** - HIP build of `main` @ c62d5e3a, unpatched, 11 unique ~1.5k-token prompts via `serve/server.py` (park-unique script): `OK=1 ERR=10`, 49 non-finite events - bug reproduces on the 0.2.9 line. - Same build + this patch: 2/2 rounds `OK=11 ERR=0`, 0 non-finite. - On 0.2.0-beta (`main` @ e88ee39d, same rig and script): unpatched `OK=0 ERR=11`, nf=43 (also on the official prebuilt install); patched 2/2 rounds `OK=11 ERR=0`, nf=0. - On 0.1.45 (same rig, same scripts): baseline rounds nf=35/41/17 -> patched 5/5 rounds nf=0; production constellation 22/22 requests OK, 0 non-finite, decode ~55 tok/s. **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 current `main`; 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 mirroring `conversation_snapshot.cpp`'s existing `on_device()`; it compiles and runs on hardware under HIP. CUDA compilation stays unverified. The `cudaHostAlloc` failure 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=0` restores 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Niko1221/Strata#4549
No description provided.