okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
f2b41fd29
main
1// Standalone diagnostic harness for strata-prefill's optional MMQ path. 2// Keep this artifact outside the project source until it is reviewed and wired into a HIP test target. 3// It compares GGML's MMQ result (with its intended q8_1 activation rounding) to a CPU FP32 product using 4// GGML's own dequantizer for the exact same weight blocks. The tolerances screen layout/stride/bounds errors; 5// they do not assert bitwise or FP16 parity. 6#include "strata/prefill/mmq_ids_margin.hpp" 7#include "strata/prefill/moe_mmq.hpp" 8#include "ggml.h" 9#include <hip/hip_runtime.h> 10 11#include <algorithm> 12#include <cmath> 13#include <cstdint> 14#include <cstring> 15#include <cstdlib> 16#include <fstream> 17#include <iostream> 18#include <numeric> 19#include <sstream> 20#include <stdexcept> 21#include <string> 22#include <vector> 23 24namespace { 25using strata::prefill::mmq::Context ; 26using strata::prefill::mmq::Product ; 27using strata::prefill::mmq::matrix_bytes ; 28using strata::prefill::mmq::q8_bytes ; 29using strata::prefill::mmq::quantize ; 30using strata::prefill::mmq::supported ; 31 32void hip_check (hipError_t e ,const char * what ) { 33if (e != hipSuccess )throw std::runtime_error (std::string (what )+ ": " + hipGetErrorString (e )); 34} 35 36struct DeviceBuffer { 37void * p = nullptr ; 38explicit DeviceBuffer (size_t n ) {hip_check (hipMalloc (& p ,n ),"hipMalloc" ); } 39 ~DeviceBuffer () {if (p )hipFree (p ); } 40DeviceBuffer (const DeviceBuffer & )= delete ; 41DeviceBuffer & operator= (const DeviceBuffer & )= delete ; 42template < class T > T * as ()const {return static_cast < T *> (p ); } 43}; 44 45size_t row_bytes (ggml_type type ,int64_t cols ) { 46return ggml_row_size (type ,cols ); 47} 48 49std::vector < float > decode_matrix (ggml_type type ,const std::vector < uint8_t > & q ,int64_t rows ,int64_t cols ) { 50const auto * tr = ggml_get_type_traits (type ); 51if (!tr || !tr -> to_float )throw std::runtime_error ("GGML type has no host dequantizer" ); 52const size_t rb = row_bytes (type ,cols ); 53if (q .size ()!= (size_t )rows * rb )throw std::runtime_error ("matrix byte count mismatch" ); 54 std::vector < float > out ((size_t )rows * (size_t )cols ); 55for (int64_t r = 0 ;r < rows ;++ r ) { 56tr -> to_float (q .data ()+ (size_t )r * rb ,out .data ()+ (size_t )r * (size_t )cols ,cols ); 57 } 58return out ; 59} 60 61std::vector < uint8_t > make_q2_matrix (int64_t rows ,int64_t cols ,int expert ,int trial , 62ggml_type type = GGML_TYPE_Q2_0 ) { 63const auto * tr = ggml_get_type_traits (type ); 64if (!tr || !tr -> from_float_ref )throw std::runtime_error ("host quantizer unavailable" ); 65const size_t rb = row_bytes (type ,cols ); 66 std::vector < uint8_t > out ((size_t )rows * rb ); 67 std::vector < float > row ((size_t )cols ); 68for (int64_t r = 0 ;r < rows ;++ r ) { 69for (int64_t k = 0 ;k < cols ;++ k ) { 70const int code = (int ) ((k * 37 + r * 19 + expert * 23 + trial * 11 ) %101 )- 50 ; 71row [(size_t )k ]= 0.025f * std::sin (0.013f * (float ) (k + 1 )+ 0.17f * (float )r + 0.31f * (float )expert )+ 720.0015f * (float )code ; 73 } 74tr -> from_float_ref (row .data (),out .data ()+ (size_t )r * rb ,cols ); 75 } 76return out ; 77} 78 79std::vector < float > make_activations (int rows ,int64_t cols ,int trial ) { 80 std::vector < float > x ((size_t )rows * (size_t )cols ); 81for (int r = 0 ;r < rows ;++ r ) { 82for (int64_t k = 0 ;k < cols ;++ k ) { 83x [(size_t )r * (size_t )cols + (size_t )k ]= 840.45f * std::sin (0.009f * (float ) (k + 1 )+ 0.23f * (float )r + 0.07f * (float )trial )+ 850.17f * std::cos (0.021f * (float ) (k + 3 )- 0.19f * (float )r )+ 860.002f * (float ) (((k * 7 + r * 13 + trial * 5 ) %19 )- 9 ); 87 } 88 } 89// Exercise a complete all-zero row; its expected output is exactly zero even though Q8_1 rounding is enabled. 90 std::fill (x .end ()- cols ,x .end (),0.0f ); 91return x ; 92} 93 94std::vector < int32_t > permutation (int rows ,int shift ,bool reverse ) { 95 std::vector < int32_t > p ((size_t )rows ); 96for (int i = 0 ;i < rows ;++ i ) { 97p [(size_t )i ]= reverse ? (int32_t ) ((rows - 1 - i + shift ) %rows ) 98 : (int32_t ) ((i + shift ) %rows ); 99 } 100return p ; 101} 102 103std::vector < int32_t > make_bounds (const std::vector < int > & counts ) { 104 std::vector < int32_t > b (counts .size ()+ 1 ,0 ); 105for (size_t i = 0 ;i < counts .size ();++ i )b [i + 1 ]= b [i ]+ counts [i ]; 106return b ; 107} 108 109struct Metrics {double rel_l2 = 0 ,max_over_rms = 0 ,zero_row_max = 0 ,ref_rms = 0 ; }; 110 111Metrics run_product (Context & ctx ,hipStream_t stream ,const std::string & name ,ggml_type type , 112int64_t out_rows ,int64_t cols ,const std::vector < std::vector < uint8_t >> & expert_weights , 113const std::vector < int > & counts ,const std::vector < float > & x , 114const std::vector < int32_t > & src_ids ,const std::vector < int32_t > & dst_ids ) { 115const int rows = (int )src_ids .size (); 116const int experts = (int )expert_weights .size (); 117const std::vector < int32_t > bounds = make_bounds (counts ); 118if (!supported ((int )type )|| experts <=0 || counts .size ()!= expert_weights .size ()|| 119bounds .back ()!= rows || dst_ids .size ()!= (size_t )rows || x .size ()!= (size_t )rows * (size_t )cols ) { 120throw std::runtime_error (name + ": invalid test geometry" ); 121 } 122const size_t expert_bytes = matrix_bytes ((int )type ,out_rows ,cols ); 123const size_t tail = 4096 ;// match the production group's zero guard after its last expert 124 std::vector < uint8_t > w ((size_t )experts * expert_bytes + tail ,0 ); 125for (int e = 0 ;e < experts ;++ e ) { 126if (expert_weights [(size_t )e ].size ()!= expert_bytes )throw std::runtime_error (name + ": expert size mismatch" ); 127 std::copy (expert_weights [(size_t )e ].begin (),expert_weights [(size_t )e ].end (), 128w .begin ()+ (size_t )e * expert_bytes ); 129 } 130 131DeviceBuffer dx (x .size ()* sizeof (float )); 132DeviceBuffer dsrc (src_ids .size ()* sizeof (int32_t )); 133// llama.cpp's mul_mat_q and its stream-k fixup read the row-id table up to a J-column tile (J <= 128) past the last row, up to roundup(max_rows, J) from an 134// expert's first row (mmq_ids_margin.hpp): the table has the margin, its extra entries hold row index 0 (valid; they are read, never used) 135const size_t ids_rows = (size_t ) strata::prefill::mmq::mmq_ids_table_rows ((uint64_t )rows , (uint64_t )* std::max_element (counts .begin (),counts .end ())); 136 std::vector < int32_t > dst_table (dst_ids ); 137dst_table .resize (ids_rows ,0 ); 138DeviceBuffer ddst (dst_table .size ()* sizeof (int32_t )); 139DeviceBuffer dbounds (bounds .size ()* sizeof (int32_t )); 140DeviceBuffer dw (w .size ()); 141DeviceBuffer dxq (q8_bytes (rows ,cols )); 142DeviceBuffer dy ((size_t )rows * (size_t )out_rows * sizeof (float )); 143hip_check (hipMemcpy (dx .p ,x .data (),x .size ()* sizeof (float ),hipMemcpyHostToDevice ),"copy x" ); 144hip_check (hipMemcpy (dsrc .p ,src_ids .data (),src_ids .size ()* sizeof (int32_t ),hipMemcpyHostToDevice ),"copy src ids" ); 145hip_check (hipMemcpy (ddst .p ,dst_table .data (),dst_table .size ()* sizeof (int32_t ),hipMemcpyHostToDevice ),"copy dst ids" ); 146hip_check (hipMemcpy (dbounds .p ,bounds .data (),bounds .size ()* sizeof (int32_t ),hipMemcpyHostToDevice ),"copy bounds" ); 147hip_check (hipMemcpy (dw .p ,w .data (),w .size (),hipMemcpyHostToDevice ),"copy weights and zero tail" ); 148// On the product's stream: a plain hipMemset runs on the null stream, which a non-blocking stream does not wait 149// for - on a Radeon 8060S (gfx1151, Windows) it landed after the MMQ kernel and left only the sentinel 150hip_check (hipMemsetAsync (dy .p ,0xff , (size_t )rows * (size_t )out_rows * sizeof (float ),stream ), 151"initialize output sentinel" ); 152 153quantize (dx .as < float > (),dsrc .as < int32_t > (),dxq .p , (int )type ,cols ,cols ,rows , (void * )stream ); 154const int max_rows = * std::max_element (counts .begin (),counts .end ()); 155Product p ; 156p .w = dw .p ;p .type = (int )type ;p .w_rows = out_rows ;p .w_cols = cols ;p .expert_bytes = expert_bytes ; 157p .n = experts ;p .xq = dxq .p ;p .bounds = dbounds .as < int32_t > ();p .ids = ddst .as < int32_t > (); 158p .total_rows = rows ;p .max_rows = max_rows ;p .dst = dy .as < float > ();p .ld_dst = out_rows ; 159ctx .run (p , (void * )stream ); 160hip_check (hipGetLastError (),"MMQ launch" ); 161hip_check (hipStreamSynchronize (stream ),"MMQ synchronize" ); 162 std::vector < float > got ((size_t )rows * (size_t )out_rows ); 163hip_check (hipMemcpy (got .data (),dy .p ,got .size ()* sizeof (float ),hipMemcpyDeviceToHost ),"copy output" ); 164 165 std::vector < float > ref (got .size (),0.0f ); 166double err2 = 0 ,ref2 = 0 ; 167float max_abs = 0 ,zero_max = 0 ; 168for (int e = 0 ;e < experts ;++ e ) { 169const std::vector < float > wd = decode_matrix (type ,expert_weights [(size_t )e ],out_rows ,cols ); 170for (int r = bounds [(size_t )e ];r < bounds [(size_t )e + 1 ];++ r ) { 171const int src = src_ids [(size_t )r ]; 172const int dst = dst_ids [(size_t )r ]; 173const float * xr = x .data ()+ (size_t )src * (size_t )cols ; 174for (int64_t o = 0 ;o < out_rows ;++ o ) { 175double acc = 0 ; 176const float * wr = wd .data ()+ (size_t )o * (size_t )cols ; 177for (int64_t k = 0 ;k < cols ;++ k )acc += (double )wr [k ]* xr [k ]; 178ref [(size_t )dst * (size_t )out_rows + (size_t )o ]= (float )acc ; 179 } 180 } 181 } 182 { 183size_t bad = 0 ,first = got .size (); 184uint32_t first_bits = 0 ; 185for (size_t i = 0 ;i < got .size ();++ i ) 186if (!std::isfinite (got [i ])) {if (!bad ++ ) {first = i ; std::memcpy (& first_bits ,& got [i ],4 ); } } 187if (bad ) 188throw std::runtime_error (name + ": " + std::to_string (bad )+ " non-finite or unwritten MMQ outputs, first at row " + 189 std::to_string (first / (size_t )out_rows )+ " col " + std::to_string (first % (size_t )out_rows )+ 190" bits " + std::to_string (first_bits )); 191 } 192for (size_t i = 0 ;i < got .size ();++ i ) { 193const double d = (double )got [i ]- ref [i ]; 194err2 += d * d ;ref2 += (double )ref [i ]* ref [i ];max_abs = std::max (max_abs , (float ) std::fabs (d )); 195 } 196const double rms = std::sqrt (ref2 / (double )ref .size ()); 197for (int r = 0 ;r < rows ;++ r ) { 198if (std::all_of (x .begin ()+ (size_t )src_ids [(size_t )r ]* (size_t )cols , 199x .begin ()+ ((size_t )src_ids [(size_t )r ]+ 1 )* (size_t )cols , 200 [](float v ) {return v == 0.0f ; })) { 201for (int64_t o = 0 ;o < out_rows ;++ o ) 202zero_max = std::max (zero_max , std::fabs (got [(size_t )dst_ids [(size_t )r ]* (size_t )out_rows + (size_t )o ])); 203 } 204 } 205Metrics m ; 206m .rel_l2 = rms > 0 ? std::sqrt (err2 / (double )ref .size ()) /rms : std::sqrt (err2 ); 207m .max_over_rms = rms > 0 ?max_abs /rms :max_abs ; 208m .zero_row_max = zero_max ;m .ref_rms = rms ; 209 std::cout <<name <<": type=" << (int )type <<" rows=" <<rows <<" experts=" <<experts 210 <<" ref_rms=" <<m .ref_rms <<" rel_l2=" <<m .rel_l2 211 <<" max_abs/ref_rms=" <<m .max_over_rms <<" zero_row_max=" <<m .zero_row_max <<'\n' ; 212// Q8_1 rounding is expected. These deliberately broad limits catch wrong block order, row strides, ids, 213// expert bounds, or stale output while allowing ordinary activation-quantization error. 214if (m .rel_l2 > 0.04 || m .max_over_rms > 0.35 || m .zero_row_max > std::max (1e-5 ,1e-4 * rms )) 215throw std::runtime_error (name + ": parity screen failed" ); 216return m ; 217} 218 219std::vector < std::vector < uint8_t >> synthetic_q2 (int experts ,int64_t out_rows ,int64_t cols ,int trial , 220ggml_type type = GGML_TYPE_Q2_0 ) { 221 std::vector < std::vector < uint8_t >> w ; 222for (int e = 0 ;e < experts ;++ e )w .push_back (make_q2_matrix (out_rows ,cols ,e ,trial ,type )); 223return w ; 224} 225 226// A synthetic matrix of any ggml type with a host quantizer (the K-quants: the dense GGUF tensors the 227// STRATA_DENSE_MMQ path multiplies on HIP). K stays a 256-value multiple: the dense path only takes 228// such K, and a partial 256-value chunk would read past the synthetic tensor's end. 229std::vector < std::vector < uint8_t >> synthetic_of_type (ggml_type type ,int experts ,int64_t out_rows ,int64_t cols , 230int trial ) { 231const auto * tr = ggml_get_type_traits (type ); 232if (!tr || !tr -> from_float_ref )throw std::runtime_error ("no host quantizer for the type" ); 233 std::vector < std::vector < uint8_t >> w ; 234for (int e = 0 ;e < experts ;++ e ) { 235 std::vector < uint8_t > blocks ((size_t )out_rows * row_bytes (type ,cols )); 236 std::vector < float > row ((size_t )cols ); 237for (int64_t r = 0 ;r < out_rows ;++ r ) { 238for (int64_t k = 0 ;k < cols ;++ k ) { 239const int code = (int ) ((k * 29 + r * 17 + e * 31 + trial * 13 ) %97 )- 48 ; 240row [(size_t )k ]= 0.02f * std::sin (0.011f * (float ) (k + 2 )+ 0.29f * (float )r + 0.37f * (float )e )+ 2410.0009f * (float )code ; 242 } 243tr -> from_float_ref (row .data (),blocks .data ()+ (size_t )r * row_bytes (type ,cols ),cols ); 244 } 245w .push_back (std::move (blocks )); 246 } 247return w ; 248} 249 250// A synthetic matrix of any ggml type through ggml_quantize_chunk (the i-quants need an importance matrix; ones here). 251std::vector < std::vector < uint8_t >> synthetic_chunk (ggml_type type ,int experts ,int64_t out_rows ,int64_t cols ,int trial ) { 252 std::vector < std::vector < uint8_t >> w ; 253const std::vector < float > imatrix ((size_t )cols ,1.0f ); 254for (int e = 0 ;e < experts ;++ e ) { 255 std::vector < float > f ((size_t )out_rows * (size_t )cols ); 256for (int64_t r = 0 ;r < out_rows ;++ r ) 257for (int64_t k = 0 ;k < cols ;++ k ) { 258const int code = (int ) ((k * 29 + r * 17 + e * 31 + trial * 13 ) %97 )- 48 ; 259f [(size_t ) (r * cols + k )]= 0.02f * std::sin (0.011f * (float ) (k + 2 )+ 0.29f * (float )r + 0.37f * (float )e )+ 2600.0009f * (float )code ; 261 } 262 std::vector < uint8_t > blocks ((size_t )out_rows * row_bytes (type ,cols )); 263ggml_quantize_chunk (type ,f .data (),blocks .data (),0 ,out_rows ,cols , 264ggml_quantize_requires_imatrix (type ) ?imatrix .data () :nullptr ); 265w .push_back (std::move (blocks )); 266 } 267return w ; 268} 269 270bool run_real_iq3_first_expert (Context & ctx ,hipStream_t stream ,const std::string & pack ) { 271 std::ifstream meta (pack + "/native_experts.txt" ); 272if (!meta )throw std::runtime_error ("cannot open native_experts.txt: " + pack ); 273int layer = -1 ,gt = -1 ,dt = -1 ; 274uint64_t offset = 0 ,blob_bytes = 0 ; 275 std::string line ; 276bool found = false; 277while (std::getline (meta ,line )) { 278if (line .empty ()|| line [0 ]== '#' )continue ; 279 std::istringstream ss (line ); 280if (ss >>layer >>gt >>dt >>offset >>blob_bytes && layer == 0 ) {found = true;break ; } 281 } 282if (!found )throw std::runtime_error ("native metadata has no layer 0" ); 283if (gt != GGML_TYPE_IQ3_XXS || !supported (gt )|| !supported (dt )) { 284 std::cout <<"real-IQ3 first expert skipped: layer 0 types are " <<gt <<"/" <<dt <<'\n' ; 285return false; 286 } 287 std::ifstream file (pack + "/experts.bin" , std::ios::binary ); 288if (!file )throw std::runtime_error ("cannot open experts.bin: " + pack ); 289 std::vector < uint8_t > blob ((size_t )blob_bytes ); 290file .seekg ((std::streamoff )offset ); 291file .read ((char * )blob .data (), (std::streamsize )blob .size ()); 292if (!file )throw std::runtime_error ("short read of first native expert" ); 293 294constexpr int64_t N = 2560 ,FF = 640 ; 295const size_t gu_row = row_bytes ((ggml_type )gt ,N ),d_row = row_bytes ((ggml_type )dt ,FF ); 296const size_t one_gu = (size_t )FF * gu_row ,down_off = 2 * one_gu ,one_down = (size_t )N * d_row ; 297if (down_off + one_down != blob .size ())throw std::runtime_error ("native blob shape/offset mismatch" ); 298 std::vector < uint8_t > gu (blob .begin (),blob .begin ()+ (ptrdiff_t )down_off ); 299 std::vector < uint8_t > down (blob .begin ()+ (ptrdiff_t )down_off ,blob .end ()); 300const int rows = 5 ; 301const std::vector < int > counts {rows }; 302const auto src = permutation (rows ,2 , false),dst = permutation (rows ,1 , true); 303run_product (ctx ,stream ,"real-first-IQ3_XXS-GU" , (ggml_type )gt ,1280 ,N , {gu },counts , 304make_activations (rows ,N ,71 ),src ,dst ); 305run_product (ctx ,stream ,"real-first-down" , (ggml_type )dt ,N ,FF , {down },counts , 306make_activations (rows ,FF ,73 ),src ,dst ); 307 std::cout <<"real first expert tested: layer=0 expert=0 blob_bytes=" <<blob_bytes <<'\n' ; 308return true; 309} 310}// namespace 311 312int main (int argc ,char ** argv ) { 313try { 314if (argc > 2 )throw std::runtime_error ("usage: mmq-parity-test [optional-native-pack-dir]" ); 315hip_check (hipSetDevice (0 ),"hipSetDevice" ); 316hipStream_t stream = nullptr ; 317hip_check (hipStreamCreateWithFlags (& stream ,hipStreamNonBlocking ),"create stream" ); 318int failures = 0 ; 319 { 320Context ctx ;// reuse one MMQ context/pool across every pass below 321const std::vector < std::vector < int >> batches {{1 ,3 ,3 }, {4 ,1 ,2 }, {2 ,3 }}; 322int trial = 0 ; 323for (const auto & counts :batches ) { 324const int rows = std::accumulate (counts .begin (),counts .end (),0 ); 325const int n = (int )counts .size (); 326const auto src = permutation (rows ,trial + 1 , false); 327const auto dst = permutation (rows ,trial + 2 , true); 328run_product (ctx ,stream ,"synthetic-Q2_0-GU-pass" + std::to_string (trial ),GGML_TYPE_Q2_0 , 3291280 ,2560 ,synthetic_q2 (n ,1280 ,2560 ,trial ),counts , 330make_activations (rows ,2560 ,trial ),src ,dst ); 331run_product (ctx ,stream ,"synthetic-Q2_0-down-pass" + std::to_string (trial ),GGML_TYPE_Q2_0 , 3322560 ,640 ,synthetic_q2 (n ,2560 ,640 ,trial + 9 ),counts , 333make_activations (rows ,640 ,trial + 3 ),src ,dst ); 334++ trial ; 335 } 336// The K-quant instances a STRATA_MMQ_KQUANTS build adds (the dense GGUF projections of the 337// mixed-quant packs through Gemm::native). Skipped when the build does not have them. 338for (const auto & [name ,type ] : std::initializer_list < std::pair < const char * ,ggml_type >> { 339 {"Q4_K" ,GGML_TYPE_Q4_K }, {"Q5_K" ,GGML_TYPE_Q5_K }, {"Q6_K" ,GGML_TYPE_Q6_K }, 340 {"Q5_1" ,GGML_TYPE_Q5_1 }}) { 341if (!supported ((int )type )) { 342 std::cout <<"synthetic-" <<name <<" skipped: not built (STRATA_MMQ_KQUANTS off?)\n" ; 343continue ; 344 } 345const int rows = 5 ; 346const std::vector < int > counts {rows }; 347const auto src = permutation (rows ,3 , false),dst = permutation (rows ,2 , true); 348run_product (ctx ,stream , std::string ("synthetic-" )+ name ,type , 3491280 ,2560 ,synthetic_of_type (type ,1 ,1280 ,2560 ,5 ),counts , 350make_activations (rows ,2560 ,77 ),src ,dst ); 351 } 352// Round 0214 (the new Unsloth Qwen3.8-Flash-Next quants): every gate/up type of the new sets at 1280 x 2560 and 353// every down type at 2560 x 640 (FF 640 is not a multiple of 256: the 32-block types only). Q5_0 is built 354// only with STRATA_ORCA_Q4KS_MMQ (the opt-in); IQ1_M has no MMQ instance (its prompts take the gather route). 355for (const auto & [name ,type ] : std::initializer_list < std::pair < const char * ,ggml_type >> { 356 {"IQ1_M" ,GGML_TYPE_IQ1_M }, {"IQ2_XXS" ,GGML_TYPE_IQ2_XXS }, {"IQ2_XS" ,GGML_TYPE_IQ2_XS }, 357 {"IQ2_S" ,GGML_TYPE_IQ2_S }, {"IQ3_XXS" ,GGML_TYPE_IQ3_XXS }, {"IQ4_XS" ,GGML_TYPE_IQ4_XS }, 358 {"Q2_0" ,GGML_TYPE_Q2_0 }, {"Q5_0" ,GGML_TYPE_Q5_0 }}) { 359if (!supported ((int )type )) { std::cout <<"gate/up " <<name <<": no MMQ instance in this build (skipped)\n" ;continue ; } 360const std::vector < int > counts {2 ,3 }; 361const auto src = permutation (5 ,1 , false),dst = permutation (5 ,2 , true); 362run_product (ctx ,stream , std::string ("new-set-GU-" )+ name ,type ,1280 ,2560 ,synthetic_chunk (type ,2 ,1280 ,2560 ,7 ), 363counts ,make_activations (5 ,2560 ,8 ),src ,dst ); 364 } 365for (const auto & [name ,type ] : std::initializer_list < std::pair < const char * ,ggml_type >> { 366 {"Q2_0" ,GGML_TYPE_Q2_0 }, {"IQ4_NL" ,GGML_TYPE_IQ4_NL }, {"Q5_0" ,GGML_TYPE_Q5_0 }, {"Q8_0" ,GGML_TYPE_Q8_0 }}) { 367if (!supported ((int )type )) { std::cout <<"down " <<name <<": no MMQ instance in this build (skipped)\n" ;continue ; } 368const std::vector < int > counts {2 ,3 }; 369const auto src = permutation (5 ,1 , false),dst = permutation (5 ,2 , true); 370run_product (ctx ,stream , std::string ("new-set-down-" )+ name ,type ,2560 ,640 ,synthetic_chunk (type ,2 ,2560 ,640 ,9 ), 371counts ,make_activations (5 ,640 ,10 ),src ,dst ); 372 } 373// APR trellis experts (ggml types 144-146), when the build has their MMQ instances (agention fork): gate/up 374// 1280 x 2560 and down 2560 x 640 (5 blocks per row: the last 256-slice reads past the row, against zero 375// activations) 376for (const ggml_type t : {(ggml_type )145 , (ggml_type )146 , (ggml_type )144 }) { 377if (!supported ((int )t )) { std::cout <<"type " << (int )t <<": no MMQ instance in this build\n" ;continue ; } 378if ((int )t >= (int )GGML_TYPE_COUNT ) { std::cout <<"type " << (int )t <<": this ggml has no host traits for the trellis types (skipped)\n" ;continue ; } 379const std::vector < int > counts {2 ,3 }; 380const auto src = permutation (5 ,1 , false),dst = permutation (5 ,2 , true); 381const char * known = ggml_type_name (t );// null when this ggml has no name for the id (no trellis types in it): #3358 382const std::string tn = known ?known :"type" + std::to_string ((int )t ); 383const char * rep = std::getenv ("MMQ_PARITY_REPEAT" );// repeat each product (flakiness screen) 384const int reps = rep ? std::max (1 , std::atoi (rep )) :1 ; 385const auto wgu = synthetic_q2 (2 ,1280 ,2560 ,5 ,t ),wd = synthetic_q2 (2 ,2560 ,640 ,6 ,t ); 386for (int r = 0 ;r < reps ;++ r ) { 387run_product (ctx ,stream ,"synthetic-" + tn + "-GU" ,t ,1280 ,2560 ,wgu ,counts , 388make_activations (5 ,2560 ,5 ),src ,dst ); 389run_product (ctx ,stream ,"synthetic-" + tn + "-down" ,t ,2560 ,640 ,wd ,counts , 390make_activations (5 ,640 ,6 ),src ,dst ); 391 } 392 } 393if (argc == 2 )run_real_iq3_first_expert (ctx ,stream ,argv [1 ]); 394 } 395hip_check (hipStreamSynchronize (stream ),"final synchronize" ); 396hip_check (hipStreamDestroy (stream ),"destroy stream" ); 397 std::cout <<"MMQ parity screen passed\n" ; 398return failures ?1 :0 ; 399 }catch (const std::exception & e ) { 400 std::cerr <<"MMQ parity screen failed: " <<e .what () <<'\n' ; 401return 1 ; 402 } 403}