mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-05 07:48:45 +00:00
prefill: the Qwen3.6 K-quant pairs take the 128-row tile from 112 rows an expert up on sm_86 cards with 80+ SMs
The tile rule picked 64 rows for the staged K-quant pairs of UD-Q4_K_XL (Q4_K / Q5_K gate/up with a Q5_K / Q6_K down) above 112 rows an expert on an sm_86 card with 80+ SMs, which is every prompt chunk of 4,096 tokens (the chunk the engine uses when the experts are resident: 32,768 routed rows over 256 experts). The staged 128-row kernels are faster there. One layer of Qwen3.6's shape (256 experts, top 8), MMQ ms / fused ms at 2,048 / 4,096 / 8,192 / 20,000 tokens, two repeats, the output bits hash equal at every tile: RTX A6000 (84 SMs), tile 64: Q4_K / Q5_K 0.91 0.85 0.71 0.65 Q4_K / Q6_K 0.82 0.73 0.61 0.53 Q5_K / Q6_K 0.71 0.63 0.52 0.46 RTX A6000 (84 SMs), tile 128: Q4_K / Q5_K 1.42 1.08 0.95 0.91 Q4_K / Q6_K 1.47 1.17 1.02 0.91 Q5_K / Q6_K 1.37 1.14 0.98 0.86 RTX PRO 5000 (110 SMs, sm_120), tile 64: 0.99 0.85 0.72 0.63 0.92 0.77 0.66 0.58 0.83 0.70 0.60 0.52 RTX PRO 5000 (110 SMs, sm_120), tile 128: 1.28 1.07 1.02 0.87 1.33 1.12 0.99 0.96 1.23 1.08 0.93 0.90 On the sm_120 card the rule already picks 128 there, so its default row equals the forced-128 row. At 2,048 tokens (64 rows an expert) both rules pick 128 already. fused_tile::wide_pair names the pairs of the existing wide class (a Q6_K or Q8_0 gate/up) and now also a Q4_K / Q5_K gate/up with a Q5_K / Q6_K down; experts_native_ext in the Qwen3.6 copy of the kernels passes it as the launch's wide argument. Flash-Next's K-quant gate/up (Q5_1 / Q8_0 down), the i-quant pairs, sm_120 cards, cards under 80 SMs (staged rule) and HIP are unchanged. The output bits are the same at either tile. No kernel changes; the unit test pins wide_pair over the type grid and the rule at the engine's chunk sizes on 84-, 108-, 128-SM sm_86 cards, the 48-SM staged card and the sm_120 cards, with a grid oracle for staged + wide on sm_86 cards.
This commit is contained in:
1 parent
3860b43a4a
commit
9e491df8e7
3 files changed
+61
-3
No files matched your search
@@ -43,7 +43,7 @@ constexpr double kS120LargeAvg = 159.9; // sm_120, 80+ SMs: a prompt of 8,192
|
||||
constexpr double kS120MidAvg = 112.0; // sm_120, 100-149 SMs (PRO 5000): from above the band, continuous with it
|
||||
constexpr double kS120SmallAvg = 119.9; // sm_120, 40-79 SMs (RTX 5070): a prompt of 6,144 tokens routes 6,143 positions = 119.98 an expert
|
||||
|
||||
// staged: the launch's gate/up kernel is a weight-staging instance (sw_on in src/prefill/moe_fused_iq.cu). wide: the launch's gate/up is Q6_K or Q8_0 (the pair class below). Defaults false = the rule as it was.
|
||||
// staged: the launch's gate/up kernel is a weight-staging instance (sw_on in src/prefill/moe_fused_iq.cu). wide: the launch's pair is in the class of wide_pair below (a Q6_K or Q8_0 gate/up; Qwen3.6's K-quant pairs). Defaults false = the rule as it was.
|
||||
constexpr Pick pick(const Card& c, int64_t n, int n_expert, bool staged = false, bool wide = false) {
|
||||
const double avg = (double) n / (double) (n_expert > 1 ? n_expert : 1);
|
||||
// GB10 (sm_121, 48 SMs): the launch's average is above 112 rows an expert for every prompt size here, so the 56-112 band never fires and the 64-row tile would be
|
||||
@@ -77,10 +77,23 @@ constexpr Pick pick(const Card& c, int64_t n, int n_expert, bool staged = false,
|
||||
// 50.64 -> 42.02, 109.88 -> 89.91, 186.36 -> 140.29. The class is narrow on purpose: the same cards run the 64-row tile faster above 112 rows for the unstaged IQ2_S / Q2_0 pair at 8K (33.80 against 35.05) and
|
||||
// for Q2_0 / Q2_0 (26.52 against 28.56 at 8K), so the line does not take every pair. On the RTX A6000 (sm_86, 84 SMs; lane P4-Q36, Boston jobs boston-20261111-2158-c9cf / -1d66 / -2209-d899) Qwen3.6 UD-Q6_K_XL with every expert in VRAM, end to end,
|
||||
// ratio to MMQ at 2K / 8K / 20K: today's tile rule 0.95 / 0.90 / 0.92 (five rounds, spread under 0.02), STRATA_PF_FUSED_TILE=128 0.95 / 0.98 / 0.99 (three rounds). The i-quant pairs keep the rule lane OWN-4X gated on that class.
|
||||
// The K-quant pairs of Qwen3.6's UD-Q4_K_XL (wide_pair below: a Q4_K / Q5_K gate/up with a Q5_K / Q6_K down, both weight-staging instances at 128 rows) take this line too. One layer of Qwen3.6's shape (256
|
||||
// experts, top 8), MMQ ms / fused ms, 2,048 / 4,096 / 8,192 / 20,000 tokens, two repeats, output bits hash equal at every tile, STRATA_PF_FUSED_TILE=64 against 128 (the rule's own pick before this line = 64
|
||||
// from 128 rows an expert, 4,096 tokens): RTX A6000 (sm_86, 84 SMs) Q4_K / Q5_K tile 64 0.91 / 0.85 / 0.71 / 0.65, tile 128 1.42 / 1.08 / 0.95 / 0.91; Q4_K / Q6_K 64: 0.82 / 0.73 / 0.61 / 0.53, 128: 1.47 / 1.17 /
|
||||
// 1.02 / 0.91; Q5_K / Q6_K 64: 0.71 / 0.63 / 0.52 / 0.46, 128: 1.37 / 1.14 / 0.98 / 0.86 (2,048 tokens = 64 rows an expert is 128 in the band already: equal). RTX PRO 5000 (sm_120, 110 SMs; its rule above
|
||||
// already picks 128 from 56 rows an expert, so its default row equals the forced-128 row): tile 64 0.99 / 0.85 / 0.72 / 0.63, 0.92 / 0.77 / 0.66 / 0.58, 0.83 / 0.70 / 0.60 / 0.52 against 1.28 / 1.07 / 1.02 / 0.87,
|
||||
// 1.33 / 1.12 / 0.99 / 0.96, 1.23 / 1.08 / 0.93 / 0.90. So on both SM classes tested 128 rows is the faster tile from 4,096 tokens up and not worse at 2,048 (par/RESULTS-Q36-DEFAULT.md).
|
||||
if (wide && c.s86 && c.sms >= 40 && avg > 112.0) return {2, Why::kS86Wide};
|
||||
return {avg > 56.0 && avg <= 112.0 ? 2 : 4, Why::kBand};
|
||||
}
|
||||
|
||||
// The gate/up + down pairs of the wide line (ggml type ids as in moe_fused_iq.cu): a Q6_K or Q8_0 gate/up (Q6_K + Q8_0, Q8_0 / Q8_0), and since 11-12 the K-quant pairs of Qwen3.6's UD-Q4_K_XL, a Q4_K or Q5_K gate/up
|
||||
// with a Q5_K or Q6_K down (the Qwen3.6 copy of the kernels only: Flash-Next's K-quant gate/up has a Q5_1 / Q8_0 down and keeps its rule).
|
||||
constexpr int kTypeQ8_0 = 8, kTypeQ4K = 12, kTypeQ5K = 13, kTypeQ6K = 14;
|
||||
constexpr bool wide_pair(int gu_type, int d_type) {
|
||||
return gu_type == kTypeQ6K || gu_type == kTypeQ8_0 || ((gu_type == kTypeQ4K || gu_type == kTypeQ5K) && (d_type == kTypeQ5K || d_type == kTypeQ6K));
|
||||
}
|
||||
|
||||
// Whether native_supported's default rule (STRATA_PF_FUSED unset; the IQ3_S pack's gate/up IQ2_S / IQ3_XXS / IQ3_S / IQ4_XS with an IQ4_NL / Q2_0 down) takes a launch on this card, as a pure function so the
|
||||
// rule can be tested without a GPU. sm_86-class (s86_class: 8.0, 8.6, 8.9) and sm_120 cards with 80+ SMs: always. sm40 (the 40-79 SM rule; ON by default since the owner's word of 11-12, STRATA_PF_FUSED_SM40=0 turns it off, see sm40_on
|
||||
// below; it was a research switch, off unless set, before) adds the sm_86 / sm_120 cards with 40-79 SMs for the
|
||||
|
||||
@@ -127,9 +127,9 @@ void experts_native_ext(const Batch& b, const NativeGeom& g, int n_expert, int64
|
||||
const Tables tb = tables(const_cast<void*>(scratch), n_expert);
|
||||
// staged: the launch's gate/up or down kernel is a weight-staging instance (the K-quant downs are, K = 512); the staged instances are the 128-row tile's. launch_ww (as in
|
||||
// experts_native) runs the staging check for such a launch: one whose expert blobs are not device memory at 2-byte aligned addresses takes the unstaged 64-row kernel of the
|
||||
// same formats (same output bits), sticky for the process, one log line, no exit. The wide argument (the Q6_K / Q8_0 gate/up class of the sm_86 tile line) is false for this path's gate/up.
|
||||
// same formats (same output bits), sticky for the process, one log line, no exit. The wide argument is fused_tile::wide_pair: true for this path's K-quant pairs, so sm_86 cards with 40+ SMs take the 128-row tile above 112 rows an expert (fused_tile_rule.hpp; the 80+ SM ones used to take 64 there).
|
||||
const bool staged = sw_on(g.gu_type, true) || sw_on(g.d_type, false);
|
||||
const int ww = launch_ww(b, g, n, n_expert, staged, g.gu_type == T_Q6_K || g.gu_type == T_Q8_0);
|
||||
const int ww = launch_ww(b, g, n, n_expert, staged, strata::prefill::fused_tile::wide_pair(g.gu_type, g.d_type));
|
||||
const int64_t tiles = (n + kTileRows - 1) / kTileRows + (b.e1 - b.e0);
|
||||
const unsigned k_gu = (unsigned) std::min<int64_t>(tiles * (GU_ROWS_N / weight_rows(ww)), (int64_t) d.sms * d.occ_kq);
|
||||
const unsigned k_d = (unsigned) std::min<int64_t>(tiles * (D_ROWS_N / weight_rows(ww)), (int64_t) d.sms * (g.d_type == T_Q5_K ? kd.occ5 : kd.occ6));
|
||||
|
||||
@@ -512,5 +512,50 @@ int main() {
|
||||
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));
|
||||
}
|
||||
// ---- the K-quant pairs of Qwen3.6's UD-Q4_K_XL in the wide class (tile 128 above 112 rows an expert on sm_86 cards with 40+ SMs): wide_pair(gu_type, d_type) and the rule at the engine's launch sizes
|
||||
{
|
||||
using namespace strata::prefill::fused_tile;
|
||||
// ggml type ids: Q8_0 8, Q4_K 12, Q5_K 13, Q6_K 14, IQ3_XXS 18, IQ3_S 21, IQ4_XS 23, IQ4_NL 20, Q5_1 7, Q2_0 (any), Q5_0 6
|
||||
long long bad = 0, yes = 0;
|
||||
for (int gu = 0; gu < 40; ++gu)
|
||||
for (int d = 0; d < 40; ++d) {
|
||||
const bool want = gu == 14 || gu == 8 || ((gu == 12 || gu == 13) && (d == 13 || d == 14));
|
||||
if (wide_pair(gu, d) != want) ++bad;
|
||||
yes += want ? 1 : 0;
|
||||
}
|
||||
CHECK(bad == 0 && yes == 84); // gu 14 (40 downs) + gu 8 (40) + {12, 13} x {13, 14} (4);
|
||||
CHECK(wide_pair(12, 13) && wide_pair(12, 14) && wide_pair(13, 13) && wide_pair(13, 14) && wide_pair(14, 8) && wide_pair(8, 8));
|
||||
CHECK(!wide_pair(12, 7) && !wide_pair(12, 8) && !wide_pair(13, 7) && !wide_pair(12, 20) && !wide_pair(18, 20) && !wide_pair(21, 20) && !wide_pair(23, 20) && !wide_pair(22, 2)); // Flash-Next's K-quant gate/up (Q5_1 / Q8_0 down) and the i-quant pairs keep their rule
|
||||
// Qwen3.6: 256 experts, top 8, a chunk of T tokens = T * 8 rows an expert-average of T / 32: 1,024 / 1,792 / 2,048 / 4,096 / 8,192 / 20,000 tokens
|
||||
const Card a6000{false, false, 84, true}, a4000{false, false, 48, true}, a100{false, false, 108, true}, rtx4090{false, false, 128, true}, pro5000{true, false, 110, false}, rtx5090{true, false, 170, false};
|
||||
const bool w = wide_pair(12, 13);
|
||||
for (const Card& c : {a6000, a100, rtx4090}) { // sm_86 class with 80+ SMs
|
||||
CHECK(pick(c, 1024 * 8, 256, true, w).ww == 4 && pick(c, 1792 * 8, 256, true, w).ww == 4); // 32 and 56 rows an expert: the band's bottom, 64 as before
|
||||
CHECK(pick(c, 2048 * 8, 256, true, w).ww == 2 && pick(c, 2048 * 8, 256, true, w).why == Why::kBand); // 64: the band, 128 as before
|
||||
for (int T : {4096, 8192, 20000}) CHECK(pick(c, (int64_t) T * 8, 256, true, w).ww == 2 && pick(c, (int64_t) T * 8, 256, true, w).why == Why::kS86Wide); // 128 / 256 / 625: 128 rows now
|
||||
for (int T : {4096, 8192, 20000}) CHECK(pick(c, (int64_t) T * 8, 256, true, false).ww == 4); // not the class: the old pick, 64 rows
|
||||
CHECK(pick(c, 4096 * 8, 256, true, w).ww == 2 && pick(c, 3584 * 8, 256, true, w).ww == 2 && pick(c, 3584 * 8, 256, true, false).ww == 2); // 112 rows an expert (3,584 tokens): band, 128 either way
|
||||
CHECK(pick(c, 3585 * 8, 256, true, w).ww == 2 && pick(c, 3585 * 8, 256, true, false).ww == 4); // 112.03: the line
|
||||
}
|
||||
// under 80 SMs the staged rule already takes 128 (A4000), sm_120 never looks at wide
|
||||
for (int T : {1024, 2048, 4096, 8192, 20000}) {
|
||||
const int64_t n = (int64_t) T * 8;
|
||||
CHECK(pick(a4000, n, 256, true, w).ww == 2 && pick(a4000, n, 256, true, w).why == Why::kStaged && pick(a4000, n, 256, true, false).ww == 2);
|
||||
for (const Card& c : {pro5000, rtx5090, Card{true, false, 48, false}}) CHECK(pick(c, n, 256, true, w).ww == pick(c, n, 256, true, false).ww && pick(c, n, 256, true, w).why == pick(c, n, 256, true, false).why);
|
||||
}
|
||||
CHECK(pick(pro5000, 4096 * 8, 256, true, w).ww == 2 && pick(pro5000, 2048 * 8, 256, true, w).ww == 2 && pick(rtx5090, 4096 * 8, 256, true, w).ww == 4); // the 110-SM card picks 128 from 56 rows an expert; the 170-SM one is as before
|
||||
// the whole sm_86 grid at the Qwen3.6 shape against an oracle written from the sentence: staged and wide, an sm_86-class card: 1-79 SMs 128 rows; 80+ SMs 128 rows from above 56 rows an expert, else 64
|
||||
long long bad2 = 0, cmp2 = 0;
|
||||
for (int sms = 1; sms <= 200; ++sms)
|
||||
for (int T = 256; T <= 24576; T += 64) {
|
||||
const int64_t n = (int64_t) T * 8;
|
||||
const double avg = (double) n / 256.0;
|
||||
const int want = sms < 80 ? 2 : (avg > 56.0 ? 2 : 4);
|
||||
++cmp2;
|
||||
if (pick(Card{false, false, sms, true}, n, 256, true, true).ww != want) ++bad2;
|
||||
}
|
||||
CHECK(bad2 == 0);
|
||||
std::printf("fused_tile_rule_test: Qwen3.6 K-quant pairs in the wide class: %lld sm_86 SM count / chunk combinations (%lld wrong)\n", cmp2, bad2);
|
||||
}
|
||||
return failed == 0 ? 0 : 1;
|
||||
}
|
||||
Reference in new issue
Block a user