[PR #646] [CLOSED] DeepSeek ds4 recent slots: a failed fill must not publish its slot (+ DS4_FAULT_RC_FILL test lever) #647

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

📋 Pull Request Information

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

Base: main ← Head: pr/rc-fill-error


📝 Commits (2)

  • 9308175 ds4 recent slots: DS4_FAULT_RC_FILL=N test lever (every Nth fill fails at issue)
  • fa4b5d7 ds4 recent slots: a failed fill must not publish its slot

📊 Changes

1 file changed (+38 additions, -2 deletions)

View changed files

📝 src/ds4/ds4_model.cu (+38 -2)

📄 Description

DeepSeek ds4 recent slots: a failed fill must not publish its slot (silent stale-weight inference)

Follow-up to the cache-management bug report shared by a delta-inference-engine dev (a failed
promotion still published the expert→slot mapping, silently corrupting inference). Auditing the same
class here found the discipline already present in the streamed-expert landing path (lane_copy
sets pull->bad[i] on a failed read, and the mapper publishes a landing only when
P->done == seq && P->bad[q] == 0) — but absent in the recent-slot fills path, which had the bug
the report describes, verbatim.

The bug (rc_loop, fills)

stream_expert(l, m, j.expert, sat(...), rc_cs[di], err);            // return value DISCARDED
cudaEventRecord(l.rc_ev[j.slot * l.nm + m], rc_cs[di]);             // recorded unconditionally
...
if (done) { rc_done[l.rc_off + j.slot].store(j.gen, release); ... } // on event success alone
// tick:
if (e < 0 || rc_done[l.rc_off + i].load(acquire) != l.rc_gen[i]) continue;
... l.slot[e] = ...; set_tab(e, i);                                 // stale/partial bytes become tab[e]

stream_expert carefully checks every cudaMemcpyAsync enqueue and returns false + fills err on
failure — the fills path threw that away. A failed enqueue still recorded the event, still stored
rc_done, and the tick published the mapping and the device table entry (vram_tab[e] → the
slot's address) over stale or partial bytes. The err text was written and then discarded. Nothing
was logged.

On this engine the fill source is the pinned RAM tier (not storage), so the realistic triggers are a
failed H2D enqueue or a lost device rather than a failed file read — but the failure class, the
silent publish, and the corruption are exactly the ones reported.

The fix

Mirrors the landing path's own discipline and the report's fix semantics:

  • the issue loop captures stream_expert()'s return; on failure the job never reaches fly, so
    nothing stores rc_done, and the tick's rc_done != rc_gen check never publishes the slot nor
    its vram_tab entry
    — the previous mapping (if any) stays intact;
  • rc_pending is decremented at once, so rc_drain's bounded wait cannot count the dead job;
  • the failure is logged with layer/expert/slot and the error text
    (ds4: recent-slot fill failed, slot left unmapped: ...) instead of being discarded;
  • the affected expert routes over its non-VRAM lane (correct, slower); the slot retires for the run
    (rc_fill keeps holding it out of the free list — bounded by the small per-layer recent-slot pool).

Proof by injected failure

New test lever, off by default: DS4_FAULT_RC_FILL=N makes every Nth fill fail at issue (as if
its first H2D enqueue failed — nothing copied) while the completion event still records. Commit 1
keeps the pre-fix behavior, commit 2 is the fix; same lever, same stimulus, both builds:

arm env injected failures published anyway rc_drain stalls
commit 1 (pre-fix) plain 8,613 8,613 (0 blocked) 0
commit 2 (fix) plain 1,278 0 — 1,279 slot left unmapped 0
commit 2 (fix) production (DS4_STREAM_ZC_ALL) 1,280 0 — 1,280 slot left unmapped 0

Identical stimulus, opposite publish behavior, rc_drain healthy everywhere.

Two honest observations from the end-to-end runs (4 fixed greedy prompts, temperature 0, pinned lane
calibration):

  • The degradation is silent-numerical, not cosmetic. Even with thousands of stale publishes, the
    pre-fix arm produced fluent, on-topic answers — every arm did. Nothing in the output text flags the
    corruption; only the bytes are wrong. That matches "silently corrupt inference results" and is
    exactly why this class needs the publish gate rather than an output-level check.
  • Our own production tuning masks the stale publishes: under DS4_STREAM_ZC_ALL full coverage the
    decode arm streams every pick in place from the pinned RAM tier, so the vram_tab entries the
    corrupt publishes wrote were not consulted for compute. In the default (non-ZC) configuration the
    table is the compute source (kernel-side tab[e]), which is where the stale bytes feed inference.
    This is a good example of the bug hiding behind a fast-path configuration.

A note on methodology for anyone repeating this: ds4 greedy answers are not byte-stable across
boots when expert transport changes (landing/fill timing, CPU-lane vs VRAM rounding). Answer-level
A/Bs on this engine need a pinned DS4_LANE_CAL and drift-envelope comparisons; the decisive
evidence for a publish-gate change is the mechanism log above.

Performance

The change is once-per-fill bookkeeping: one bool, one compare, and an atomic sub on the failure
path only
; the success path adds a single not-taken branch.

  • Full-size cell (par-2, 32,768-prompt + 2,048-decode, IQ1_M, --dspark on): pre-fix 1,014 t/s
    prefill / 42.3 t/s decode aggregate — post-fix cell not directly comparable on the same machine
    (a second engine cannot fit beside the production one in 128 GB; aborts on the RAM floor).
  • Same-conditions A/B beside no other engine (par-2, 8,192-prompt + 2,048-decode, identical config,
    fresh boots): prefill 322.1 → 319.6 t/s (−0.8 %), decode aggregate 39.69 → 38.57 t/s (−2.8 %,
    within this box's established single-cell noise of ±5 %). Both cells were also partly hit by the
    unrelated early-finish=length bug (#638), which truncates conversations and invalidates wall-time
    comparison; prefill completes before decode and is unaffected.

Consistent with a success path that gains one branch.

Notes for review

  • The landing path needed no change: it already had the full done+bad discipline this commit brings to
    fills.
  • The injected-failure lever (commit 1) is what the proof ran on; it is env-gated, off by default, and
    prints a FAULT line per injection, so it can serve CI-style failure tests (the same way the
    reporter's team verified their fix).
  • A failed fill's slot retiring for the engine run is deliberate (no cross-thread mutation of the
    tick-owned rc_fill from the copy thread); failures are pathological, and the bound is the small
    per-layer recent-slot pool.

🔄 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/646 **Author:** [@handmade0octopus](https://github.com/handmade0octopus) **Created:** 10/29/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `pr/rc-fill-error` --- ### 📝 Commits (2) - [`9308175`](https://github.com/mw00/project-maya/commit/93081751adcea6e11458407c329151a5d3a10849) ds4 recent slots: DS4_FAULT_RC_FILL=N test lever (every Nth fill fails at issue) - [`fa4b5d7`](https://github.com/mw00/project-maya/commit/fa4b5d7ac8b030409301e88c3b4c66f7e73a1693) ds4 recent slots: a failed fill must not publish its slot ### 📊 Changes **1 file changed** (+38 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `src/ds4/ds4_model.cu` (+38 -2) </details> ### 📄 Description # DeepSeek ds4 recent slots: a failed fill must not publish its slot (silent stale-weight inference) Follow-up to the cache-management bug report shared by a delta-inference-engine dev (a failed promotion still published the expert→slot mapping, silently corrupting inference). Auditing the same class here found the discipline **already present in the streamed-expert landing path** (`lane_copy` sets `pull->bad[i]` on a failed read, and the mapper publishes a landing only when `P->done == seq && P->bad[q] == 0`) — but **absent in the recent-slot fills path**, which had the bug the report describes, verbatim. ## The bug (`rc_loop`, fills) ```cpp stream_expert(l, m, j.expert, sat(...), rc_cs[di], err); // return value DISCARDED cudaEventRecord(l.rc_ev[j.slot * l.nm + m], rc_cs[di]); // recorded unconditionally ... if (done) { rc_done[l.rc_off + j.slot].store(j.gen, release); ... } // on event success alone // tick: if (e < 0 || rc_done[l.rc_off + i].load(acquire) != l.rc_gen[i]) continue; ... l.slot[e] = ...; set_tab(e, i); // stale/partial bytes become tab[e] ``` `stream_expert` carefully checks every `cudaMemcpyAsync` enqueue and returns `false` + fills `err` on failure — the fills path threw that away. A failed enqueue still recorded the event, still stored `rc_done`, and the tick published the mapping *and the device table entry* (`vram_tab[e]` → the slot's address) over stale or partial bytes. The `err` text was written and then discarded. Nothing was logged. On this engine the fill source is the pinned RAM tier (not storage), so the realistic triggers are a failed H2D enqueue or a lost device rather than a failed file read — but the failure class, the silent publish, and the corruption are exactly the ones reported. ## The fix Mirrors the landing path's own discipline and the report's fix semantics: - the issue loop captures `stream_expert()`'s return; on failure the job **never reaches `fly`**, so nothing stores `rc_done`, and the tick's `rc_done != rc_gen` check **never publishes the slot nor its `vram_tab` entry** — the previous mapping (if any) stays intact; - `rc_pending` is decremented at once, so `rc_drain`'s bounded wait cannot count the dead job; - the failure is logged with layer/expert/slot and the error text (`ds4: recent-slot fill failed, slot left unmapped: ...`) instead of being discarded; - the affected expert routes over its non-VRAM lane (correct, slower); the slot retires for the run (`rc_fill` keeps holding it out of the free list — bounded by the small per-layer recent-slot pool). ## Proof by injected failure New test lever, off by default: **`DS4_FAULT_RC_FILL=N`** makes every Nth fill fail at issue (as if its first H2D enqueue failed — nothing copied) while the completion event still records. Commit 1 keeps the pre-fix behavior, commit 2 is the fix; same lever, same stimulus, both builds: | arm | env | injected failures | published anyway | `rc_drain` stalls | |---|---|---|---|---| | commit 1 (pre-fix) | plain | 8,613 | **8,613** (0 blocked) | 0 | | commit 2 (fix) | plain | 1,278 | **0** — 1,279 `slot left unmapped` | 0 | | commit 2 (fix) | production (`DS4_STREAM_ZC_ALL`) | 1,280 | **0** — 1,280 `slot left unmapped` | 0 | Identical stimulus, opposite publish behavior, `rc_drain` healthy everywhere. Two honest observations from the end-to-end runs (4 fixed greedy prompts, temperature 0, pinned lane calibration): - **The degradation is silent-numerical, not cosmetic.** Even with thousands of stale publishes, the pre-fix arm produced fluent, on-topic answers — every arm did. Nothing in the output text flags the corruption; only the bytes are wrong. That matches "silently corrupt inference results" and is exactly why this class needs the publish gate rather than an output-level check. - **Our own production tuning masks the stale publishes:** under `DS4_STREAM_ZC_ALL` full coverage the decode arm streams every pick in place from the pinned RAM tier, so the `vram_tab` entries the corrupt publishes wrote were not consulted for compute. In the default (non-ZC) configuration the table *is* the compute source (kernel-side `tab[e]`), which is where the stale bytes feed inference. This is a good example of the bug hiding behind a fast-path configuration. A note on methodology for anyone repeating this: ds4 greedy answers are **not** byte-stable across boots when expert transport changes (landing/fill timing, CPU-lane vs VRAM rounding). Answer-level A/Bs on this engine need a pinned `DS4_LANE_CAL` and drift-envelope comparisons; the decisive evidence for a publish-gate change is the mechanism log above. ## Performance The change is once-per-fill bookkeeping: one bool, one compare, and an atomic sub **on the failure path only**; the success path adds a single not-taken branch. - Full-size cell (par-2, 32,768-prompt + 2,048-decode, IQ1_M, `--dspark on`): pre-fix 1,014 t/s prefill / 42.3 t/s decode aggregate — post-fix cell not directly comparable on the same machine (a second engine cannot fit beside the production one in 128 GB; aborts on the RAM floor). - Same-conditions A/B beside no other engine (par-2, 8,192-prompt + 2,048-decode, identical config, fresh boots): prefill **322.1 → 319.6 t/s (−0.8 %)**, decode aggregate 39.69 → 38.57 t/s (−2.8 %, within this box's established single-cell noise of ±5 %). Both cells were also partly hit by the unrelated early-`finish=length` bug (#638), which truncates conversations and invalidates wall-time comparison; prefill completes before decode and is unaffected. Consistent with a success path that gains one branch. ## Notes for review - The landing path needed no change: it already had the full done+bad discipline this commit brings to fills. - The injected-failure lever (commit 1) is what the proof ran on; it is env-gated, off by default, and prints a `FAULT` line per injection, so it can serve CI-style failure tests (the same way the reporter's team verified their fix). - A failed fill's slot retiring for the engine run is deliberate (no cross-thread mutation of the tick-owned `rc_fill` from the copy thread); failures are pathological, and the bound is the small per-layer recent-slot pool. --- <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:50 +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#647
No description provided.