okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
3e0210663
main
1// src/kernels/native_grouped_parity.cpp - native_expert_grouped's group stride (grid_groups) and its fused SwiGLU + 2// q8_1 pass, against the launches before them (native_grouped_set_v1: a block row per possible group, SwiGLU and the 3// q8_1 quantization as two kernels over all cap_entries). Synthetic blobs, no model. 4// 5// build/native_grouped_parity the checks (a ctest; needs the GPU) 6// build/native_grouped_parity --bench the checks, then v1/new timings of 48 calls in a graph (a window's layers) 7// 8// Every gate/up format with every down format; calls of 0..cap groups of 1..T entries each (an empty call is what the 9// verify window's PCIe call usually is), entries from 0 and from past 0 (the PCIe call's follow the VRAM call's), 10// scattered destinations, stale scratch, grid_groups 0 (= cap), 1, 2, 3, 4 and above cap: the output must be BITWISE 11// equal to v1's, the rows the call must not write included (both start from the same NaN pattern). 12// 13// Random bytes are valid codes for every format here (every grid index is in range); only the fp16 block scales are 14// set, small enough that the SwiGLU outputs keep a finite fp16 q8_1 scale. 15#include "strata/kernels/iq_kernels.hpp" 16 17#include <cuda_runtime.h> 18 19#include <algorithm> 20#include <cmath> 21#include <cstdio> 22#include <cstdlib> 23#include <cstring> 24#include <numeric> 25#include <random> 26#include <string> 27#include <vector> 28 29namespace k= strata::kernels; 30 31namespace { 32 33int g_fail = 0 ; 34 35void ck (cudaError_t e ,const char * what ) { 36if (e != cudaSuccess ) { 37 std::fprintf (stderr ,"CUDA error in %s: %s\n" ,what ,cudaGetErrorString (e )); 38 std::exit (2 ); 39 } 40} 41 42template < typename T > 43T * dalloc (size_t n ) { 44T * p = nullptr ; 45ck (cudaMalloc (& p ,n * sizeof (T )+ 256 ),"malloc" ); 46ck (cudaMemset (p ,0 ,n * sizeof (T )+ 256 ),"memset" ); 47return p ; 48} 49 50const char * name_of (int t ) { 51switch (t ) { 52case 16 :return "IQ2_XXS" ; 53case 17 :return "IQ2_XS" ; 54case 18 :return "IQ3_XXS" ; 55case 20 :return "IQ4_NL" ; 56case 21 :return "IQ3_S" ; 57case 22 :return "IQ2_S" ; 58case 23 :return "IQ4_XS" ; 59case 29 :return "IQ1_M" ; 60case 42 :return "Q2_0" ; 61case 12 :return "Q4_K" ; 62case 13 :return "Q5_K" ; 63case 14 :return "Q6_K" ; 64case 7 :return "Q5_1" ; 65case 8 :return "Q8_0" ; 66case 6 :return "Q5_0" ; 67default :return "?" ; 68 } 69} 70int block_values (int t ) {return t == 20 || t == 7 || t == 8 || t == 6 || t == 2 || t == 3 ?32 :t == 42 ?64 :256 ; }// (6 = Q5_0: 32-value blocks, each needs its own finite scale) 71 72// `rows` rows of `n` values of format t: random bytes, then a finite fp16 scale in every block 73std::vector < uint8_t > random_rows (int t ,int64_t rows ,int64_t n , std::mt19937 & rng ) { 74const size_t rb = k::iq_row_bytes (t ,n ),bs = k::iq_row_bytes (t ,block_values (t )); 75 std::vector < uint8_t > w ((size_t )rows * rb ); 76 std::uniform_int_distribution < int > byte (0 ,255 ),ex (2 ,8 ),man (0 ,1023 ),sgn (0 ,1 ); 77for (auto & b :w )b = (uint8_t )byte (rng ); 78for (size_t o = 0 ;o < w .size ();o += bs ) { 79if (t == 29 ) { 80// IQ1_M: the fp16 scale is the top nibbles of its four scale words (bytes 48..55), the sign and the 81// exponent's top bits in the last: 0x1 / 0x2 there (0x9 / 0xA negative) keeps it in 2^-11 .. 2^-3 82const uint8_t nib = (uint8_t ) ((sgn (rng ) ?0x8 :0x0 ) | (1 + (byte (rng )& 1 ))); 83w [o + 55 ]= (uint8_t ) ((w [o + 55 ]& 0x0F ) | (nib <<4 )); 84 }else {// the other formats start their block with the fp16 scale: 2^-13 .. 2^-6 85// (Q4_K / Q5_K: 2^-14 .. 2^-11, their 6-bit sub-scales multiply it by up to 63) 86const int e = (t == 12 || t == 13 ) ?1 + ex (rng ) %4 :ex (rng ); 87const uint16_t h = (uint16_t ) ((sgn (rng ) ?0x8000 :0 ) | (e <<10 ) |man (rng )); 88 std::memcpy (& w [o ],& h ,2 ); 89if (t == 12 || t == 13 || t == 7 ) {// Q4_K / Q5_K: dmin, Q5_1: m - the second fp16, as small 90const int em = (t == 7 ) ?ex (rng ) :1 + ex (rng ) %4 ; 91const uint16_t m = (uint16_t ) ((sgn (rng ) ?0x8000 :0 ) | (em <<10 ) |man (rng )); 92 std::memcpy (& w [o + 2 ],& m ,2 ); 93 } 94 } 95 } 96return w ; 97} 98 99// one window's worth of expert calls on one format pair: blobs, T tokens' q8_1 activations, cap = T * K entries 100struct Setup { 101 k::NativeExpertLayout L ; 102int T = 0 ,K = 0 ,cap = 0 ,n_blobs = 0 ; 103int active_lo = 0 ,active_hi = 0 ; 104size_t slot = 0 ; 105uint8_t * blobs = nullptr ; 106uint8_t * xq = nullptr ; 107uint8_t * scr = nullptr ; 108size_t scr_bytes = 0 ; 109float * out = nullptr ; 110size_t out_floats = 0 ; 111unsigned long long * ptr = nullptr ; 112int32_t * start = nullptr ,* n = nullptr ,* dst = nullptr ,* tok = nullptr ; 113 114Setup (int gu ,int dt ,int64_t H ,int64_t FF ,int tokens ,int k_per_token ,int blobs_n , std::mt19937 & rng , 115cudaStream_t s ) { 116L = k::native_expert_layout (gu ,dt ,H ,FF ); 117T = tokens ;K = k_per_token ;cap = T * K ;n_blobs = blobs_n ; 118slot = (L .bytes + 255 )& ~(size_t )255 ; 119blobs = dalloc < uint8_t > (slot * (size_t )n_blobs ); 120for (int b = 0 ;b < n_blobs ;++ b ) { 121// gate rows | up rows (format gu, H values each) | down rows (format dt, FF values each) 122auto blob = random_rows (gu ,2 * FF ,H ,rng ); 123const auto down = random_rows (dt ,H ,FF ,rng ); 124blob .insert (blob .end (),down .begin (),down .end ()); 125if (blob .size ()!= L .bytes ) { std::fprintf (stderr ,"blob %zu != %zu bytes\n" ,blob .size (),L .bytes ); std::exit (2 ); } 126ck (cudaMemcpy (blobs + slot * (size_t )b ,blob .data (),blob .size (),cudaMemcpyHostToDevice ),"blob" ); 127 } 128 std::normal_distribution < float > nd (0.f ,1.f ); 129 std::vector < float > x ((size_t )T * H ); 130for (auto & v :x )v = nd (rng ); 131float * dx = dalloc < float > (x .size ()); 132ck (cudaMemcpy (dx ,x .data (),x .size ()* 4 ,cudaMemcpyHostToDevice ),"x" ); 133xq = dalloc < uint8_t > ((size_t )T * (H /32 )* 36 ); 134 k::quantize_q8_1_rows (dx ,T ,H ,xq ,s ); 135ck (cudaStreamSynchronize (s ),"quantize" ); 136cudaFree (dx ); 137scr_bytes = k::native_expert_scratch_bytes (cap ,FF ); 138scr = dalloc < uint8_t > (scr_bytes ); 139out_floats = (size_t )cap * H ; 140out = dalloc < float > (out_floats ); 141ptr = dalloc < unsigned long long > (cap ); 142start = dalloc < int32_t > (cap + 1 ); 143n = dalloc < int32_t > (1 ); 144dst = dalloc < int32_t > (cap ); 145tok = dalloc < int32_t > (cap ); 146 } 147 ~Setup () { 148cudaFree (blobs );cudaFree (xq );cudaFree (scr );cudaFree (out ); 149cudaFree (ptr );cudaFree (start );cudaFree (n );cudaFree (dst );cudaFree (tok ); 150 } 151// a plan: `groups` groups of 1..T entries from entry `base` on (as many as fit in cap) 152int plan (int groups ,int base , std::mt19937 & rng ) { 153 std::uniform_int_distribution < int > size (1 ,T ); 154 std::vector < int > sizes ; 155int used = base ; 156for (int g = 0 ;g < groups ;++ g ) { 157const int m = std::min (size (rng ),cap - used ); 158if (m <=0 )break ; 159sizes .push_back (m ); 160used += m ; 161 } 162return plan_sizes (sizes ,base ,rng ); 163 } 164// groups of these sizes from entry `base` on, each its own blob (as long as there are enough: a window's groups 165// are different experts); scattered destinations, random tokens 166int plan_sizes (const std::vector < int >& sizes ,int base , std::mt19937 & rng ) { 167 std::uniform_int_distribution < int > tk (0 ,T - 1 ); 168 std::vector < int > order (n_blobs ); 169 std::iota (order .begin (),order .end (),0 ); 170 std::shuffle (order .begin (),order .end (),rng ); 171 std::vector < unsigned long long > p ; 172 std::vector < int32_t > st (1 ,base ),tk_v ,ds (cap ); 173for (const int m :sizes ) { 174p .push_back ((unsigned long long ) (blobs + slot * (size_t )order [p .size () %order .size ()])); 175st .push_back (st .back ()+ m ); 176 } 177if (st .back ()> cap ) { std::fprintf (stderr ,"plan: %d entries > cap %d\n" ,st .back (),cap ); std::exit (2 ); } 178const int ng = (int )p .size (); 179active_lo = base ; 180active_hi = st .back (); 181 std::iota (ds .begin (),ds .end (),0 ); 182 std::shuffle (ds .begin (),ds .end (),rng );// scattered rows of `out` 183for (int e = 0 ;e < cap ;++ e )tk_v .push_back (tk (rng )); 184if (ng )ck (cudaMemcpy (ptr ,p .data (),p .size ()* 8 ,cudaMemcpyHostToDevice ),"ptr" ); 185ck (cudaMemcpy (start ,st .data (),st .size ()* 4 ,cudaMemcpyHostToDevice ),"start" ); 186ck (cudaMemcpy (n ,& ng ,4 ,cudaMemcpyHostToDevice ),"n" ); 187ck (cudaMemcpy (dst ,ds .data (),ds .size ()* 4 ,cudaMemcpyHostToDevice ),"dst" ); 188ck (cudaMemcpy (tok ,tk_v .data (),tk_v .size ()* 4 ,cudaMemcpyHostToDevice ),"tok" ); 189return ng ; 190 } 191void call (int64_t grid_groups ,cudaStream_t s ) { 192 k::native_expert_grouped (L ,ptr ,start ,n ,dst ,tok ,cap ,cap ,xq ,scr ,out ,s ,grid_groups ); 193 } 194// `out` after one call from the NaN pattern, the scratch holding `junk` (what earlier calls left there) 195 std::vector < uint32_t > result (bool v1 ,int64_t grid_groups ,int junk ,cudaStream_t s ) { 196ck (cudaMemset (out ,0xFF ,out_floats * 4 ),"memset" ); 197ck (cudaMemset (scr ,junk ,scr_bytes ),"memset" ); 198 k::native_grouped_set_v1 (v1 ); 199call (grid_groups ,s ); 200 k::native_grouped_set_v1 (false); 201ck (cudaStreamSynchronize (s ),"sync" ); 202 std::vector < uint32_t > o (out_floats ); 203ck (cudaMemcpy (o .data (),out ,o .size ()* 4 ,cudaMemcpyDeviceToHost ),"out" ); 204// Fused SwiGLU does not write h or inactive Q8 rows. Compare only the 205// active Q8_1 bytes, appended after the full output (including padding). 206const size_t fa = ((size_t )cap * L .n_ff * sizeof (float )+ 255 )& ~(size_t )255 ; 207const size_t qrow = (size_t ) (L .n_ff /32 )* 36 ; 208const size_t qb = (size_t ) (active_hi - active_lo )* qrow ; 209const size_t old = o .size (); 210o .resize (old + qb /sizeof (uint32_t )); 211if (qb ) 212ck (cudaMemcpy (o .data ()+ old ,scr + 3 * fa + active_lo * qrow ,qb ,cudaMemcpyDeviceToHost ),"active hq" ); 213return o ; 214 } 215}; 216 217// The words that differ between v1 and the new launches: where, their values, and whether it is a NaN / Inf pair or a finite difference. 218void diff_list (const std::vector < uint32_t >& v1 ,const std::vector < uint32_t >& nw ,int64_t H ,size_t out_floats ,const char * what ) { 219size_t shown = 0 ,total = 0 ,nan_pairs = 0 ,fin = 0 ; 220double maxrel = 0 ; 221for (size_t i = 0 ;i < v1 .size ();++ i ) { 222if (v1 [i ]== nw [i ])continue ; 223++ total ; 224float a ,b ; 225 std::memcpy (& a ,& v1 [i ],4 ); 226 std::memcpy (& b ,& nw [i ],4 ); 227const bool fa = std::isfinite (a ),fb = std::isfinite (b ); 228if (!fa && !fb )++ nan_pairs ; 229if (fa && fb && i < out_floats ) {++ fin ;maxrel = std::max (maxrel , (double ) std::fabs (a - b ) / (std::fabs (a )+ 1e-30 )); } 230if (shown ++ < 6 ) { 231if (i < out_floats ) 232 std::printf (" %s word %zu (row %zu col %lld): v1 %.9g (0x%08x) new %.9g (0x%08x)\n" ,what ,i ,i / (size_t )H , 233 (long long ) (i % (size_t )H ),a ,v1 [i ],b ,nw [i ]); 234else 235 std::printf (" %s q8 word %zu (past the output): v1 0x%08x new 0x%08x\n" ,what ,i - out_floats ,v1 [i ],nw [i ]); 236 } 237 } 238 std::printf (" %s: %zu words differ: %zu both non-finite, %zu finite output floats (max relative difference %.3e)\n" ,what ,total , 239nan_pairs ,fin ,maxrel ); 240} 241 242void check (int gu ,int dt ,int64_t H ,int64_t FF ,cudaStream_t s , std::mt19937 & rng ) { 243Setup S (gu ,dt ,H ,FF ,6 ,4 ,9 ,rng ,s );// 6 tokens x 4 experts: cap 24 entries 244int calls = 0 ,bad = 0 ; 245size_t written = 0 ; 246for (const int base : {0 ,7 }) { 247for (const int groups : {0 ,1 ,2 ,3 ,5 ,8 ,24 }) { 248const int ng = S .plan (groups ,base ,rng ); 249const auto ref = S .result (true,0 ,0x00 ,s ); 250size_t w = 0 ; 251for (size_t i = 0 ;i < S .out_floats ;++ i )w += ref [i ]!= 0xFFFFFFFFu ; 252written += w ; 253for (const int64_t gy : {(int64_t )0 , (int64_t )1 , (int64_t )2 , (int64_t )3 , (int64_t )4 , (int64_t )S .cap + 3 }) { 254const auto got = S .result (false,gy , (calls & 1 ) ?0x7F :0x00 ,s ); 255++ calls ; 256size_t diff = 0 ; 257for (size_t i = 0 ;i < ref .size ();++ i )diff += ref [i ]!= got [i ]; 258if (diff ) { 259 std::printf (" %-8s/%-7s base %d, %d groups, grid_groups %lld: %zu of %zu output/Q8 words differ FAIL\n" , 260name_of (gu ),name_of (dt ),base ,ng , (long long )gy ,diff ,ref .size ()); 261if (!bad ) { 262diff_list (ref ,got ,H ,S .out_floats ,"first failure" ); 263 } 264++ bad ; 265 } 266 } 267 } 268 } 269 std::printf ("%-8s/%-7s %5lld x %4lld %d calls: %s (%zu output floats written in all)\n" ,name_of (gu ),name_of (dt ), 270 (long long )H , (long long )FF ,calls ,bad ?"FAIL" :"bitwise equal to v1" ,written ); 271if (written == 0 ) { std::printf (" nothing was written: the check checked nothing FAIL\n" );++ bad ; } 272g_fail += bad ; 273} 274 275// ------------------------------------------------------------------------------------------------ --bench 276// A window's 48 calls, one per layer, each with ITS OWN experts as the layers have: copies of the Setup's blobs in one 277// arena, so the weights stream from DRAM as in the engine. (48 calls re-reading the same 28 experts - 73 MB, about an 278// Ada L2 - would read part of them from L2; the engine's layers share none.) 279struct Layers { 280uint8_t * arena = nullptr ; 281 std::vector < unsigned long long *> ptr ;// per layer: its groups' blobs (device) 282Layers (Setup & S ,int ng ) { 283const int per = std::max (ng ,1 ); 284arena = dalloc < uint8_t > (S .slot * (size_t ) (48 * per )); 285for (int l = 0 ;l < 48 ;++ l ) { 286 std::vector < unsigned long long > p ; 287for (int j = 0 ;j < per ;++ j ) { 288uint8_t * d = arena + S .slot * (size_t ) (l * per + j ); 289ck (cudaMemcpy (d ,S .blobs + S .slot * (size_t ) ((l * per + j ) %S .n_blobs ),S .L .bytes , 290cudaMemcpyDeviceToDevice ),"blob copy" ); 291p .push_back ((unsigned long long )d ); 292 } 293unsigned long long * dp = dalloc < unsigned long long > (p .size ()); 294ck (cudaMemcpy (dp ,p .data (),p .size ()* 8 ,cudaMemcpyHostToDevice ),"ptr" ); 295ptr .push_back (dp ); 296 } 297 } 298Layers (const Layers & )= delete ; 299Layers & operator= (const Layers & )= delete ; 300 ~Layers () { 301for (auto * p :ptr )cudaFree (p ); 302cudaFree (arena ); 303 } 304}; 305 306// the 48 calls of one variant captured in one graph 307cudaGraphExec_t make_graph (cudaStream_t s ,Setup & S ,const Layers & Ls ,bool v1 ,int64_t gy ) { 308 k::native_grouped_set_v1 (v1 ); 309cudaGraph_t g ; 310cudaGraphExec_t ge ; 311ck (cudaStreamBeginCapture (s ,cudaStreamCaptureModeThreadLocal ),"capture" ); 312for (int l = 0 ;l < 48 ;++ l ) 313 k::native_expert_grouped (S .L ,Ls .ptr [l ],S .start ,S .n ,S .dst ,S .tok ,S .cap ,S .cap ,S .xq ,S .scr ,S .out ,s ,gy ); 314ck (cudaStreamEndCapture (s ,& g ),"capture" ); 315ck (cudaGraphInstantiate (& ge ,g ,0 ),"instantiate" ); 316ck (cudaGraphDestroy (g ),"graph" ); 317 k::native_grouped_set_v1 (false); 318return ge ; 319} 320 321// one launch of the graph: microseconds per call 322float launch_us (cudaStream_t s ,cudaGraphExec_t ge ,cudaEvent_t e0 ,cudaEvent_t e1 ) { 323ck (cudaEventRecord (e0 ,s ),"record" ); 324ck (cudaGraphLaunch (ge ,s ),"launch" ); 325ck (cudaEventRecord (e1 ,s ),"record" ); 326ck (cudaEventSynchronize (e1 ),"bench" ); 327float ms = 0 ; 328ck (cudaEventElapsedTime (& ms ,e0 ,e1 ),"elapsed" ); 329return 1e3f * ms /48.0f ; 330} 331 332float median (std::vector < float > v ) { 333 std::sort (v .begin (),v .end ()); 334return v [v .size () /2 ]; 335} 336 337// The two variants' launches ALTERNATE (v1-new, new-v1, ...) after a warm-up, and each reports its median: a card 338// under sustained load steps its clock down after a fraction of a second (an RTX 4080 SUPER went from 80 to 89 us 339// per gate/up call within one run), and whichever variant ran before the step would look faster. 340constexpr int kWarmPairs = 20 ,kPairs = 40 ; 341 342void bench (cudaStream_t s , std::mt19937 & rng ) { 343 std::printf ("\n--bench: microseconds per call, a window's 48 calls in a graph, each layer with its own experts (the\n" 344"weights stream from DRAM as in the engine); v1 / new (grid_groups): medians of %d launches each,\n" 345"alternating, after %d warm-up pairs - idle GPU assumed\n" ,kPairs ,kWarmPairs ); 346// a verify window's shape: 4 tokens x 10 experts, 2560 x 768 IQ3_S / IQ4_XS experts 347Setup S (21 ,23 ,2560 ,768 ,4 ,10 ,32 ,rng ,s ); 348 std::vector < int > vram (16 ,1 ); 349vram .insert (vram .end (),12 ,2 );// 28 groups, 40 entries 350const struct {const char * what ; std::vector < int > sizes ;int64_t gy ; }rows []= { 351 {"no group (the PCIe call at pcie_frac 0)" , {},4 }, 352 {"1 group of 2 entries (a PCIe call)" , {2 },4 }, 353 {"28 groups, 40 entries (a VRAM call)" ,vram ,0 }, 354 }; 355cudaEvent_t e0 ,e1 ; 356ck (cudaEventCreate (& e0 ),"event" ); 357ck (cudaEventCreate (& e1 ),"event" ); 358for (const auto & r :rows ) { 359const int ng = S .plan_sizes (r .sizes ,0 ,rng ); 360const Layers Ls (S ,ng );// 48 x 28 experts: 3.7 GB for the VRAM call 361cudaGraphExec_t ga = make_graph (s ,S ,Ls , true,0 ),gb = make_graph (s ,S ,Ls , false,r .gy ); 362 std::vector < float > ta ,tb ; 363for (int i = 0 ;i < kWarmPairs + kPairs ;++ i ) { 364const bool a_first = i %2 == 0 ; 365const float x = launch_us (s ,a_first ?ga :gb ,e0 ,e1 ),y = launch_us (s ,a_first ?gb :ga ,e0 ,e1 ); 366if (i < kWarmPairs )continue ; 367ta .push_back (a_first ?x :y ); 368tb .push_back (a_first ?y :x ); 369 } 370ck (cudaGraphExecDestroy (ga ),"graph" ); 371ck (cudaGraphExecDestroy (gb ),"graph" ); 372 std::printf (" %-42s %8.2f / %8.2f us (grid_groups %lld)\n" ,r .what ,median (ta ),median (tb ), (long long )r .gy ); 373 } 374cudaEventDestroy (e0 ); 375cudaEventDestroy (e1 ); 376} 377 378}// namespace 379 380int main (int argc ,char ** argv ) { 381setvbuf (stdout ,nullptr ,_IONBF ,0 );// keep the trail on a crash 382#if defined(__HIP_PLATFORM_AMD__ ) 383 {// gfx1151 defaults to expert mode 8 (the fused gate/up + SwiGLU + q8_1 LDS kernel) for an unstrided call and to the CUDA layout 384// for a strided one; the two sum in a different order, so "bitwise equal to v1" does not hold between them there (summation 385// order only: round 0214 diagnosis, RESULTS-ENGAMD.md). Pin the CUDA layout for both runs unless the caller chose a mode. 386cudaDeviceProp prop ; 387if (std::getenv ("STRATA_EXP_MODE" )== nullptr && cudaGetDeviceProperties (& prop ,0 )== cudaSuccess && 388 std::strstr (prop .gcnArchName ,"gfx1151" )!= nullptr ) { 389#ifdef _WIN32 390_putenv_s ("STRATA_EXP_MODE" ,"0" ); 391#else 392setenv ("STRATA_EXP_MODE" ,"0" ,1 ); 393#endif 394 std::printf ("gfx1151: STRATA_EXP_MODE=0 pinned for both runs (mode 8 and the CUDA layout differ in summation order)\n" ); 395 } 396 } 397#endif 398const bool do_bench = argc > 1 && std::string (argv [1 ])== "--bench" ; 399cudaStream_t s ; 400ck (cudaStreamCreate (& s ),"stream" ); 401 std::mt19937 rng (316 ); 402for (int gu : {16 ,17 ,18 ,21 ,22 ,23 ,29 ,42 ,12 ,13 , 403#ifdef STRATA_Q6K_EXPERTS 40414 , 405#endif 4068 })// STRATA_GU_FMTS 407for (int dt : {20 ,23 ,42 ,7 ,8 ,6 })check (gu ,dt ,512 ,256 ,s ,rng );// STRATA_D_FMTS (6 = Q5_0: UD-IQ4_XS / Q3_K_XL); IQ4_XS: n_ff % 256 408check (42 ,42 ,2560 ,640 ,s ,rng ); 409check (21 ,20 ,2560 ,640 ,s ,rng );// a model's shapes 410// round 0214: every expert type pair of the new Unsloth Qwen3.8-Flash-Next sets at the model's 2560 x 640 411// (IQ1_M/IQ2_XXS/IQ2_XS/IQ2_S/Q2_0/IQ3_XXS/IQ4_XS gate/up; Q2_0/IQ4_NL/Q5_0/Q8_0 down; IQ4_XS is 256-wide so n_ff 640 needs a 32-block down) 412for (int gu : {29 ,16 ,17 ,22 ,42 ,18 ,23 }) 413for (int dt : {42 ,20 ,6 ,8 })check (gu ,dt ,2560 ,640 ,s ,rng ); 414check (21 ,23 ,2560 ,768 ,s ,rng ); 415if (do_bench )bench (s ,rng ); 416 std::printf ("native_grouped_parity: %d failures\n" ,g_fail ); 417cudaStreamDestroy (s ); 418return g_fail ?1 :0 ; 419}