[PR #550] [CLOSED] generate: residency-table uploads wait for their own copy before the non-blocking streams read the table #2684

Closed
opened 2026-11-04 02:02:22 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/Niko1221/Strata/pull/550
Author: @sergqwer
Created: 10/2/2026
Status: ❌ Closed

Base: main ← Head: pr/res-upload-order


📝 Commits (1)

  • 000f288 generate: residency-table uploads wait for their own copy before the non-blocking streams read the table

📊 Changes

1 file changed (+16 additions, -9 deletions)

View changed files

📝 src/program/generate.cpp (+16 -9)

📄 Description

Every upload of the expert residency table, host_res to d_res and each stage's, is a plain cudaMemcpy (src/program/generate.cpp, 9 call sites). The kernels that read the table run on streams created cudaStreamNonBlocking.

  • A pageable host-to-device cudaMemcpy may return once the data is staged, before its DMA has landed.
  • A non-blocking stream does not wait for the legacy stream the copy runs on.

So nothing orders a kernel enqueued right after an upload (the next verify window after an adaptive swap, a trim, a refill) behind the copy. That kernel could read a table half old, half new: an expert computed by both the GPU and the CPU, or by neither.

The table is ~100 KB and usually lands in microseconds, so this rarely fires. It is the same class as #532 and #536, where the tests' uploads raced their non-blocking streams. Ours made one of those tests fail in 6 of 20 runs.

Fix: the uploads go through res_put(), which waits for the copy on the current device's legacy stream (cudaStreamSynchronize(cudaStreamLegacy)): that copy only, not the device.

Measured on an RTX 5090, IQ2_XS (ISTA), --expert-cache 14900, v0.1.37 against this PR:

  • First-token logits after a 2K and a 32K prompt: byte-identical.
  • Decode (a 32K prompt, then up to 600 tokens, --stop-eos), 6 interleaved pairs: 15.82 ms a round against 15.93 (+0.7%, within noise). One more pair is left out: 19.80 ms on a different token path, a desktop stall.

🤖 Generated with Claude Code

https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio


🔄 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/550 **Author:** [@sergqwer](https://github.com/sergqwer) **Created:** 10/2/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/res-upload-order` --- ### 📝 Commits (1) - [`000f288`](https://github.com/Niko1221/Strata/commit/000f2887d4a61d764bfaf4b25a5f60cfd0ee7ee8) generate: residency-table uploads wait for their own copy before the non-blocking streams read the table ### 📊 Changes **1 file changed** (+16 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `src/program/generate.cpp` (+16 -9) </details> ### 📄 Description Every upload of the expert residency table, host_res to `d_res` and each stage's, is a plain `cudaMemcpy` (`src/program/generate.cpp`, 9 call sites). The kernels that read the table run on streams created `cudaStreamNonBlocking`. - A pageable host-to-device `cudaMemcpy` may return once the data is staged, before its DMA has landed. - A non-blocking stream does not wait for the legacy stream the copy runs on. So nothing orders a kernel enqueued right after an upload (the next verify window after an adaptive swap, a trim, a refill) behind the copy. That kernel could read a table half old, half new: an expert computed by both the GPU and the CPU, or by neither. The table is ~100 KB and usually lands in microseconds, so this rarely fires. It is the same class as #532 and #536, where the tests' uploads raced their non-blocking streams. Ours made one of those tests fail in 6 of 20 runs. **Fix:** the uploads go through `res_put()`, which waits for the copy on the current device's legacy stream (`cudaStreamSynchronize(cudaStreamLegacy)`): that copy only, not the device. **Measured** on an RTX 5090, IQ2_XS (ISTA), `--expert-cache 14900`, v0.1.37 against this PR: - First-token logits after a 2K and a 32K prompt: byte-identical. - Decode (a 32K prompt, then up to 600 tokens, `--stop-eos`), 6 interleaved pairs: 15.82 ms a round against 15.93 (+0.7%, within noise). One more pair is left out: 19.80 ms on a different token path, a desktop stall. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01VZy1yKaDDiA8a7svdwaHio --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-04 02:02:22 +07:00
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#2684
No description provided.