mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-03 19:03:30 +07:00
[GH-ISSUE #5480] [Engine] Windows/HIP: silent data corruption in hipMemcpy2D uploads from read-only file mappings, plus two engine findings (DP pinned-KV waste blocking 1M startup; VRAM reserve coupling into prefill chunk size) #5446
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#5446
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?
Originally created by @bigbrid2023 on GitHub (Nov 7, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/5480
Hi — this is a focused report of three engine-level findings from Windows dual-GPU field work. All three were localized and measured on a build of the rdna3 fork (HEAD
bd34f079da92e8b47dc4de6b40d894a867154797), but in each case the mechanism sits in engine code shared with upstream — the weight-upload path, the DP session allocation, and the prefill staging logic — not in fork-specific code, which is why we are filing here as well as filing a full dual-card report with the fork. For each finding we state where it was verified and why we believe it applies upstream. None of the three has yet been re-verified on a stock upstream build; a standalone reproduction script for Finding 1 is included in the Appendix at the end of this issue.Environment
amdhip64_7.dll, SHA256344386DD39B2BBA7060D62720054B9375401F23F2BCD29D730DD8D43019683CD) is byte-identical between the fork build and the stock 0.1.56 engine on this machine, and the Finding 1 reproduction uses no engine code at all.Summary
hipMemcpy2Dwith a read-only file mapping (MapViewOfFile,FILE_MAP_READ) as the source silently copies wrong data while the API returns success. In the engine this corrupted TP column-slice weight uploads at load time and produced deterministic garbage output. Writable RAM and pinned memory as sources are clean, and packing the slice contiguously on CPU + a singlehipMemcpyis clean (240 slices read back with 0 bytes differing).Finding 1 —
hipMemcpy2Dfrom a read-only file mapping silently corrupts dataSymptom in the engine. Dual-card tensor-parallel serve starts and generates, but output is deterministic garbage (draft acceptance 0). Layer-split without TP on the same build is fully clean.
Engine-level evidence. The TP path uploaded GGUF weights as column slices via
hipMemcpy2D. GPU readback of the first layer'sblk.0.ssm_out.weightagainst the correct slice:This is load-time model-data corruption, not an output/encoding artifact. Segment-by-segment comparison of the full first layer shows zero difference up to the layer-0 output projection, which is the first divergence (relative RMS ≈ 1.3889). All 96 dual-card all-reduces in the first window are bit-exact against the FP32 sum of both inputs, ruling out link desync.
Standalone reproduction (no engine code). Python ctypes against the same
amdhip64_7.dll, copying the same column half-slices (8,355,840 bytes each):hipMemcpy2DMapViewOfFile,FILE_MAP_READ)hipMemcpy2DhipMemcpy2DhipMemcpy(The two byte counts above — 8,273,507 from the engine readback and 8,323,025 from the standalone repro — are two different slices/stages of the same bug, not a discrepancy.)
Where verified / why upstream-relevant. Verified on the fork build and, independently of any engine, via ctypes against the HIP DLL that is byte-identical to the one shipping with stock 0.1.56 on this machine. Any engine path that uploads 2D slices directly out of a read-only mmap of the model file on Windows/HIP is exposed to the same failure mode. We have not isolated which component inside the HIP/Windows mapped-memory path is responsible (no alternate HIP version tested) and are not claiming a general Windows/driver defect — only that this source/method combination is reliably wrong on this rig while reporting success. Not yet reproduced on a stock upstream build; the script in the Appendix lets you verify in minutes.
Finding 2 — DP foreign sessions allocate ≈12.375 GiB of pinned host KV and discard it; blocks 1M startup
Mechanism (source-level, shared engine code). In
generate-main-keep.cpp, a DP foreign session runssession_init(), whoseqsa_state_init()allocates a full pinned host KV for every QSA layer. The DP path then overwrites.hostwith the owner session's KV — the first allocation is never used by that path but keeps holding pinned/lockable memory. On a dual-GPU WDDM system this matters: the source's arena branch notes a default lock/mapping protection of ≈8 GiB once many host pages are mapped to two GPUs, and 1M-context dual configs failed to start at high pin caps on the original build (pin 32 and pin 16 failed during expert-cache init; pin 12 completed allocation but never became READY in 600 s; pin 8 started and passed functional checks).Fix and pin ladder. A candidate build (
engine-shared-kv) lets full-geometry DP foreign sessions borrow the owner session's host KV at init instead of allocating their own (with validation of layer range, context length, page count and KV mode/format/pointer; TP half-head sessions keep the original allocation). Runtime logs quantify the saving exactly: 12 ×avoided 1107297280 bytes= 13,287,567,360 bytes ≈ 12.375 GiB skipped. On the shared-KV build (1M max-context, vision on, reserve 2560 MiB), the pin ladder is (two functional 64K requests per rung — functional timings, not medians):Caveat. This fix provably removes wasted pinned allocations. It is not established as the cause of the intermittent cold-start wrong answer noted at the end of this report, and we do not claim that.
Finding 3 — VRAM reserve couples into prefill chunking
Mechanism (shared engine code).
Prefill::take_stage()sizes the KV staging pool from the session's total page count andPrefill::carve()sizes index workspaces frommax_cells; the DP path (dp_step_for()/run_dp()) requires balanced even chunk counts. Raising max-context to 1M at reserve 2560 MiB shrank the per-GPU expert cache by ≈1.9 GiB and dropped the chunk cap from 32,768 to 29,440. A 65,536-token input then splits as 4 × 16,384 instead of 2 × 32,768 (ceil(65536/29440) = 3, padded to even 4) — more expert movement, more cross-card state publishes, smaller GEMMs.Measurements (same shared-KV engine, pin 16 GiB, only max-context changed; functional runs):
Lowering reserve restored the 32,768 chunk: reserve 1536/lend93 measured 3192.9 tok/s (+≈48% vs 2164.2). The adopted final values, reserve 2048/lend97, keep chunk = 32,768 with more external-card headroom and measured 3145.9 / 3191.5 tok/s on cold 64K runs — ≈3150–3200 vs the ≈2160–2175 slow configuration (≈+46–48%). Because lowering reserve both enlarges the cache and crosses the chunk threshold, the gain cannot be split precisely between the two effects.
Why upstream-relevant. The staging/chunk sizing logic is shared engine code, and the failure mode is silent: nothing logs that a reserve change has cut the chunk cap and cost a third of the prefill rate on identical input. A log line (or guardrail) when the chunk cap drops below the configured maximum would have saved the debugging round; at minimum the coupling is worth documenting.
Minimal repro
Finding 1 reproduces without any engine code. The standalone script
hip_copy_diagnostic.py(Python, ctypes againstamdhip64_7.dll) maps the model file read-only viaMapViewOfFile(..., FILE_MAP_READ), copies column half-slices withhipMemcpy2D, and compares device readback against the expected bytes; writable RAM, pinned memory and packed single-hipMemcpyvariants run as controls. Expected results on an affected rig: read-only-mapping source → 8,323,025 / 8,355,840 bytes differ with the API returning success; every control → 0 bytes differ. The script is included in the Appendix at the end of this issue (SHA2567a61551fbc6a8d93e85e60c09bd5ebe29e2ba6ab52f5e6a02cfbe02a8d9fff67).Workarounds
Finding 1 — pack before uploading. Pack each column slice into one contiguous CPU buffer at load time and upload with a single
hipMemcpy(in our fork tree:STRATA_TP_UPLOAD_PACKED=1; optional readback diagnosticSTRATA_TP_UPLOAD_CHECK=1). Packing happens only at load; prefill/decode use the resident weights. With the packed build, all 240 row/column slices read back with 0 bytes differ.Finding 2 — borrow the owner KV instead of duplicating it. The
engine-shared-kvbuild lets full-geometry DP foreign sessions borrow the owner session's host KV at init (with validation) instead of allocating their own; TP half-head sessions keep the original allocation. Absent that build, low pin caps are the only lever we found (pin 8 started on the original build; 12 completed allocation but never became READY, 16 and 32 failed earlier).Finding 3 — keep the chunk cap at its maximum. Choose reserve values that leave the prefill chunk cap at 32,768 (on this rig: reserve 2048/lend97 for the 1M configuration), and treat any silent drop of the chunk cap as a performance regression to investigate, not a tuning detail.
Verification status
bd34f079da92e8b47dc4de6b40d894a867154797) on the single rig described under Environment, with full logs retained.generate-main-keep.cpp, and the prefill staging/chunk logic — not in fork-specific code. Finding 1 additionally reproduces with no engine code at all, against a HIP runtime DLL that is byte-identical between the fork build and stock 0.1.56 on this machine.Open item, for completeness. With the dual "stage2" configuration used for the final numbers in the companion report, one fresh engine process failed its first 64K request after a cold start (retrieval codes not recovered); six subsequent cold starts with identical inputs all passed. The root cause is not located, and those configurations are labelled "Test", not production.
Companion full report (dual-card results, topology, verification detail): https://github.com/nicejunjie/Strata-rdna3/issues/6
Appendix — reproduction script
hip_copy_diagnostic.py— standalone Finding 1 reproduction (Python/ctypes, no engine code). SHA256:7a61551fbc6a8d93e85e60c09bd5ebe29e2ba6ab52f5e6a02cfbe02a8d9fff67hip_copy_diagnostic.py (98 lines, SHA256 `7a61551fbc6a8d93e85e60c09bd5ebe29e2ba6ab52f5e6a02cfbe02a8d9fff67`)
@github-actions[bot] commented on GitHub (Nov 7, 2026):
Thanks for the issue. To keep the tracker readable, every item needs an area prefix in the title and the parts of the issue form filled in. This one is missing:
Edit the issue (title and description) and this note goes away on its own. If it is still missing parts in 5 days it will be closed, which is not a rejection: fix it and comment
/reopen.Details: CONTRIBUTING.md
@github-actions[bot] commented on GitHub (Nov 7, 2026):
Thanks, this follows the format now.