diff --git a/include/strata/core/gfx12_extra.hpp b/include/strata/core/gfx12_extra.hpp index 179552f8f7..696112074b 100644 --- a/include/strata/core/gfx12_extra.hpp +++ b/include/strata/core/gfx12_extra.hpp @@ -7,6 +7,18 @@ // instead of one gr_read per token (#3264, bsorensen110). R9700 (p620, IQ3_S, serve, static residency, // 8 interleaved pairs, A/A beside it): json_extract +0.82% (6/8 pairs), agent +0.63% (6/8), code_py -0.96% // (3/8; that prompt's A/A moves +-3.5% a pair), greedy ids identical in 16/16 and 15/16 request sets. +// +// Changes the answers (needs the owner's yes; this is the separate, droppable commit): +// STRATA_SELECT_WMMA=1 + STRATA_SELECT_ALT_MIN_TOKENS=28672 the gfx12 matrix-core QSA block scorer (already in the engine as an opt-in) for +// chunks whose context so far is 28,672 tokens or more; a read that stays below that is bit-identical to the warp +// kernel (first-token KL 0.00000 on twelve 8K-24K prompts). R9700 (p620, IQ3_S, serve, interleaved pairs, prompt +// tok/s vs unset, 3 pairs): 32K +1.83% (3/3), 98K +5.74% (3/3, steady). First-token KL against unset on seven 30K-96K +// prompts: mean 0.0018, max 0.0055, top-1 7/7; needle recall 25/25 at 8K..96K x 5 depths. Without the floor (STRATA_SELECT_WMMA=1 +// alone, 4 pairs): 4K +0.34%, 8K +0.94%, 16K +1.73%, 24K +3.34%, 32K +4.5..6.0%, 98K +6.9..7.3%, but the values change from 8K +// up (KL mean 0.0056, max 0.0193, top-1 11/12 at 8K-24K); a floor of 16,384 was no better (32K -0.27%, noisy). The floor is +// the owner's trade between "ordinary prompts keep their exact answers" and a few percent more at 32K. +// Chosen over PR 3073's simt2 (author Vop3p), which is slower below 32K, has KL 0.0029 / 0.0095 and yields to WMMA on gfx12. +// Off: STRATA_SELECT_WMMA=0, STRATA_GFX12_DEFAULTS=0, STRATA_DEFAULTS=026. #pragma once #include @@ -33,4 +45,19 @@ inline std::vector> gfx12_exact_extra_env(co return gfx12_exact_extra_env(gcn_arch, strata::qwen_defaults_026()); } +/// The value-changing defaults of gfx12 (see above). `defaults026`: STRATA_DEFAULTS=026. +inline std::vector> gfx12_value_changing_env(const char* gcn_arch, bool defaults026) { + std::vector> t; + if (!strata::kernels::gfx_arch_is_gfx12(gcn_arch)) return t; + const char* off = std::getenv("STRATA_GFX12_DEFAULTS"); + if (off != nullptr && off[0] == '0') return t; + if (defaults026) return t; + t.push_back({"STRATA_SELECT_WMMA", "1"}); + t.push_back({"STRATA_SELECT_ALT_MIN_TOKENS", "28672"}); + return t; +} +inline std::vector> gfx12_value_changing_env(const char* gcn_arch) { + return gfx12_value_changing_env(gcn_arch, strata::qwen_defaults_026()); +} + } // namespace strata::core diff --git a/src/core/arch_defaults.cpp b/src/core/arch_defaults.cpp index 5f6c505ecd..d4a7ae0221 100644 --- a/src/core/arch_defaults.cpp +++ b/src/core/arch_defaults.cpp @@ -222,6 +222,18 @@ std::vector apply_arch_defaults(const char* gcn_arch, bool integrat std::fprintf(stderr, "\n"); } } + { // gfx12 defaults that change the answers (gfx12_extra.hpp): the matrix-core QSA scorer from 28,672 tokens; its own line + const auto vc = gfx12_value_changing_env(gcn_arch); + bool any = false; + for (const auto& kv : vc) { + if (std::getenv(kv.first.c_str()) != nullptr) continue; + set_default(kv); + any = true; + } + if (any) + std::fprintf(stderr, "strata: gfx12 (RDNA4): the matrix-core QSA block scorer is on once a prompt is past 28,672 tokens (+5.7%% prompt speed at 98K on an R9700, shorter prompts unchanged; " + "the first-token KL against the warp kernel is 0.002 on average above 30K; STRATA_SELECT_WMMA=0 or STRATA_GFX12_DEFAULTS=0 turns it off)\n"); + } if (!set.empty()) { const bool g12 = strata::kernels::gfx_arch_is_gfx12(gcn_arch); std::fprintf(stderr, "strata: %s: %zu exact speed switches on by default (%s=0 turns " diff --git a/src/core/arch_defaults_test.cpp b/src/core/arch_defaults_test.cpp index 32fd3de988..a8d71fd92b 100644 --- a/src/core/arch_defaults_test.cpp +++ b/src/core/arch_defaults_test.cpp @@ -276,6 +276,7 @@ int main() { CHECK(std::string(std::getenv("STRATA_SMALL_UNR")) == "3" && std::string(std::getenv("STRATA_GR_Q32_G")) == "2" && std::string(std::getenv("STRATA_GR_Q8_PFS")) == "1"); CHECK(apply_arch_defaults("gfx1201", false).empty()); + unset("STRATA_SELECT_WMMA"); unset("STRATA_SELECT_ALT_MIN_TOKENS"); unset("STRATA_HEAD_MIX_MULTI"); // gfx12_extra.hpp's defaults (own test: gfx12_extra_test) CHECK(apply_arch_defaults("gfx1103", false).empty()); // integrated == false: a mixed box (iGPU + dGPU) keeps the old defaults for (const char* k : five) CHECK(std::getenv(k) == nullptr); put("STRATA_HC_UPMIX", "0"); diff --git a/src/core/gfx12_extra_test.cpp b/src/core/gfx12_extra_test.cpp index 083560d822..a5dfcc2a72 100644 --- a/src/core/gfx12_extra_test.cpp +++ b/src/core/gfx12_extra_test.cpp @@ -56,6 +56,25 @@ int main() { put("STRATA_GFX12_DEFAULTS", "0"); apply_arch_defaults("gfx1201", false); CHECK(std::getenv("STRATA_HEAD_MIX_MULTI") == nullptr); + // the value-changing default (separate commit): gfx12 only, the same off switches, and the user's own setting wins + unset("STRATA_GFX12_DEFAULTS"); unset("STRATA_SELECT_WMMA"); unset("STRATA_SELECT_ALT_MIN_TOKENS"); + CHECK(has(gfx12_value_changing_env("gfx1201", false), "STRATA_SELECT_WMMA", "1")); + CHECK(has(gfx12_value_changing_env("gfx1201", false), "STRATA_SELECT_ALT_MIN_TOKENS", "28672")); + CHECK(gfx12_value_changing_env("gfx1201", true).empty()); + for (const char* other : {"gfx1100", "gfx1151", "gfx1030", "gfx906", "", "gfx12010"}) CHECK(gfx12_value_changing_env(other, false).empty()); + apply_arch_defaults("gfx1201", false); + CHECK(std::getenv("STRATA_SELECT_WMMA") != nullptr && std::string(std::getenv("STRATA_SELECT_WMMA")) == "1"); + CHECK(std::getenv("STRATA_SELECT_ALT_MIN_TOKENS") != nullptr && std::string(std::getenv("STRATA_SELECT_ALT_MIN_TOKENS")) == "28672"); + unset("STRATA_SELECT_WMMA"); unset("STRATA_SELECT_ALT_MIN_TOKENS"); + put("STRATA_SELECT_WMMA", "0"); // the off switch + apply_arch_defaults("gfx1201", false); + CHECK(std::string(std::getenv("STRATA_SELECT_WMMA")) == "0"); + unset("STRATA_SELECT_WMMA"); unset("STRATA_SELECT_ALT_MIN_TOKENS"); + apply_arch_defaults("gfx1100", false); + CHECK(std::getenv("STRATA_SELECT_WMMA") == nullptr); + put("STRATA_GFX12_DEFAULTS", "0"); + apply_arch_defaults("gfx1201", false); + CHECK(std::getenv("STRATA_SELECT_WMMA") == nullptr && std::getenv("STRATA_SELECT_ALT_MIN_TOKENS") == nullptr); if (fails == 0) std::printf("gfx12_extra_test: OK\n"); return fails == 0 ? 0 : 1; }