diff --git a/data/settings-register.json b/data/settings-register.json index 50283d5287..b602ed53a3 100644 --- a/data/settings-register.json +++ b/data/settings-register.json @@ -24456,7 +24456,7 @@ "last_date": "", "status": "research", "owner": "prefill", - "note": "CUDA diagnostic for bug reports, not a user setting: =0 puts compute capability 8.6 cards with 80+ SMs back on MMQ for the IQ3_S pack's formats (the fused prompt kernels are the default there since 11-11). Goes away with MMQ (release C).", + "note": "CUDA diagnostic for bug reports, not a user setting: =0 puts compute capability 8.6 cards with 80+ SMs back on MMQ for the default list's gate/up formats (IQ2_XXS, IQ2_XS, IQ2_S, IQ3_XXS, IQ3_S, IQ4_XS; the fused prompt kernels are the default there since 11-11, IQ2_XXS / IQ2_XS since 11-12). Goes away with MMQ (release C).", "retire_after": "", "retired_in": "" }, diff --git a/include/strata/prefill/fused_tile_rule.hpp b/include/strata/prefill/fused_tile_rule.hpp index afe637714d..a31da2c0f4 100644 --- a/include/strata/prefill/fused_tile_rule.hpp +++ b/include/strata/prefill/fused_tile_rule.hpp @@ -87,6 +87,23 @@ constexpr bool takes_by_default(const Card& c, bool sm40, bool gate_staged, bool return sm40 && gate_staged && down_ok && c.sms >= 40; } +// The gate/up formats native_supported's default rule (CUDA, STRATA_PF_FUSED unset) takes at all: IQ2_XXS, IQ2_XS, IQ2_S, IQ3_XXS, IQ3_S, IQ4_XS, as ggml type ids (moe_fused_iq.cu static_asserts +// that they are GGML_TYPE_*). IQ2_XXS / IQ2_XS joined on the owner's word of 11-12 ("2-bit fused kernels as the default on 80+ SM NVIDIA cards"): the IQ3_XXS set's 19 gate/up layers (9 IQ2_XXS, +// 10 IQ2_XS) on an RTX A6000 (sm_86, 84 SMs): prompt time fused / default 0.874-0.976 from 300 to 8,193 tokens on the integration head, teacher-forced KL against the FP16 prompt path 0.965 [0.912, +// 1.021] at 512, 1.062 [0.995, 1.137] at 1,000, 1.072 [1.020, 1.123] at 2,048 and 1.008 [0.939, 1.101] at 8,192 ids (RESULTS-OWN-4X.md). The card rule is takes_by_default above and did not +// change: sm_86 / sm_120 with 80+ SMs; below 80 SMs the sm40 research switch only takes the weight-staging gate/up instances (IQ3_XXS / IQ3_S / IQ4_XS: sw_on), never IQ2_XXS / IQ2_XS. +// AMD (HIP) has its own rule in native_supported and is not touched. +constexpr int kTypeIq2Xxs = 16, kTypeIq2Xs = 17, kTypeIq3Xxs = 18, kTypeIq3S = 21, kTypeIq2S = 22, kTypeIq4Xs = 23; +constexpr bool default_gate_format(int t) { + return t == kTypeIq2Xxs || t == kTypeIq2Xs || t == kTypeIq2S || t == kTypeIq3Xxs || t == kTypeIq3S || t == kTypeIq4Xs; +} + +// native_supported's CUDA default decision for a gate/up format on a card: `env` is STRATA_PF_FUSED as native_supported reads it (-1 unset, 0 = "0", 1 = other: the opt-in, decided +// elsewhere, never "by default"), so only an unset variable can take a layer here, and STRATA_PF_FUSED=0 turns the default off again. +constexpr bool default_takes(int env, const Card& c, bool sm40, bool gate_staged, bool down_ok, int gu_type) { + return env < 0 && default_gate_format(gu_type) && takes_by_default(c, sm40, gate_staged, down_ok); +} + // ---- the weight-staging guard (check_staged_blobs's decision in src/prefill/moe_fused_iq.cu), as pure functions so the decision can be tested without a GPU. // The staging kernels (sw_on instances) copy the expert blobs into shared memory with cp.async and read 16-bit words at the rows' offsets: they need blobs in device (or managed) // memory at 2-byte aligned addresses and 2-byte aligned rows and offsets. A launch that fails the check does NOT end the process: it takes the unstaged 64-row kernel of the same diff --git a/src/prefill/moe_fused_iq.cu b/src/prefill/moe_fused_iq.cu index d86bd5f80d..a50f10e8f8 100644 --- a/src/prefill/moe_fused_iq.cu +++ b/src/prefill/moe_fused_iq.cu @@ -88,6 +88,10 @@ constexpr int H_ROW_BYTES = D_ROWS_K / 64 * AB; // bytes of a row of H in the static_assert(GU_ROWS_K % 256 == 0 && D_ROWS_K % 64 == 0, "the native expert kernels: K of gate/up is whole 256-value super-blocks, K of down whole 64-value stages"); // the formats (ggml type ids) +static_assert(GGML_TYPE_IQ2_XXS == strata::prefill::fused_tile::kTypeIq2Xxs && GGML_TYPE_IQ2_XS == strata::prefill::fused_tile::kTypeIq2Xs && + GGML_TYPE_IQ2_S == strata::prefill::fused_tile::kTypeIq2S && GGML_TYPE_IQ3_XXS == strata::prefill::fused_tile::kTypeIq3Xxs && + GGML_TYPE_IQ3_S == strata::prefill::fused_tile::kTypeIq3S && GGML_TYPE_IQ4_XS == strata::prefill::fused_tile::kTypeIq4Xs, + "fused_tile_rule.hpp's default_gate_format uses ggml's type ids"); constexpr int T_IQ2_XXS = GGML_TYPE_IQ2_XXS, T_IQ2_XS = GGML_TYPE_IQ2_XS, T_IQ2_S = GGML_TYPE_IQ2_S, T_IQ3_XXS = GGML_TYPE_IQ3_XXS, T_IQ3_S = GGML_TYPE_IQ3_S, T_IQ4_XS = GGML_TYPE_IQ4_XS, T_IQ4_NL = GGML_TYPE_IQ4_NL, T_Q2_0 = GGML_TYPE_Q2_0, @@ -2792,15 +2796,16 @@ bool native_supported(int gu_type, int d_type) { // formats measured there - the IQ3_S pack's IQ2_S, IQ3_XXS, IQ3_S and IQ4_XS layers with IQ4_NL / Q2_0 down (RTX PRO 5000: // prompt +7.0% 4K, +5.2% 20K, +3.4% 98K; teacher-forced KL against MMQ 0.0002 over 5998 positions, 0.0010 over 1760 long // ones; first-token KL against the FP16 prompt path 0.01181 vs MMQ's 0.01236 over 48 prompts; HumanEval, reasoning, - // agent, needles, CJK and tool calls the same). IQ2_XXS / IQ2_XS gate/up (the IQ3_XXS and IQ2_XS packs) keep MMQ until - // measured. The same on a compute capability 8.6 card with 80+ SMs (RTX A6000, 84 SMs, IQ3_S pack, 11-11: prompt +6.7% 4K, +3.6% 8K, + // agent, needles, CJK and tool calls the same). The same on a compute capability 8.6 card with 80+ SMs (RTX A6000, 84 SMs, IQ3_S pack, 11-11: prompt +6.7% 4K, +3.6% 8K, // +1.0% 20K, 5/5 each; first-token KL against the FP16 prompt path at or below MMQ's at 2,048 / 4K / 8K / 20K; neutral-writer // forced-token gate PASS over 48 prompts; small chunks, agent, first 8K read, backstop as MMQ; STRATA_PF_FUSED_SM86=0 off). + // IQ2_XXS / IQ2_XS gate/up (the IQ3_XXS and IQ2_XS packs) joined on 11-12 on the owner's word (RTX A6000, IQ3_XXS pack: prompt time fused / MMQ-mixed 0.874-0.976 from 300 to 8,193 + // tokens on the integration head, 5 rounds; teacher-forced KL vs the FP16 prompt path 0.965 / 1.062 / 1.072 / 1.008 at 512 / 1,000 / 2,048 / 8,192 ids; the rule: fused_tile_rule.hpp). // Every other CUDA card: opt-in as before. if (env < 0) { // the native Q2_0 pack's Q2_0 / Q2_0 layers: only with STRATA_PF_FUSED_Q2N=1 (d.q2n), on any sm_80+ card if (gu_type == T_Q2_0) { const DevInfo& d = dev_info(); return d.ok && d.q2n && d_type == T_Q2_0 && d_covered_on(d_type, d); } - if (gu_type != T_IQ2_S && gu_type != T_IQ3_XXS && gu_type != T_IQ3_S && gu_type != T_IQ4_XS) return false; + if (!strata::prefill::fused_tile::default_gate_format(gu_type)) return false; // IQ2_XXS / IQ2_XS joined 11-12 (owner), see fused_tile_rule.hpp const DevInfo& d = dev_info(); // 12.0 and 8.6 cards with 80+ SMs only (RTX PRO 5000 / 6000, RTX 5080 / 5090; RTX A6000 / A40, RTX 3090 / 3090 Ti / 3080 Ti): // on an RTX 5070 (48 SMs, IQ2_XS pack, experts partly in RAM) the fused kernels were 4.7% slower on 20K prompts (0/6 pairs), @@ -2808,7 +2813,7 @@ bool native_supported(int gu_type, int d_type) { // STRATA_PF_FUSED_SM40=1 (research, off unless set): the sm_86 / sm_120 cards with 40-79 SMs also take the launches with a staged gate/up kernel (IQ3_XXS / IQ3_S / IQ4_XS) and an IQ4_NL / Q2_0 // down; the rule itself is fused_tile::takes_by_default (unit-tested) static const bool sm40 = [] { const char* v = std::getenv("STRATA_PF_FUSED_SM40"); return v != nullptr && v[0] == '1'; }(); - return d.ok && strata::prefill::fused_tile::takes_by_default({d.s120, d.s121, d.sms, d.s86}, sm40, sw_on(gu_type, true), d_type == T_IQ4_NL || d_type == T_Q2_0) && !d.t75 && + return d.ok && strata::prefill::fused_tile::default_takes(env, {d.s120, d.s121, d.sms, d.s86}, sm40, sw_on(gu_type, true), d_type == T_IQ4_NL || d_type == T_Q2_0, gu_type) && !d.t75 && d_covered_on(d_type, d); } if (gu_type == T_Q2_0 && d_type != T_Q2_0) return false; // the opt-in (STRATA_PF_FUSED=1 as well) takes the Q2_0 / Q2_0 pair only diff --git a/tests/prefill/fused_tile_rule_test.cpp b/tests/prefill/fused_tile_rule_test.cpp index 76b27c6ba9..f80085c3ba 100644 --- a/tests/prefill/fused_tile_rule_test.cpp +++ b/tests/prefill/fused_tile_rule_test.cpp @@ -173,6 +173,43 @@ int main() { CHECK(bad == 0); std::printf("fused_tile_rule_test: default rule with the switch unset: %lld card / launch combinations compared with 'sm_86 / sm_120, 80+ SMs' (%lld differing)\n", cmpd, bad); } + // ---- the 2-bit gate/up formats in the default (owner 11-12): default_gate_format / default_takes(env, card, sm40, gate_staged, down_ok, gu_type) + { + using namespace strata::prefill::fused_tile; + // the ids are ggml's (GGML_TYPE_*, asserted in moe_fused_iq.cu): IQ2_XXS 16, IQ2_XS 17, IQ3_XXS 18, IQ1_S 19, IQ4_NL 20, IQ3_S 21, IQ2_S 22, IQ4_XS 23 + CHECK(default_gate_format(16) && default_gate_format(17)); // IQ2_XXS, IQ2_XS: new + CHECK(default_gate_format(18) && default_gate_format(21) && default_gate_format(22) && default_gate_format(23)); // IQ3_XXS, IQ3_S, IQ2_S, IQ4_XS: as before + CHECK(!default_gate_format(19) && !default_gate_format(20) && !default_gate_format(29) && !default_gate_format(12) && !default_gate_format(0)); // IQ1_S, IQ4_NL, IQ1_M, Q4_K, F32 + const int kIq2[2] = {16, 17}; + long long cmp2 = 0, bad2 = 0; + for (int gu : kIq2) + for (int s120 = 0; s120 < 2; ++s120) + for (int s86 = 0; s86 < 2; ++s86) + for (int s121 = 0; s121 < 2; ++s121) + for (int sms = 0; sms <= 200; ++sms) + for (int sm40 = 0; sm40 < 2; ++sm40) + for (int d = 0; d < 2; ++d) { + ++cmp2; + const Card c{s120 != 0, s121 != 0, sms, s86 != 0}; + const bool want = (s120 || s86) && sms >= 80; // sm_86 / sm_120, 80+ SMs; gate_staged is false for IQ2_XXS / IQ2_XS (sw_on), so sm40 adds nothing + if (default_takes(-1, c, sm40 != 0, false, d != 0, gu) != want) ++bad2; + if (default_takes(0, c, sm40 != 0, false, d != 0, gu)) ++bad2; // STRATA_PF_FUSED=0: the default is off again + if (default_takes(1, c, sm40 != 0, false, d != 0, gu)) ++bad2; // STRATA_PF_FUSED=1 is the opt-in, decided elsewhere + } + CHECK(bad2 == 0); + std::printf("fused_tile_rule_test: IQ2_XXS / IQ2_XS default: %lld card / switch combinations (%lld wrong)\n", cmp2, bad2); + // named cards: 80 SMs yes, 79 no, 48 no, AMD (no s86 / s120 flag) no at any SM count, sm_89 / sm_80 (no flag) no + CHECK(default_takes(-1, Card{false, false, 84, true}, false, false, true, 16) && default_takes(-1, Card{false, false, 80, true}, false, false, true, 17)); // A6000, 3080 Ti + CHECK(!default_takes(-1, Card{false, false, 79, true}, false, false, true, 16) && !default_takes(-1, Card{false, false, 79, true}, true, false, true, 17)); // 79 SMs: no, switch or not + CHECK(!default_takes(-1, Card{false, false, 48, true}, true, false, true, 16) && !default_takes(-1, Card{true, false, 48, false}, true, false, true, 17)); // A4000, 5070 + CHECK(default_takes(-1, Card{true, false, 100, false}, false, false, true, 16)); // PRO 5000 (sm_120) + CHECK(!default_takes(-1, Card{false, false, 304, false}, true, false, true, 16) && !default_takes(-1, Card{false, false, 128, false}, false, false, true, 17)); // AMD / sm_89: no + // the formats already in the list keep their rule: IQ3_XXS on 80+ SMs yes, with the sm40 switch and a staged gate also 40-79 + CHECK(default_takes(-1, Card{false, false, 84, true}, false, true, true, 18) && !default_takes(-1, Card{false, false, 60, true}, false, true, true, 18) && + default_takes(-1, Card{false, false, 60, true}, true, true, true, 18)); + // a format outside the list never takes the default + CHECK(!default_takes(-1, Card{false, false, 84, true}, true, true, true, 19) && !default_takes(-1, Card{false, false, 84, true}, true, true, true, 20)); + } // every class, every launch size: staged = false gives the rule of commit 083b1ac82 exactly as before the argument existed, for the sm_86 cards too (the new flag does not move them) { long long cmp = 0, diff = 0;