[PR #550] [CLOSED] DeepSeek: close two expert-table publication races #591

Closed
opened 2026-10-29 21:27:15 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/550
Author: @handmade0octopus
Created: 10/27/2026
Status: ❌ Closed

Base: main ← Head: pr/ds4-stream-table-races


📝 Commits (1)

  • 06bd0c4 DeepSeek: close two expert-table publication races

📊 Changes

2 files changed (+85 additions, -1 deletions)

View changed files

📝 src/ds4/ds4_model.cu (+12 -1)
➕ tests/ds4_tab_set_buffer_sentinel.cu (+73 -0)

📄 Description

Summary

  • Prevent a streamed expert from landing in a recent slot while that same expert already has a pending swap-in. It continues through the normal staging path.
  • Synchronize each device stream before replacing its single host-mapped rc_upd pair buffer, so an earlier tab_set cannot read overwritten input.
  • Fail stop if that synchronization fails rather than continuing with unknown host/device expert-table state.
  • Include a standalone CUDA sentinel for the mapped-input reuse hazard (not registered with CTest because its unguarded half intentionally demonstrates the race).

1. Swap/landing duplicate publication

land_dst() could select an expert with e == l.sw_in. The recent-slot landing and pending swap then owned the same expert, and their two different vram_tab[e] updates could enter one tab_set launch. tab_set_kernel() assigns pairs to independent threads, so host append order does not determine which value survives.

An instrumented live capture showed exactly this for layer 7, expert 73: one submitted batch contained the recent-slot write followed by the swap write, while the host canonical slot was 94 and the device table/recent slot used slot 63:

history serial=52 rc_clock=55 pair=15  submitted=145 value=0x1a433e0800  # recent landing
history serial=52 rc_clock=55 pair=133 submitted=145 value=0x18f82b1000  # pending swap
host l.slot[73]=94; live device table/recent slot=63

Excluding e == l.sw_in mirrors the recent-fill path's existing exclusion. It fixes both the duplicate table publication and duplicate ownership; merely deduplicating writes would not fix ownership. No expert or route is skipped: the guarded pick uses staging and the pending swap completes normally.

2. Host-mapped input reuse

tick_flush() reuses one mapped rc_upd buffer per device. A later flush could overwrite those pairs before an earlier queued tab_set read them, especially across back-to-back cache_drain() / rc_drain() flushes. Live instrumentation separately observed an intended eviction-to-zero that remained nonzero on device.

The included tests/ds4_tab_set_buffer_sentinel.cu uses the exact three-line tab_set_kernel and a delay to force two batches to queue before either reads the shared input. On an RTX 4090 D it produced:

UNGUARDED table: 1000 1001 222 333
UNGUARDED_LOSS_OBSERVED: A's zero/111 updates were overwritten by B's mapped input
GUARDED table: 0 111 222 333
GUARDED_PASS: predecessor sync preserved both intended batches

Synchronizing before every nonempty overwrite covers ordinary ticks and both drain paths. Ordinary forward ticks already synchronize this stream, so their additional wait is normally a no-op; a drain now waits only for the predecessor work required for correctness.

Validation

The two normal-path guards were tested together on Windows with DS4_STREAM_WIN=1, DS4_LAND=1, full streaming zero-copy, and DSpark enabled:

  • Fresh 104,294-token prompt, forced 96-token decode: exact completion, zero reuse, no CUDA or diagnostic invariant error, graceful exit.
  • Fresh 32,768-token prompt, forced 2,048-token decode with debug instrumentation disabled: exact completion, zero reuse, no errors, graceful exit. Result: 967.532 tok/s prefill, 30.062 tok/s decode; 97.695% expert-cache hits and 78.441% DSpark acceptance.
DONE 2048 32768 33867.6 68125.7 length 946 1206 0 580045 593730

The instrumented candidate also answered real HTTP generations and ran under exact-token capture with first-fault monitoring. These tests support the fixes but do not prove that a previously observed, un-reproduced CUDA IMA is eliminated; this PR fixes the two independently demonstrated corruption mechanisms above.

PR-base validation: clean Windows CUDA 12.8 / arch 89 Release build of maya-ds4 on upstream main c4be544 (v1.1.31) passed. Built engine SHA-256: F9805305BBFD28E148372277CE9E8E1D4F4676EBDDF414EBCFF6AC6A5D920D83. git diff --check and independent static review passed with no remaining blockers.

Notes

  • The routing, expert-selection, and normal swap algorithms are unchanged.
  • No debug instrumentation or local performance tuning is included.
  • The synchronization error path intentionally aborts: after a CUDA failure the table state cannot be vouched for, so continuing could silently publish inconsistent ownership.

🔄 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/mw00/project-maya/pull/550 **Author:** [@handmade0octopus](https://github.com/handmade0octopus) **Created:** 10/27/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/ds4-stream-table-races` --- ### 📝 Commits (1) - [`06bd0c4`](https://github.com/mw00/project-maya/commit/06bd0c46b37acabaaa07d6e621c599cb097638a9) DeepSeek: close two expert-table publication races ### 📊 Changes **2 files changed** (+85 additions, -1 deletions) <details> <summary>View changed files</summary> 📝 `src/ds4/ds4_model.cu` (+12 -1) ➕ `tests/ds4_tab_set_buffer_sentinel.cu` (+73 -0) </details> ### 📄 Description ## Summary - Prevent a streamed expert from landing in a recent slot while that same expert already has a pending swap-in. It continues through the normal staging path. - Synchronize each device stream before replacing its single host-mapped `rc_upd` pair buffer, so an earlier `tab_set` cannot read overwritten input. - Fail stop if that synchronization fails rather than continuing with unknown host/device expert-table state. - Include a standalone CUDA sentinel for the mapped-input reuse hazard (not registered with CTest because its unguarded half intentionally demonstrates the race). ## 1. Swap/landing duplicate publication `land_dst()` could select an expert with `e == l.sw_in`. The recent-slot landing and pending swap then owned the same expert, and their two different `vram_tab[e]` updates could enter one `tab_set` launch. `tab_set_kernel()` assigns pairs to independent threads, so host append order does not determine which value survives. An instrumented live capture showed exactly this for layer 7, expert 73: one submitted batch contained the recent-slot write followed by the swap write, while the host canonical slot was 94 and the device table/recent slot used slot 63: ```text history serial=52 rc_clock=55 pair=15 submitted=145 value=0x1a433e0800 # recent landing history serial=52 rc_clock=55 pair=133 submitted=145 value=0x18f82b1000 # pending swap host l.slot[73]=94; live device table/recent slot=63 ``` Excluding `e == l.sw_in` mirrors the recent-fill path's existing exclusion. It fixes both the duplicate table publication and duplicate ownership; merely deduplicating writes would not fix ownership. No expert or route is skipped: the guarded pick uses staging and the pending swap completes normally. ## 2. Host-mapped input reuse `tick_flush()` reuses one mapped `rc_upd` buffer per device. A later flush could overwrite those pairs before an earlier queued `tab_set` read them, especially across back-to-back `cache_drain()` / `rc_drain()` flushes. Live instrumentation separately observed an intended eviction-to-zero that remained nonzero on device. The included `tests/ds4_tab_set_buffer_sentinel.cu` uses the exact three-line `tab_set_kernel` and a delay to force two batches to queue before either reads the shared input. On an RTX 4090 D it produced: ```text UNGUARDED table: 1000 1001 222 333 UNGUARDED_LOSS_OBSERVED: A's zero/111 updates were overwritten by B's mapped input GUARDED table: 0 111 222 333 GUARDED_PASS: predecessor sync preserved both intended batches ``` Synchronizing before every nonempty overwrite covers ordinary ticks and both drain paths. Ordinary forward ticks already synchronize this stream, so their additional wait is normally a no-op; a drain now waits only for the predecessor work required for correctness. ## Validation The two normal-path guards were tested together on Windows with `DS4_STREAM_WIN=1`, `DS4_LAND=1`, full streaming zero-copy, and DSpark enabled: - Fresh 104,294-token prompt, forced 96-token decode: exact completion, zero reuse, no CUDA or diagnostic invariant error, graceful exit. - Fresh 32,768-token prompt, forced 2,048-token decode with debug instrumentation disabled: exact completion, zero reuse, no errors, graceful exit. Result: **967.532 tok/s prefill, 30.062 tok/s decode**; 97.695% expert-cache hits and 78.441% DSpark acceptance. ```text DONE 2048 32768 33867.6 68125.7 length 946 1206 0 580045 593730 ``` The instrumented candidate also answered real HTTP generations and ran under exact-token capture with first-fault monitoring. These tests support the fixes but do not prove that a previously observed, un-reproduced CUDA IMA is eliminated; this PR fixes the two independently demonstrated corruption mechanisms above. PR-base validation: clean Windows CUDA 12.8 / arch 89 Release build of `maya-ds4` on upstream `main` `c4be544` (`v1.1.31`) **passed**. Built engine SHA-256: `F9805305BBFD28E148372277CE9E8E1D4F4676EBDDF414EBCFF6AC6A5D920D83`. `git diff --check` and independent static review passed with no remaining blockers. ## Notes - The routing, expert-selection, and normal swap algorithms are unchanged. - No debug instrumentation or local performance tuning is included. - The synchronization error path intentionally aborts: after a CUDA failure the table state cannot be vouched for, so continuing could silently publish inconsistent ownership. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:27:15 +07:00
Sign in to join this conversation.
No labels
pull-request
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
mw00/project-maya#591
No description provided.