[GH-ISSUE #2014] SYCL resident RAM mode: resident_stage_swaps stages the exchange without copying the evicted expert back #802

Closed
opened 2026-11-04 01:46:01 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @kuhlsnu on GitHub (Oct 12, 2026).
Original GitHub issue: https://github.com/Niko1221/Strata/issues/2014

The SYCL port of resident_stage_swaps has no device-to-host copy where the CUDA version has one. I found this reading the code while porting an exchange check; I have no Intel GPU, so nothing here ran.

CUDA, src/program/generate.cpp:292-299 (7695859a):

const SwapHome home = locate(s.layer);
const strata::core::OnDevice on(home.dev);
if (const cudaError_t e = cudaMemcpyAsync(src.exchange_buffer(q), home.cache->device_slot(slot),
                    (size_t) strata::kernels::cpu::expert_layout().blob_bytes(s.layer), cudaMemcpyDeviceToHost,
                    home.stream); e != cudaSuccess) {

SYCL, sycl/src/program/generate.cpp (resident_stage_swaps at :318), same spot:

const SwapHome home = locate(s.layer);
const strata::core::OnDevice on(home.dev);
/*
DPCT1124: cudaMemcpyAsync is migrated to asynchronous memcpy API.
...
*/

bool seen = false;

The migration comment is there but the memcpy itself is not, and the swap is still staged (staged.push_back, then stage_exchange). If this path runs, the RAM copy would take whatever is already in exchange buffer q as the evicted expert, so a later request routed to it on the CPU reads wrong weights, with no error.

What I could not check:

  • whether SYCL ever reaches this function (resident RAM mode with adaptive swaps on a SYCL build)
  • whether anything else fills the exchange buffer first

If it is reachable, this could be related to the silent wrong answers in #1484, though that one points at the expert kernels. A quick check: run resident RAM mode with adaptive swaps on SYCL and compare a swapped expert's RAM bytes with the model file.

Originally created by @kuhlsnu on GitHub (Oct 12, 2026). Original GitHub issue: https://github.com/Niko1221/Strata/issues/2014 **The SYCL port of `resident_stage_swaps` has no device-to-host copy where the CUDA version has one.** I found this reading the code while porting an exchange check; I have no Intel GPU, so nothing here ran. CUDA, `src/program/generate.cpp:292-299` (7695859a): ```cpp const SwapHome home = locate(s.layer); const strata::core::OnDevice on(home.dev); if (const cudaError_t e = cudaMemcpyAsync(src.exchange_buffer(q), home.cache->device_slot(slot), (size_t) strata::kernels::cpu::expert_layout().blob_bytes(s.layer), cudaMemcpyDeviceToHost, home.stream); e != cudaSuccess) { ``` SYCL, `sycl/src/program/generate.cpp` (`resident_stage_swaps` at :318), same spot: ```cpp const SwapHome home = locate(s.layer); const strata::core::OnDevice on(home.dev); /* DPCT1124: cudaMemcpyAsync is migrated to asynchronous memcpy API. ... */ bool seen = false; ``` The migration comment is there but the memcpy itself is not, and the swap is still staged (`staged.push_back`, then `stage_exchange`). If this path runs, the RAM copy would take whatever is already in exchange buffer `q` as the evicted expert, so a later request routed to it on the CPU reads wrong weights, with no error. **What I could not check:** - whether SYCL ever reaches this function (resident RAM mode with adaptive swaps on a SYCL build) - whether anything else fills the exchange buffer first If it is reachable, this could be related to the silent wrong answers in #1484, though that one points at the expert kernels. A quick check: run resident RAM mode with adaptive swaps on SYCL and compare a swapped expert's RAM bytes with the model file.
Author
Owner

@Niko1221 commented on GitHub (Oct 12, 2026):

Thank you, this was a real bug and your reading is exactly right. In the SYCL port of resident_stage_swaps the dpct migration had dropped both the device-to-host copy (cudaMemcpyAsync into the exchange buffer) and the stream synchronisation that follows it, but stage_exchange still ran. So with the resident RAM mode (--resident-experts, whose adaptive tier is the blocking one by default) the RAM copy took whatever the exchange buffer held as the evicted expert: that expert was lost and a later CPU read of it used the wrong weights, with no error. It is reachable on any SYCL build with a host mirror (an Arc B70/A750 without STRATA_VERIFY_NO_HOST).

The fix puts the copy and the wait back, as in the CUDA version. I also added a test aid, STRATA_CHECK_SWAPS=1, which compares each staged exchange buffer with the model file and, at the end of a CLI run, every RAM-copy blob with the file. On an Arc Pro B70 (IQ3_S, 300 tokens, adaptive swaps every round): the build without the copy-back had every staged buffer differ from the file (1,854 of 1,854) and 2,012 RAM blobs differing at the end; with the fix, 0 of 2,226 and 0 differ. On an A750 (IQ3_XXS, 1,500 tokens, 495 rounds, 3,841 swaps): 0 differ. The fix lands in 0.1.43.1 (out now). (It is not the cause of #1484: that one is in the expert kernels.)

<!-- gh-comment-id:6129324467 --> @Niko1221 commented on GitHub (Oct 12, 2026): Thank you, this was a real bug and your reading is exactly right. In the SYCL port of resident_stage_swaps the dpct migration had dropped both the device-to-host copy (cudaMemcpyAsync into the exchange buffer) and the stream synchronisation that follows it, but stage_exchange still ran. So with the resident RAM mode (--resident-experts, whose adaptive tier is the blocking one by default) the RAM copy took whatever the exchange buffer held as the evicted expert: that expert was lost and a later CPU read of it used the wrong weights, with no error. It is reachable on any SYCL build with a host mirror (an Arc B70/A750 without STRATA_VERIFY_NO_HOST). The fix puts the copy and the wait back, as in the CUDA version. I also added a test aid, STRATA_CHECK_SWAPS=1, which compares each staged exchange buffer with the model file and, at the end of a CLI run, every RAM-copy blob with the file. On an Arc Pro B70 (IQ3_S, 300 tokens, adaptive swaps every round): the build without the copy-back had every staged buffer differ from the file (1,854 of 1,854) and 2,012 RAM blobs differing at the end; with the fix, 0 of 2,226 and 0 differ. On an A750 (IQ3_XXS, 1,500 tokens, 495 rounds, 3,841 swaps): 0 differ. The fix lands in 0.1.43.1 (out now). (It is not the cause of #1484: that one is in the expert kernels.)
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#802
No description provided.