diff --git a/docs/AMD_HIP.md b/docs/AMD_HIP.md index eaa664dd95..1c93f17d6c 100644 --- a/docs/AMD_HIP.md +++ b/docs/AMD_HIP.md @@ -528,6 +528,11 @@ before it installs a model. mapped after a larger one in the same reservation, so every piece of a reservation is made one size there (the expert cache had lost its last 64 MiB piece, and an attention cache grown to its end failed). `STRATA_VMM_EQUAL_PIECES=1` or `=0` turns that on or off on any Linux HIP build. +- On NVIDIA the buffers only a prompt uses (about 300 MB of Qwen3.6's at a prompt batch of 2,048) go to the expert + cache between prompts. A HIP build keeps them: with them lent, strata-poly crashed inside the HIP runtime's kernel + launch under WSL2 (a SIGSEGV in `libamdhip64`, RX 9070 XT, some experts in RAM), and the access violation in + `amdhip64_7.dll` on the first long prompt on Windows + ([#305](https://github.com/simplexai-labs/PolyStrata/issues/305)) fits the same path. - hipBLASLt loads a product type's kernels at its first call. On Windows (RX 9070 XT, ROCm 10.2.0a20260930) the first single-precision product of a prompt took 4 s on one CPU thread with the card idle, inside the first prompt of every strata-poly process. strata-poly now makes one small product of each kind the prompt uses (halves into diff --git a/engine/include/strata/hip_compat/cuda.h b/engine/include/strata/hip_compat/cuda.h index 0aefa8eff4..2fc2cc6b3a 100644 --- a/engine/include/strata/hip_compat/cuda.h +++ b/engine/include/strata/hip_compat/cuda.h @@ -26,6 +26,14 @@ #define STRATA_VMM_EQUAL_PIECES 1 #endif +// A prompt's buffers are not lent to the expert cache between prompts on any HIP build (Engine::alloc()). With them +// lent, strata-poly crashed inside the HIP runtime's kernel launch in 15 of 16 runs: a SIGSEGV in libamdhip64 under +// the dequantize launch of a dense product into the lent work memory (ROCm 7.2.4 with librocdxg, WSL2's way to the +// Windows driver; an RX 9070 XT with some experts in RAM). Native Windows has an access violation in amdhip64_7.dll +// on the first long prompt of every start that fits the same path (issue 305, RX 7600 XT, Qwen3.6 UD-Q3_K_M with +// some experts in RAM; not yet run with the lending off). Native Linux (KFD) never showed it: off there to match. +#define STRATA_VMM_NO_PROMPT_LEND 1 + typedef hipError_t CUresult; typedef int CUdevice; // HIP's own CUdeviceptr/handle equivalents are pointer-typed; CUDA's are integers, and strata-poly's Mapped diff --git a/engine/src/poly/engine.cpp b/engine/src/poly/engine.cpp index 35005b37ed..908d1a004d 100644 --- a/engine/src/poly/engine.cpp +++ b/engine/src/poly/engine.cpp @@ -3860,10 +3860,10 @@ void Engine::alloc() { // a prompt's batch is lent with them, and a call of a few tokens has a layout of its own. At a prompt batch of // 2,048 Qwen3.6's scratch is 450 MB, of which the few tokens' layout keeps some 70 (the attention's scores). const int most_step = (opt_.batch + 1) * (opt_.batch_mtp ? 2 : 1); - // Whether the prompt's buffers are lent (prompt_lends_, below). Not on ROCm on Linux, which gives VRAM back only - // with its addresses (see below): there nothing is lent, so the scratch keeps one layout, and a call of a few - // tokens never finds the prompt's layout left in place (which kept graph replay off for every later step). -#ifdef STRATA_VMM_RELEASE_WITH_ADDRESSES + // Whether the prompt's buffers are lent (prompt_lends_, below). Not on HIP (STRATA_VMM_NO_PROMPT_LEND, below): + // there nothing is lent, so the scratch keeps one layout, and a call of a few tokens never finds the prompt's + // layout left in place (which kept graph replay off for every later step). +#ifdef STRATA_VMM_NO_PROMPT_LEND const bool lends = false; #else const bool lends = vmm_ && !split_ && std::max(opt_.window, most_step) < kStageRows; @@ -3933,11 +3933,11 @@ void Engine::alloc() { work = floats_bytes + (need.halves * 2 + 255) / 256 * 256; // The buffers only a call of kStageRows rows or more uses (moe_rows(), lin_raw()'s products), side by side: // where they can be mapped apart (VMM) and the answer's calls never have that many rows, the expert cache - // has their VRAM between prompts (lend_prompt()), 300 MB of Qwen3.6's at a prompt batch of 2,048. Not on ROCm - // on Linux, which gives VRAM back only with its addresses (vmm_unmap()), as the staging buffer's widening is - // not: with the buffers lent, strata-poly crashed (SIGSEGV inside hipLaunchKernel, the dequantize launch of a - // prompt's dense product into the lent work memory) in 15 of 16 runs of Inkling 2 Mini IQ4_NL on an RX 9070 XT - // with 2,443 of its 3,072 experts in VRAM, ROCm 7.2.4. + // has their VRAM between prompts (lend_prompt()), 300 MB of Qwen3.6's at a prompt batch of 2,048. Not on HIP + // (STRATA_VMM_NO_PROMPT_LEND): with the buffers lent, strata-poly crashed inside the HIP runtime (SIGSEGV + // inside hipLaunchKernel, the dequantize launch of a prompt's dense product into the lent work memory) in 15 + // of 16 runs of Inkling 2 Mini IQ4_NL on an RX 9070 XT with 2,443 of its 3,072 experts in VRAM, ROCm 7.2.4 + // under WSL2 (librocdxg), and issue 305's access violation in amdhip64_7.dll on Windows fits the same path. prompt_lends_ = lends; const size_t sizes[] = {rr * 2 * n_ff_exp_ * sizeof(float), rr * n_ff_exp_ * sizeof(float), rr * n_embd_ * sizeof(float), rr * sizeof(float), diff --git a/engine/src/poly/inkling2.cpp b/engine/src/poly/inkling2.cpp index c20d374044..8f603f3a25 100644 --- a/engine/src/poly/inkling2.cpp +++ b/engine/src/poly/inkling2.cpp @@ -724,12 +724,12 @@ void Inkling2::load_layer(int il) { size_t Inkling2::recurrent_floats() const { return slots_.size() * past_floats(); } -// ROCm on Linux gives VRAM back only with its addresses (Engine::vmm_unmap()), and a prompt's lent buffers crashed -// strata-poly there (an RX 9070 XT, Inkling 2 Mini IQ4_NL with some experts in RAM): the prompt batch's scratch stays -// out of them, in one layout as before. With the experts frozen (STRATA_FREEZE_EXPERTS, --check-batch) lend_prompt() +// A HIP build lends no prompt buffers (STRATA_VMM_NO_PROMPT_LEND): lent, they crashed strata-poly inside the HIP +// runtime (an RX 9070 XT, Inkling 2 Mini IQ4_NL with some experts in RAM), so the prompt batch's scratch stays out of +// them, in one layout as before. With the experts frozen (STRATA_FREEZE_EXPERTS, --check-batch) lend_prompt() // lends nothing, and the small layout would only take VRAM from the expert cache for the whole run. bool Inkling2::scores_apart() const { -#ifdef STRATA_VMM_RELEASE_WITH_ADDRESSES +#ifdef STRATA_VMM_NO_PROMPT_LEND return false; #else return !ds_file_ && !freeze_experts_asked_ && mmq_ && vmm_ && !split_ && rows_ >= kStageRows;