diff --git a/docs/DETAILS.md b/docs/DETAILS.md index 4b086877..349eca7c 100644 --- a/docs/DETAILS.md +++ b/docs/DETAILS.md @@ -1914,3 +1914,5 @@ The page uses relative URLs and works through the existing host binding or a rev ### Prompt buffers: `bo` shares `emb` (#1454) The prompt path's half-output buffer `bo` reuses the embedding buffer `emb`, which is dead after the first hyper-connection broadcast: T x 2560 floats less VRAM per chunk (320 MiB at 32768 rows). The planner still counts those bytes by default, so the auto chunk and the cache slots the prompt path borrows are exactly those of 0.1.40.3 and the output bits are unchanged. `STRATA_EMB_REUSE_ACCOUNT=1` lets the planner use the saved bytes: where VRAM limits the chunk it grows (RTX 3060, IQ3_XXS: 6400 to 6656 tokens, 1652 to 1670 borrowed slots, prompt about +3.9%). A different chunk changes the prompt path's rounding, so prompt residuals are not byte-identical to the default; greedy output matched in our runs. Opt-in until it has a KL measurement. + +**Fused int8 prompt experts on gfx12 (RDNA4, R9700): on by default for IQ3_S and IQ3_XXS packs.** `STRATA_PF_FUSED=0` turns them off (back to the MMQ prompt kernels, the previous bits). R9700, 1 card: prompt 4K +15.7%, 16K +13..+17%, 32K +19..+20%, a 96K prompt +16% (answers identical text); first-token KL against the FP16 prompt path over 96 prompts is equal to MMQ within noise (IQ3_XXS 0.00613 against 0.00683, IQ3_S 0.00416 against 0.00372). Other quants and other GPUs are unchanged; `STRATA_PF_FUSED=1` still opts in every covered format. diff --git a/src/prefill/moe_fused_iq.cu b/src/prefill/moe_fused_iq.cu index e22b927c..c28a0fb3 100644 --- a/src/prefill/moe_fused_iq.cu +++ b/src/prefill/moe_fused_iq.cu @@ -1122,12 +1122,19 @@ bool native_supported(int gu_type, int d_type) { }(); // gfx12: fused::available() (the Q2_0 pack's expert_w11_kernel, not ported) stays false, so requested() does too; the // same opt-in (STRATA_PF_FUSED=1) is read here. Every other device: requested() as before. - static const bool env = [] { + // unset: on by default on gfx12 for IQ3_S and IQ3_XXS gate/up only (R9700: prompt +13..+20%, first-token KL against the FP16 prompt + // path equal to MMQ's within noise, 96 prompts each); STRATA_PF_FUSED=0 turns it off, =1 keeps the opt-in for every covered format + static const int env = [] { const char* v = std::getenv("STRATA_PF_FUSED"); - return v != nullptr && v[0] == '1'; + return v == nullptr || v[0] == '\0' ? -1 : (v[0] == '1' ? 1 : 0); }(); - if (off || !env || !gu_covered(gu_type) || !d_covered(d_type)) return false; // opt-in (=1): no device query without it + if (off || env == 0 || !gu_covered(gu_type) || !d_covered(d_type)) return false; +#if !defined(__HIPCC__) + if (env < 0) return false; // the default is gfx12 (HIP) only +#endif + if (env < 0 && gu_type != T_IQ3_S && gu_type != T_IQ3_XXS) return false; // default: only these two const DevInfo& d = dev_info(); + if (env < 0) return d.ok && d.w12; return d.ok && (requested() || d.w12); } diff --git a/src/program/generate.cpp b/src/program/generate.cpp index 2c5dc68c..c0d75be8 100644 --- a/src/program/generate.cpp +++ b/src/program/generate.cpp @@ -17,6 +17,7 @@ #include "strata/platform/memory.hpp" #include "strata/core/arch_defaults.hpp" +#include "strata/kernels/gfx_arch.hpp" #include "strata/core/dma_batch.hpp" #include "strata/core/device.hpp" #include "strata/core/remote_expert_opt.hpp" @@ -527,6 +528,8 @@ struct Options { int64_t prefill_auto_max = 8192; /// #1630: a bare `--prefill auto` stops here on a Windows HIP build (0: no cap). A chunk the user names is not capped. int64_t prefill_auto_cap = 0; + /// a bare `--prefill auto` (no ":N", no STRATA_PREFILL_AUTO_MAX): the gfx12 Linux rule below may raise its ceiling + bool prefill_auto_bare = false; bool no_split_rows = false; ///< plan v0.3 P4 A/B: one whole expert per pool thread /// Plan v0.3 P5: the prompt path borrows the top expert-cache slots for its buffers and refills them after /// the prompt (default); `--no-prefill-borrow` reserves the buffers' VRAM for the whole session instead. @@ -1932,6 +1935,7 @@ int main(int argc, char** argv) { constexpr bool win_hip = false; #endif const bool bare_auto = v == "auto" && !(o.prefill_auto && env_max != nullptr); + o.prefill_auto_bare = bare_auto && o.prefill_auto; o.prefill_auto_cap = strata::platform::host_limits::auto_chunk_cap(win_hip, bare_auto && o.prefill_auto); if (o.prefill_auto_cap > 0) o.prefill_chunk = std::min(o.prefill_chunk, o.prefill_auto_cap); if (strata::platform::host_limits::warn_user_chunk(win_hip, bare_auto, o.prefill_chunk)) @@ -2128,6 +2132,24 @@ int main(int argc, char** argv) { else (void) cudaGetLastError(); } #endif +#if defined(STRATA_USE_HIP) && !defined(_WIN32) + if (o.prefill_auto_bare && o.prefill_auto_cap == 0) { + // gfx1200 / gfx1201 (RDNA4, Linux): a bare `--prefill auto` may reach 16384 instead of 8192 (R9700, IQ3_S / Q2_0, 16K / 32K / + // 64K prompts: +0.5 .. +5.8%, residuals identical to 8192). The fit scan still picks a smaller chunk when the expert cache cannot lend + // the buffers. An explicit --prefill N, auto:N or STRATA_PREFILL_AUTO_MAX is never touched (prefill_auto_bare is false then). + // STRATA_GFX12_DEFAULTS=0 or STRATA_GFX12_CHUNK=0 keeps 8192. + const char* c0 = std::getenv("STRATA_GFX12_CHUNK"); + const char* d0 = std::getenv("STRATA_GFX12_DEFAULTS"); + cudaDeviceProp cp{}; + if (!(c0 != nullptr && c0[0] == '0') && !(d0 != nullptr && d0[0] == '0') && + cudaGetDeviceProperties(&cp, 0) == cudaSuccess && strata::kernels::gfx_arch_is_gfx12(cp.gcnArchName)) { + o.prefill_auto_max = 16384; + o.prefill_chunk = 16384; + std::fprintf(stderr, "strata generate: gfx12: --prefill auto may take chunks up to 16384 (STRATA_GFX12_CHUNK=0 keeps 8192)\n"); + } + (void) cudaGetLastError(); + } +#endif #if defined(STRATA_HIP_GFX906) { // #1728: the gfx906 build's kernels assume 64-lane waves; on a wave32 card they would fault or give wrong // numbers, so say so before the first launch (the ready-made wave32 engine is the one for those cards)