[PR #39] [MERGED] Fix tier/lending races and invalid-route indexing behind 'illegal memory access' crashes (long prompts, RAM-resident) #294

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

📋 Pull Request Information

Original PR: https://github.com/mw00/project-maya/pull/39
Author: @boxwrench
Created: 10/9/2026
Status: ✅ Merged
Merged: 10/9/2026
Merged by: @mw00

Base: main ← Head: fix/tier-lending-races


📝 Commits (2)

  • f0163b3 HIP: map the device-query names #44 uses (v1.0.21 does not build on HIP without them)
  • 6b6d520 Fix GLM tier lending races and reject invalid routes

📊 Changes

10 files changed (+323 additions, -91 deletions)

View changed files

📝 include/strata/core/glm_model.hpp (+4 -4)
📝 include/strata/hip_compat/cuda_runtime.h (+3 -0)
📝 include/strata/kernels/glm_fast.hpp (+2 -0)
📝 src/core/glm_fast_path.cu (+72 -32)
📝 src/core/glm_fast_state.hpp (+19 -1)
📝 src/core/glm_model.cu (+2 -1)
📝 src/core/glm_prefill.cu (+89 -46)
📝 src/kernels/cuda/glm_batch.cu (+15 -2)
📝 src/kernels/cuda/glm_fast.cu (+45 -4)
📝 tests/hip/glm_handoff.cpp (+72 -1)

📄 Description

Fixes an intermittent GPU crash ("an illegal memory access was encountered") on v1.0.15/16. It is generic engine code, so CUDA is exposed to the same races; it shows most often on AMD with long prompts and the RAM-heavy tier modes. Tracking: #6. Related: #15 (on hold because of this).

Symptoms (before)

  • Single RX 7900 XT, STRATA_GLM_RAM_GB=90, RAM_RESIDENT=1 + PROMOTE_MIN=6 (#25/#26): crashed by the 2nd request, at the prompt -> first-token handoff right after a conversation was set aside. Shadows (#15) crashed the same way.
  • Single R9700, 40K context, 12 GB prompt budget, resident tier: 7 of 13 prompts over 7K tokens crashed; 0 of 3 ~28K-token prompts completed (twice the illegal access, once the planner's integrity check "planned 1792 of 222488 routed rows"). Default exclusive tiers crashed once too.
  • After a prompt-path error the engine stayed wedged until restarted.

Causes

  1. Pinned table-update sources reused while their copy is pending. fast_boundary queues the H2D copies of upd_key_h / upd_val_h on the nonblocking F->cs and returns (the final flush has no wait). lend_tail runs another boundary and then writes its lending updates into the same host buffers after waiting only on F->copy. A table entry can then receive a half-overwritten key/value - e.g. a pointer into the borrowed activation region or a stale spare - and decode reads garbage weights.
  2. Background moves racing prompt lending (resident mode). bg_hold was released before lending's second boundary, so a RAM->VRAM move could target a tail slot that is then lent; retiring that move later gave the slot two owners. Waiting for the bytes alone doesn't retire the ownership metadata.
  3. Invalid routes indexed. Both top-k reductions start from INT_MAX; with all-NaN scores it survives and is used to index probabilities and expert tables (predicted IDs were not validated either). That is where the illegal access itself happened once tables were corrupted.

Fix (9 files, +316 / -87)

  • Every table-update flush (including the final and full-batch ones) waits for the compute stream before its pinned sources are reused.
  • Lending holds new background moves and spare-refill demotions, completes outstanding copies, retires their metadata and checks none remain before borrowing; lending copy errors propagate, and a split-prefill failure returns regions already borrowed by earlier GPUs.
  • Routing validates expert IDs and scores (primary, predicted and lookahead in decode; prompt rows before planning/scatter). An invalid route fails the request with a clear error instead of touching memory, and the request-local error is cleared on reset, so the engine recovers.
  • Synchronization and event failures propagate their real return codes. The planner's equality check is kept unchanged (it is an integrity check, not a capacity limit).

Verified (HIP, ROCm 7.2.1; build for gfx1100/gfx1201/gfx1151)

  • glm_layer_parity, glm_model_test, hip_glm_prefill_attention, hip_glm_handoff pass on RX 7900 XT and R9700 (8/8); the handoff check also injects all/partial NaN and Inf into primary, predicted, lookahead and prompt routing.
Setup (RAM_GB 90) Before After
RX 7900 XT, RAM-resident + PROMOTE_MIN=6, 1.6K prompts crash by request 2 12/12 ok, 347 tok/s prefill, 19.1 tok/s decode
RX 7900 XT, default exclusive tiers occasional 12/12 ok, 345 / 18.2
RX 7900 XT, resident, all-CPU plan (3,371 background promotions, 2,603 demotions) - 3/3 ok
R9700, resident, ~8K / ~16K / ~28K-token prompts 7/13 crashed, 0/3 at 28K 9/9 ok, 759 / 768 / 773 tok/s

Not tested: CUDA (no NVIDIA toolchain here). Since the races are in shared code, a CUDA build and a long-prompt run on your side would be appreciated.


🔄 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/39 **Author:** [@boxwrench](https://github.com/boxwrench) **Created:** 10/9/2026 **Status:** ✅ Merged **Merged:** 10/9/2026 **Merged by:** [@mw00](https://github.com/mw00) **Base:** `main` ← **Head:** `fix/tier-lending-races` --- ### 📝 Commits (2) - [`f0163b3`](https://github.com/mw00/project-maya/commit/f0163b372f0f493d758c801bb5995eb826f4fcdb) HIP: map the device-query names #44 uses (v1.0.21 does not build on HIP without them) - [`6b6d520`](https://github.com/mw00/project-maya/commit/6b6d5202caaeb74cd2c53af9dc132de7b80b2e30) Fix GLM tier lending races and reject invalid routes ### 📊 Changes **10 files changed** (+323 additions, -91 deletions) <details> <summary>View changed files</summary> 📝 `include/strata/core/glm_model.hpp` (+4 -4) 📝 `include/strata/hip_compat/cuda_runtime.h` (+3 -0) 📝 `include/strata/kernels/glm_fast.hpp` (+2 -0) 📝 `src/core/glm_fast_path.cu` (+72 -32) 📝 `src/core/glm_fast_state.hpp` (+19 -1) 📝 `src/core/glm_model.cu` (+2 -1) 📝 `src/core/glm_prefill.cu` (+89 -46) 📝 `src/kernels/cuda/glm_batch.cu` (+15 -2) 📝 `src/kernels/cuda/glm_fast.cu` (+45 -4) 📝 `tests/hip/glm_handoff.cpp` (+72 -1) </details> ### 📄 Description Fixes an intermittent GPU crash ("an illegal memory access was encountered") on v1.0.15/16. It is generic engine code, so CUDA is exposed to the same races; it shows most often on AMD with long prompts and the RAM-heavy tier modes. Tracking: #6. Related: #15 (on hold because of this). ### Symptoms (before) - Single RX 7900 XT, `STRATA_GLM_RAM_GB=90`, `RAM_RESIDENT=1` + `PROMOTE_MIN=6` (#25/#26): crashed by the 2nd request, at the prompt -> first-token handoff right after a conversation was set aside. Shadows (#15) crashed the same way. - Single R9700, 40K context, 12 GB prompt budget, resident tier: 7 of 13 prompts over 7K tokens crashed; 0 of 3 ~28K-token prompts completed (twice the illegal access, once the planner's integrity check "planned 1792 of 222488 routed rows"). Default exclusive tiers crashed once too. - After a prompt-path error the engine stayed wedged until restarted. ### Causes 1. **Pinned table-update sources reused while their copy is pending.** `fast_boundary` queues the H2D copies of `upd_key_h` / `upd_val_h` on the nonblocking `F->cs` and returns (the final flush has no wait). `lend_tail` runs another boundary and then writes its lending updates into the same host buffers after waiting only on `F->copy`. A table entry can then receive a half-overwritten key/value - e.g. a pointer into the borrowed activation region or a stale spare - and decode reads garbage weights. 2. **Background moves racing prompt lending (resident mode).** `bg_hold` was released before lending's second boundary, so a RAM->VRAM move could target a tail slot that is then lent; retiring that move later gave the slot two owners. Waiting for the bytes alone doesn't retire the ownership metadata. 3. **Invalid routes indexed.** Both top-k reductions start from `INT_MAX`; with all-NaN scores it survives and is used to index probabilities and expert tables (predicted IDs were not validated either). That is where the illegal access itself happened once tables were corrupted. ### Fix (9 files, +316 / -87) - Every table-update flush (including the final and full-batch ones) waits for the compute stream before its pinned sources are reused. - Lending holds new background moves and spare-refill demotions, completes outstanding copies, retires their metadata and checks none remain before borrowing; lending copy errors propagate, and a split-prefill failure returns regions already borrowed by earlier GPUs. - Routing validates expert IDs and scores (primary, predicted and lookahead in decode; prompt rows before planning/scatter). An invalid route fails the request with a clear error instead of touching memory, and the request-local error is cleared on reset, so the engine recovers. - Synchronization and event failures propagate their real return codes. The planner's equality check is kept unchanged (it is an integrity check, not a capacity limit). ### Verified (HIP, ROCm 7.2.1; build for gfx1100/gfx1201/gfx1151) - `glm_layer_parity`, `glm_model_test`, `hip_glm_prefill_attention`, `hip_glm_handoff` pass on RX 7900 XT and R9700 (8/8); the handoff check also injects all/partial NaN and Inf into primary, predicted, lookahead and prompt routing. | Setup (RAM_GB 90) | Before | After | |---|---|---| | RX 7900 XT, RAM-resident + PROMOTE_MIN=6, 1.6K prompts | crash by request 2 | 12/12 ok, 347 tok/s prefill, 19.1 tok/s decode | | RX 7900 XT, default exclusive tiers | occasional | 12/12 ok, 345 / 18.2 | | RX 7900 XT, resident, all-CPU plan (3,371 background promotions, 2,603 demotions) | - | 3/3 ok | | R9700, resident, ~8K / ~16K / ~28K-token prompts | 7/13 crashed, 0/3 at 28K | 9/9 ok, 759 / 768 / 773 tok/s | **Not tested:** CUDA (no NVIDIA toolchain here). Since the races are in shared code, a CUDA build and a long-prompt run on your side would be appreciated. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-10-29 21:23:54 +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#294
No description provided.