prefill: the Qwen3.6 engine takes the fused prompt kernels by default on the cards the Flash-Next default rule takes

strata-q36 used the fused int8 prompt-expert kernels only with STRATA_PF_FUSED=1 and read the prompt's experts with MMQ otherwise. Now an unset
STRATA_PF_FUSED takes them for every layer whose gate/up and down pair the kernels cover, on the cards fused_tile::takes_by_default takes (reused as
it is, no second class test): sm_86-class (compute capability 8.0 / 8.6 / 8.9) and sm_120 cards with 80+ SMs, and on 40-79 SM cards the staged
launches (a staged gate/up with a staged down) unless STRATA_PF_FUSED_SM40=0. STRATA_PF_FUSED=0 (or any value not starting with 1) keeps MMQ,
STRATA_PF_FUSED=1 stays the opt-in on every card that covers the pair. HIP builds, cards under 40 SMs, sm_121 and compute capability below 8
are unchanged (MMQ). The rule is fused_tile::q36_takes, a pure function with a unit test over the whole grid (switch, SM40 switch, card flags,
SM count, format flags) against an oracle; moe_fused_iq_q36.cu gets the host function native_layer_ext that feeds it the device's flags.
No kernel changes.

The engine's log line loses its draft mark: "strata-q36: prompt experts on the fused int8 kernels" (and the "(N of M layers), the rest on MMQ (int8)" form).

Measured (UD-Q4_K_XL, RTX A6000 84 SMs, every expert in VRAM): prompt speed fused / MMQ 1.034 at 2K, 0.964 at 4K, 0.966 at 8K, 0.970 at 20K,
decode equal; teacher-forced KL fused / MMQ over all positions 1.047 [0.924, 1.195] at 2K and 0.836 [0.727, 0.969] at 8K against the
non-MMQ writer's logits, 1.060 [0.893, 1.240] and 0.941 [0.700, 1.199] against the FP32 reference engine; both arms repeat bit for bit.
RTX A4000 (stream-bound, experts partly in RAM): speed equal, KL 0.880 [0.682, 1.098] at 2K and 0.704 [0.537, 0.904] at 8K.
This commit is contained in:
Niko1221 committed 2026-11-12 15:31:06 +01:00
1 parent 4e1e5f248e
commit 3860b43a4a
5 files changed
+91 -7

No files matched your search

@@ -120,6 +120,21 @@ constexpr bool default_takes_env(int env, const Card& c, int sm40_env, bool gate
return default_takes(env, c, sm40_on(sm40_env), gate_staged, down_ok, gu_type);
}
// ---- the Qwen3.6 engine (strata-q36, src/qwen35/q36_engine.cu; the copy of the kernels in src/prefill/moe_fused_iq_q36.cu): which layers take the fused prompt kernels.
// STRATA_PF_FUSED as pf_env reads it: -1 unset or empty, 1 = a value starting with '1' (the opt-in: every layer whose pair the kernels cover, on any card that covers it), 0 = any other value
// (off: every layer on MMQ). Before 11-12 the engine took the fused kernels only with the opt-in; unset now takes them on the cards the Flash-Next engine's default rule takes
// (takes_by_default above, reused as it is: sm_86-class and sm_120 cards with 80+ SMs, and the staged launches on 40-79 SMs unless STRATA_PF_FUSED_SM40=0), for the layers whose pair
// the kernels cover. gate_staged / down_ok are the launch kind of takes_by_default: the gate/up kernel is a weight-staging instance (sw_on(gu_type, true)) and the down is one the staged
// instances were measured with (a staged down or IQ4_NL / Q2_0). Evidence: RESULTS-E2E-BOSTON.md and RESULTS-P4-Q36.md (UD-Q4_K_XL on an RTX A6000, every expert in VRAM: prompt speed
// fused / MMQ 1.034 at 2K, 0.964 at 4K, 0.966 at 8K, 0.970 at 20K, decode equal; forced-token KL fused / MMQ over all positions 1.047 [0.924, 1.195] at 2K and 0.836 [0.727, 0.969] at 8K).
constexpr int pf_env(const char* v) { return v == nullptr || v[0] == '\0' ? -1 : (v[0] == '1' ? 1 : 0); }
constexpr int sm40_env_of(const char* v) { return v == nullptr ? -1 : (v[0] == '0' ? 0 : 1); } // STRATA_PF_FUSED_SM40 as moe_fused_iq.cu reads it
constexpr bool q36_takes(int env, const Card& c, int sm40_env, bool gate_staged, bool down_ok, bool covered) {
if (!covered || env == 0) return false;
if (env > 0) return true;
return takes_by_default(c, sm40_on(sm40_env), 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
+3
View File
@@ -32,6 +32,9 @@ void experts_native(const Batch& b, const NativeGeom& g, int n_expert, int64_t n
/// native_supported / experts_native plus the K-quant downs of UD-Q4_K_XL (a Q4_K or Q5_K gate/up with a Q5_K or Q6_K down: K = 512 is two 256-value
/// super-blocks), which the copy of moe_fused_iq.cu has instances for but whose dispatch is not part of it. Every other pair goes to the two above.
bool native_supported_ext(int gu_type, int d_type);
/// Whether the Qwen3.6 engine takes the fused kernels for a layer of this pair on the current device: native_supported_ext and the card rule (STRATA_PF_FUSED=1 on every card, unset on
/// the cards fused_tile_rule.hpp's takes_by_default takes, =0 never).
bool native_layer_ext(int gu_type, int d_type);
/// Launches (of experts_native / experts_native_ext) that took the unstaged 64-row kernel because the weight-staging check failed (an expert blob not in device memory, or an odd
/// address / row / offset): 0 in every default configuration. This copy's own count (moe_fused_iq.hpp's is the original copy's). For the GPU test.
int staged_blob_fallbacks();
+11
View File
@@ -99,6 +99,17 @@ bool native_supported_ext(int gu_type, int d_type) {
return native_supported(gu_type, d_type);
}
// Whether the engine takes the fused kernels for a layer of this pair on the current device: STRATA_PF_FUSED=1 on every card whose kernels cover the pair, unset on the cards
// the Flash-Next engine's default rule takes (fused_tile::q36_takes, which is takes_by_default for the card, the staged gate/up and the staged down), =0 never.
bool native_layer_ext(int gu_type, int d_type) {
static const int env = strata::prefill::fused_tile::pf_env(std::getenv("STRATA_PF_FUSED"));
static const int sm40_env = strata::prefill::fused_tile::sm40_env_of(std::getenv("STRATA_PF_FUSED_SM40"));
if (env == 0 || !native_supported_ext(gu_type, d_type)) return false;
const DevInfo& d = dev_info();
const bool down_ok = sw_on(d_type, false) || d_type == T_IQ4_NL || d_type == T_Q2_0;
return strata::prefill::fused_tile::q36_takes(env, {d.s120, d.s121, d.sms, d.s86}, sm40_env, sw_on(gu_type, true), down_ok, true);
}
void experts_native_ext(const Batch& b, const NativeGeom& g, int n_expert, int64_t n, const void* scratch, const void* xa, const int32_t* src, void* ha,
float* dm, void* stream) {
if (!is_kq_down_pair(g.gu_type, g.d_type)) {
+7 -7
View File
@@ -1393,13 +1393,13 @@ struct Engine {
const size_t n_state = m->layers.size() + (m->has_mtp ? 1 : 0);
fused_on.assign(n_state, 0);
#if !defined(__HIPCC__)
// Strata's fused kernels where they cover the layer's pair on this card: opt-in (STRATA_PF_FUSED=1), as for Flash-Next's packs
// below 80 SMs; unset or 0 keeps every layer on MMQ (the default is not changed until the gate for it is passed)
if (const char* pf = std::getenv("STRATA_PF_FUSED"); pf != nullptr && pf[0] == '1' && g.n_embd == FQ::kQ36Embd &&
g.n_ff == FQ::kQ36FF)
// Strata's fused kernels where they cover the layer's pair on this card: the default on the cards the Flash-Next engine's rule takes (sm_86-class and sm_120 cards
// with 80+ SMs, the staged launches on 40-79 SMs: fused_tile::q36_takes, the rule of takes_by_default), STRATA_PF_FUSED=1 on every card that covers the pair,
// STRATA_PF_FUSED=0 keeps every layer on MMQ; HIP builds, cards under 40 SMs and compute capability below 8 are as before (MMQ)
if (g.n_embd == FQ::kQ36Embd && g.n_ff == FQ::kQ36FF)
for (size_t i = 0; i < n_state; ++i) {
const Layer& L = layer_at((int) i);
fused_on[i] = FQ::native_supported_ext(L.L.gu_type, L.L.d_type) ? 1 : 0;
fused_on[i] = FQ::native_layer_ext(L.L.gu_type, L.L.d_type) ? 1 : 0;
}
#endif
use_pf = true;
@@ -1454,9 +1454,9 @@ struct Engine {
mq_h = dalloc((size_t) ne * FF);
}
if (n_fused == n_state)
std::fprintf(stderr, "strata-q36: [DRAFT] prompt experts on the fused int8 kernels\n");
std::fprintf(stderr, "strata-q36: prompt experts on the fused int8 kernels\n");
else if (n_fused > 0)
std::fprintf(stderr, "strata-q36: [DRAFT] prompt experts on the fused int8 kernels (%zu of %zu layers), the rest on MMQ (int8)\n",
std::fprintf(stderr, "strata-q36: prompt experts on the fused int8 kernels (%zu of %zu layers), the rest on MMQ (int8)\n",
n_fused, n_state);
else
std::fprintf(stderr, "strata-q36: prompt experts on %s\n", use_mmq ? "MMQ (int8)" : "the native grouped kernels");
+55
View File
@@ -457,5 +457,60 @@ int main() {
CHECK(pick(Card{false, false, 48, true}, 81910, E, false, false).ww == 4 && pick(Card{false, false, 48, true}, 81910, E, true, true).ww == 2); // the staged 128-row choice the fallback overrides
std::printf("fused_tile_rule_test: staging guard: %lld blob cases, 16 geometries, the check budget and the sticky fallback checked, %d failed so far\n", cases, failed);
}
// ---- the Qwen3.6 engine (strata-q36): which layers take the fused prompt kernels, q36_takes(env, card, sm40_env, gate_staged, down_ok, covered). The whole grid against an oracle written from the sentence of the
// decision: a layer whose pair the kernels do not cover, or STRATA_PF_FUSED=0 (or any value not starting with '1'): MMQ. =1: the fused kernels on every card. Unset: the cards of the Flash-Next default rule, an
// sm_86-class (8.0 / 8.6 / 8.9) or sm_120 card (not sm_121 alone, not a card with neither flag: sm_75, sm_87, sm_90, AMD) with 80+ SMs for every layer, 40-79 SMs for a staged gate/up with a staged down
// while STRATA_PF_FUSED_SM40 is not "0", under 40 SMs never.
{
using namespace strata::prefill::fused_tile;
CHECK(pf_env(nullptr) == -1 && pf_env("") == -1 && pf_env("1") == 1 && pf_env("1x") == 1 && pf_env("0") == 0 && pf_env("2") == 0 && pf_env("yes") == 0 && pf_env("off") == 0);
CHECK(sm40_env_of(nullptr) == -1 && sm40_env_of("0") == 0 && sm40_env_of("1") == 1 && sm40_env_of("") == 1 && sm40_env_of("on") == 1);
long long cmp = 0, bad = 0, yes_def = 0, yes_opt = 0, no_zero = 0, yes40 = 0, yes80 = 0;
for (int env = -1; env <= 1; ++env)
for (int sm40e = -1; sm40e <= 1; ++sm40e)
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 g = 0; g < 2; ++g)
for (int d = 0; d < 2; ++d)
for (int cov = 0; cov < 2; ++cov) {
++cmp;
const Card c{s120 != 0, s121 != 0, sms, s86 != 0};
const bool in_class = s120 || s86;
bool want = false;
if (cov != 0 && env == 1) want = true;
if (cov != 0 && env == -1) want = in_class && (sms >= 80 || (sms >= 40 && sm40e != 0 && g != 0 && d != 0));
if (q36_takes(env, c, sm40e, g != 0, d != 0, cov != 0) != want) ++bad;
if (want && env == -1) ++yes_def;
if (want && env == 1) ++yes_opt;
if (want && env == -1 && sms < 80) ++yes40;
if (want && env == -1 && sms >= 80) ++yes80;
if (env == 0 && !want) ++no_zero;
}
CHECK(bad == 0 && yes_def > 0 && yes_opt > 0 && yes40 > 0 && yes80 > 0 && no_zero > 0);
std::printf("fused_tile_rule_test: Qwen3.6 engine: %lld switch / SM40 switch / card flag / SM count / format combinations (%lld wrong; %lld yes unset, %lld of them below 80 SMs, %lld at 80+; %lld yes under =1)\n", cmp, bad, yes_def, yes40, yes80, yes_opt);
// named cards, formats of UD-Q4_K_XL (a staged K-quant gate/up with a staged Q5_K / Q6_K down), STRATA_PF_FUSED unset
const Card a6000c{false, false, 84, true}, a4000c{false, false, 48, true}, a100{false, false, 108, true}, rtx4090{false, false, 128, true}, rtx3050{false, false, 20, true}, pro5000{true, false, 110, false},
rtx5090{true, false, 170, false}, rtx5070{true, false, 48, false}, gb10c{false, true, 48, false}, turing{false, false, 68, false}, orin{false, false, 16, false}, hopper{false, false, 132, false};
for (const Card& c : {a6000c, a100, rtx4090, pro5000, rtx5090}) CHECK(q36_takes(-1, c, -1, true, true, true) && q36_takes(-1, c, 0, true, true, true)); // 80+ SMs: the SM40 switch moves nothing
for (const Card& c : {a4000c, rtx5070}) CHECK(q36_takes(-1, c, -1, true, true, true) && q36_takes(-1, c, 1, true, true, true) && !q36_takes(-1, c, 0, true, true, true)); // 40-79 SMs: staged, SM40 not "0"
for (const Card& c : {rtx3050, gb10c, turing, orin, hopper}) CHECK(!q36_takes(-1, c, -1, true, true, true) && !q36_takes(-1, c, 1, true, true, true)); // under 40 SMs, sm_121, no class flag: MMQ
CHECK(!q36_takes(-1, a4000c, -1, false, true, true) && !q36_takes(-1, a4000c, -1, true, false, true)); // an unstaged gate/up or down on 48 SMs: MMQ
CHECK(q36_takes(-1, a6000c, -1, false, false, true) && !q36_takes(-1, a6000c, -1, true, true, false)); // 80+ SMs take any covered pair, never an uncovered one
// STRATA_PF_FUSED=0 is MMQ on every card; =1 is the fused kernels on every card that covers the pair (the way strata-q36 behaved with the opt-in)
for (const Card& c : {a6000c, a4000c, a100, rtx4090, pro5000, rtx5090, rtx5070, rtx3050, gb10c, turing, orin, hopper}) {
CHECK(!q36_takes(0, c, -1, true, true, true) && q36_takes(1, c, -1, false, false, true) && !q36_takes(1, c, -1, true, true, false));
}
// the class is takes_by_default's: the same answer as the Flash-Next rule for a covered pair with the staged flags, every card above
for (const Card& c : {a6000c, a4000c, a100, rtx4090, pro5000, rtx5090, rtx5070, rtx3050, gb10c, turing, orin, hopper})
for (int sm40e = -1; sm40e <= 1; ++sm40e)
for (int g = 0; g < 2; ++g)
for (int d = 0; d < 2; ++d) CHECK(q36_takes(-1, c, sm40e, g != 0, d != 0, true) == takes_by_default(c, sm40_on(sm40e), g != 0, d != 0));
// compute capability: 8.0 / 8.6 / 8.9 are in the class (s86_class), 8.7 / 9.0 / 7.5 are not, STRATA_PF_FUSED_SM86=0 empties it
CHECK(q36_takes(-1, Card{false, false, 108, s86_class(8, 0)}, -1, true, true, true) && q36_takes(-1, Card{false, false, 128, s86_class(8, 9)}, -1, true, true, true));
CHECK(!q36_takes(-1, Card{false, false, 16, s86_class(8, 7)}, -1, true, true, true) && !q36_takes(-1, Card{false, false, 132, s86_class(9, 0)}, -1, true, true, true) &&
!q36_takes(-1, Card{false, false, 68, s86_class(7, 5)}, -1, true, true, true) && !q36_takes(-1, Card{false, false, 84, s86_class(8, 6, true)}, -1, true, true, true));
}
return failed == 0 ? 0 : 1;
}