#2069 sm_75: grouped native experts default to mode 4 (down: mode 0 in windows of 4+ tokens)

native_expert_bench on real Q2_0 rows of Flash-Next, RTX 2080 Ti, bitwise
equal to mode 0 in every case: 10 groups x 1 entry 47.3 -> 41.4 us,
20 x 1 83.7 -> 71.5, 30 x 1 120.2 -> 100.2, 20 x 2 124.2 -> 111.4. The down
projection of mode 4 loses with 3+ entries per group (12 x 3 36.5 -> 40.8,
16 x 4 56.9 -> 68.9), so cap_groups > 30 keeps mode 0 for it.
STRATA_SM75_EXP=0 keeps the CUDA layout; STRATA_EXP_MODE still overrides.
This commit is contained in:
Rafa authored and Niko1221 committed 2026-10-14 07:10:23 +02:00
1 parent 004efd4606
commit 26855986e1
1 file changed
+23 -3
+23 -3
View File
@@ -3615,13 +3615,32 @@ int exp_mode() {
// IQ4_XS 328 -> 261 us, bitwise equal); STRATA_SM61_TABLE=0 keeps the CUDA layout
const char* sm61 = std::getenv("STRATA_SM61_TABLE");
const bool p40 = major == 6 && minor == 1 && (sm61 == nullptr || std::atoi(sm61) != 0);
per_dev[dev] = 1 + ((major == 7 && minor == 0 && sm70 != nullptr && std::atoi(sm70) != 0) || p100 || p40 ? 8 : kExpModeDefault);
// Turing (sm_75): mode 4 (native_expert_bench, real Q2_0 rows of Flash-Next, bitwise equal to mode 0 on an RTX
// 2080 Ti: 10 experts x 1 entry 47.3 -> 41.4 us, 30 x 1 120.2 -> 100.2 us); the down projection keeps the CUDA
// layout in windows of 4+ tokens (sm75_down_em below). STRATA_SM75_EXP=0 keeps the CUDA layout.
const char* sm75 = std::getenv("STRATA_SM75_EXP");
const bool turing = major == 7 && minor == 5 && (sm75 == nullptr || std::atoi(sm75) != 0);
per_dev[dev] = 1 + ((major == 7 && minor == 0 && sm70 != nullptr && std::atoi(sm70) != 0) || p100 || p40 ? 8 : turing ? 4 : kExpModeDefault);
}
return per_dev[dev] - 1;
#endif
}
#endif
int g_exp_phase = 0; // the bench: 0 all, 1 gate/up + swiglu + quantize only, 2 down only
#if STRATA_EXP_LAYOUTS && !defined(__HIPCC__)
// The down projection's mode on Turing's default: mode 4 is slower than the CUDA layout once groups have 3+ entries
// (12 x 3: 36.5 -> 40.8 us, 16 x 4: 56.9 -> 68.9) - windows of 4+ tokens (cap_groups > 30) keep mode 0 there.
int sm75_down_em(int em0, int64_t cap_groups) {
if (em0 != 4 || g_exp_mode >= 0 || std::getenv("STRATA_EXP_MODE") != nullptr || cap_groups <= 30) return em0;
int dev = 0, major = 0, minor = 0;
if (cudaGetDevice(&dev) != cudaSuccess) return em0;
cudaDeviceGetAttribute(&major, cudaDevAttrComputeCapabilityMajor, dev);
cudaDeviceGetAttribute(&minor, cudaDevAttrComputeCapabilityMinor, dev);
return major == 7 && minor == 5 ? 0 : em0;
}
#else
int sm75_down_em(int em0, int64_t) { return em0; }
#endif
void native_expert_set_mode(int mode, int phase) {
#if STRATA_EXP_LAYOUTS
@@ -3789,7 +3808,8 @@ void native_expert_grouped(const NativeExpertLayout& L, const unsigned long long
const int d_rows = (!g_old_kernels && !g_no_sub16_gu && L.n_ff == 640) ? (L.d_type == 20 || L.d_type == 40 ? 32 : (L.d_type == 42 ? 16 : 8)) : 8;
const dim3 gd((unsigned) ((L.n_embd + d_rows - 1) / d_rows), (unsigned) gy);
#if STRATA_EXP_LAYOUTS
if ((em0 == 7 || em0 == 8) && (L.d_type == 20 || L.d_type == 42)) {
const int em0d = sm75_down_em(em0, cap_groups);
if ((em0d == 7 || em0d == 8) && (L.d_type == 20 || L.d_type == 42)) {
const dim3 gl((unsigned) ((L.n_embd + LDS_RB - 1) / LDS_RB), (unsigned) cap_groups);
const size_t sh = (size_t) LDS_NT * (size_t) (L.n_ff / 32) * sizeof(block_q8_1);
if (L.d_type == 20) native_down_lds_kernel<20><<<gl, 256, sh, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out);
@@ -3797,7 +3817,7 @@ void native_expert_grouped(const NativeExpertLayout& L, const unsigned long long
check("native_expert_grouped/down");
return;
}
const int em = em0 >= 5 ? kExpFallback : em0;
const int em = em0d >= 5 ? kExpFallback : em0d;
const dim3 gd_amd((unsigned) ((L.n_embd + (em == 1 ? 3 : em == 4 ? 31 : 15)) / (em == 1 ? 4 : em == 4 ? 32 : 16)), (unsigned) cap_groups);
#define STRATA_D_AMD(T) \
case T: if (em == 1) native_down_amd_kernel<T, 1><<<gd_amd, 256, 0, s>>>(grp_ptr, grp_start, n_groups, ent_dst, hq, L, out); \