okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
db137d917
main
1// src/kernels/native_expert_parity.cpp - plan v0.3 P6: one native expert three ways, on real GGUF rows. 2// 3// build/native_expert_parity <shard1.gguf> [layer ...] 4// 5// (a) float reference: ggml's own dequantizer (`to_float`) and a float SwiGLU expert, (b) the CPU path 6// (ggml-cpu vec_dot with its quantized activations), (c) the GPU path (`native_expert_grouped`, q8_1 7// activations). (b) and (c) each differ from (a) by their activation rounding only (a few 1e-3 relative). 8#include "strata/artifact/gguf_reader.hpp" 9#include "strata/kernels/cpu/native_expert.hpp" 10#include "strata/kernels/cpu/expert.hpp" 11#include "strata/kernels/cpu/iq_avx512.hpp" 12#include "strata/kernels/cpu/iq_avx2.hpp" 13#include "strata/kernels/cpu/expert_layout.hpp" 14#include "ggml-cpu.h" 15#include "strata/kernels/iq_kernels.hpp" 16 17#include "ggml.h" 18 19#include <sycl/sycl.hpp> 20#include <dpct/dpct.hpp> // SYCL port: hand-ported (dpct needs ggml-cpu.h to parse this file) 21 22#include <chrono> 23#include <cmath> 24#include <cstdio> 25#include <cstdlib> 26#include <cstring> 27#include <memory> 28#include <random> 29#include <string> 30#include <vector> 31 32namespace cpu= strata::kernels::cpu; 33 34// Round 0214: --synthetic GU/DOWN ... : random weights quantized by ggml (ggml type names, e.g. iq2_xs/q5_0) in place of real 35// rows, as the CUDA/HIP tree's native_expert_parity does; the checks below are the same. 36static int type_of (std::string name ) { 37for (auto & c :name )c = (char ) std::tolower ((unsigned char )c ); 38for (int t = 0 ;t < GGML_TYPE_COUNT ;++ t ) { 39const char * n = ggml_type_name ((ggml_type )t ); 40if (n == nullptr )continue ; 41 std::string m (n ); 42for (auto & c :m )c = (char ) std::tolower ((unsigned char )c ); 43if (m == name )return t ; 44 } 45return -1 ; 46} 47 48static std::vector < uint8_t > synthetic_blob (const cpu::NativeFmt & f ,int seed ,int64_t H ,int64_t FF ) { 49 std::vector < uint8_t > blob (f .bytes ); 50 std::mt19937 rng (seed ); 51 std::normal_distribution < float > nd (0.f ,1.f ); 52auto quant = [& ](int type ,int64_t rows ,int64_t cols ,uint8_t * dst ) { 53 std::vector < float > w ((size_t ) (rows * cols )); 54for (int64_t r = 0 ;r < rows ;++ r ) { 55const float scale = 0.02f * (0.5f + (float ) (r %7 ) /7.0f ); 56for (int64_t c = 0 ;c < cols ;++ c )w [(size_t ) (r * cols + c )]= scale * nd (rng ); 57 } 58const std::vector < float > imatrix ((size_t )cols ,1.0f ); 59ggml_quantize_chunk ((ggml_type )type ,w .data (),dst ,0 ,rows ,cols , 60ggml_quantize_requires_imatrix ((ggml_type )type ) ?imatrix .data () :nullptr ); 61 }; 62quant (f .gu_type ,FF ,H ,blob .data ()); 63quant (f .gu_type ,FF ,H ,blob .data ()+ f .up_off ); 64quant (f .d_type ,H ,FF ,blob .data ()+ f .down_off ); 65return blob ; 66} 67 68static double rel (const std::vector < float >& a ,const std::vector < float >& b ) { 69double n = 0 ,d = 0 ; 70for (size_t i = 0 ;i < a .size ();++ i ) {n += std::fabs ((double )a [i ]- b [i ]);d += std::fabs ((double )b [i ]); } 71return n / (d + 1e-30 ); 72} 73 74int main (int argc ,char ** argv ) { 75setvbuf (stdout ,nullptr ,_IONBF ,0 );// keep the trail on a crash 76if (argc < 2 ) { std::fprintf (stderr ,"usage: native_expert_parity <shard1.gguf> [layer ...] | --synthetic GU/DOWN ...\n" );return 2 ; } 77const bool synthetic = std::string (argv [1 ])== "--synthetic" ; 78 std::unique_ptr < strata::GgufFile > gguf_p ; 79if (!synthetic )gguf_p .reset (new strata::GgufFile (argv [1 ])); 80 std::vector < int > layers ; 81 std::vector < std::string > pair_names ; 82for (int i = 2 ;i < argc ;++ i ) { 83if (synthetic ) {pair_names .push_back (argv [i ]);layers .push_back ((int )pair_names .size ()- 1 ); } 84else layers .push_back (std::atoi (argv [i ])); 85 } 86if (layers .empty ()&& !synthetic )layers = {0 ,1 ,2 ,3 ,20 ,47 }; 87const int NT = 3 ,E = 7 ; 88int64_t H = 2560 ,FF = 640 ;// Q4KQ_PARITY_EMBD / Q4KQ_PARITY_FF override them (Q4-KQ, as the CUDA tree's test: expert widths 512 and 1024; Q4-SYCL: the q4_* builds) 89if (const char * e = std::getenv ("Q4KQ_PARITY_EMBD" ))H = std::atoll (e ); 90if (const char * e = std::getenv ("Q4KQ_PARITY_FF" ))FF = std::atoll (e ); 91int failures = 0 ; 92 sycl::queue * s = & dpct::get_in_order_queue (); 93for (int l :layers ) { 94 cpu::NativeFmt f ; 95 std::string err ; 96 std::vector < uint8_t > blob ; 97if (synthetic ) { 98const std::string arg = pair_names [(size_t )l ]; 99const size_t slash = arg .find ('/' ); 100const int gu = slash == std::string::npos ?-1 :type_of (arg .substr (0 ,slash )); 101const int dn = slash == std::string::npos ?-1 :type_of (arg .substr (slash + 1 )); 102if (gu < 0 || dn < 0 || !cpu::native_fmt (gu ,dn ,H ,FF ,f ,err )|| 103 !strata::kernels::native_expert_supported (gu ,dn ,H ,FF )) { 104 std::printf ("%s: %s\n" ,arg .c_str (),err .empty () ?"not a pair the GPU expert kernels take" :err .c_str ()); 105++ failures ; 106continue ; 107 } 108blob = synthetic_blob (f ,l ,H ,FF ); 109 }else { 110 strata::GgufFile & gguf = * gguf_p ; 111const strata::TensorInfo * t [3 ]= {}; 112const char * roles [3 ]= {"gate" ,"up" ,"down" }; 113for (const auto & ti :gguf .tensors ()) 114for (int r = 0 ;r < 3 ;++ r ) 115if (ti .name == "blk." + std::to_string (l )+ ".ffn_" + roles [r ]+ "_exps.weight" )t [r ]= & ti ; 116if (!t [0 ]|| !t [1 ]|| !t [2 ]) { std::printf ("layer %d: no expert tensors\n" ,l );++ failures ;continue ; } 117if (!cpu::native_fmt ((int )t [0 ]-> type , (int )t [2 ]-> type ,H ,FF ,f ,err )) { 118 std::printf ("layer %d: %s\n" ,l ,err .c_str ());++ failures ;continue ; 119 } 120blob .resize (f .bytes ); 121 std::memcpy (blob .data (),gguf .tensor_data (* t [0 ])+ (size_t )E * f .up_off ,f .up_off ); 122 std::memcpy (blob .data ()+ f .up_off ,gguf .tensor_data (* t [1 ])+ (size_t )E * f .up_off ,f .up_off ); 123 std::memcpy (blob .data ()+ f .down_off ,gguf .tensor_data (* t [2 ])+ (size_t )E * (f .bytes - f .down_off ), 124f .bytes - f .down_off ); 125 } 126// (a) the float reference 127const auto * tg = ggml_get_type_traits ((ggml_type )f .gu_type ); 128const auto * td = ggml_get_type_traits ((ggml_type )f .d_type ); 129 std::vector < float > G ((size_t )FF * H ),U ((size_t )FF * H ),D ((size_t )H * FF ); 130for (int64_t r = 0 ;r < FF ;++ r ) { 131tg -> to_float (blob .data ()+ r * f .gu_row ,G .data ()+ r * H ,H ); 132tg -> to_float (blob .data ()+ f .up_off + r * f .gu_row ,U .data ()+ r * H ,H ); 133 } 134for (int64_t r = 0 ;r < H ;++ r )td -> to_float (blob .data ()+ f .down_off + r * f .d_row ,D .data ()+ r * FF ,FF ); 135 std::mt19937 rng (11 + l ); 136 std::normal_distribution < float > nd (0.f ,1.f ); 137 std::vector < float > x ((size_t )NT * H ); 138for (auto & v :x )v = nd (rng ); 139 std::vector < float > ref ((size_t )NT * H ),got_c ((size_t )NT * H ),got_g ((size_t )NT * H ); 140for (int k = 0 ;k < NT ;++ k ) { 141 std::vector < float > h (FF ); 142for (int64_t r = 0 ;r < FF ;++ r ) { 143double g = 0 ,u = 0 ; 144for (int64_t i = 0 ;i < H ;++ i ) {g += (double )G [r * H + i ]* x [k * H + i ];u += (double )U [r * H + i ]* x [k * H + i ]; } 145h [r ]= (float ) (g / (1.0 + std::exp (- g ))* u ); 146 } 147for (int64_t r = 0 ;r < H ;++ r ) { 148double o = 0 ; 149for (int64_t i = 0 ;i < FF ;++ i )o += (double )D [r * FF + i ]* h [i ]; 150ref [k * H + r ]= (float )o ; 151 } 152 } 153// (b) the CPU 154 { 155 std::vector < std::vector < uint8_t >> act (NT , std::vector < uint8_t > (cpu::kNativeActBytes )); 156 std::vector < std::vector < uint8_t >> hq (NT , std::vector < uint8_t > (cpu::kNativeHBytes )); 157 std::vector < std::vector < float >> ff (NT , std::vector < float > (FF )); 158const void * a [NT ]; 159float * ffp [NT ]; 160const void * hp [NT ]; 161float * op [NT ]; 162for (int k = 0 ;k < NT ;++ k ) { 163 cpu::native_quant_act (f ,x .data ()+ k * H ,act [k ].data ()); 164a [k ]= act [k ].data (); 165ffp [k ]= ff [k ].data (); 166 } 167 cpu::native_gu_rows (f ,blob .data (),a ,NT ,ffp ,0 , (int )FF ); 168if (cpu::iq512_supported (f .gu_type )) { 169// ggml's own vec_dot, same Q8_K activations: the reference for both multi-token kernels 170// (float-order differences only) 171const auto * tc = ggml_get_type_traits_cpu ((ggml_type )f .gu_type ); 172 std::vector < float > gref ((size_t )NT * FF ); 173for (int k = 0 ;k < NT ;++ k ) 174for (int64_t r = 0 ;r < FF ;++ r ) 175tc -> vec_dot ((int )H ,& gref [k * FF + r ],0 ,blob .data ()+ r * f .gu_row ,0 ,a [k ],0 ,1 ); 176double usg = 0.0 ; 177 {// ggml single-token throughput, the weights cache-resident (compute bound) 178const int it = 50 ; 179auto t0 = std::chrono::steady_clock::now (); 180for (int i = 0 ;i < it ;++ i ) 181for (int64_t r = 0 ;r < FF ;++ r ) { 182float gg ,uu ; 183tc -> vec_dot ((int )H ,& gg ,0 ,blob .data ()+ r * f .gu_row ,0 ,a [0 ],0 ,1 ); 184tc -> vec_dot ((int )H ,& uu ,0 ,blob .data ()+ f .up_off + r * f .gu_row ,0 ,a [0 ],0 ,1 ); 185 } 186auto t1 = std::chrono::steady_clock::now (); 187usg = std::chrono::duration < double , std::micro > (t1 - t0 ).count () /it ; 188 } 189// one multi-token kernel: parity against ggml's vec_dot, then one-token and NT-token throughput 190auto check = [& ](const char * tag ,bool is512 ) { 191 std::vector < float > g ((size_t )NT * FF ); 192float * gp [NT ]; 193for (int k = 0 ;k < NT ;++ k )gp [k ]= g .data ()+ k * FF ; 194 (is512 ? cpu::iq512_rows : cpu::iq256_rows )(f .gu_type ,blob .data (),f .gu_row , (int )H ,a ,NT ,gp ,0 , (int )FF ); 195const double rg = rel (g ,gref ); 196 std::printf (" %s %s gate rows vs ggml vec_dot: rel %.2e\n" , 197ggml_type_name ((ggml_type )f .gu_type ),tag ,rg ); 198if (rg > 1e-5 ) {// ggml's own vec_dot is the reference: above 1e-5 it is a real mismatch, 199 std::printf (" %s %s gate rows MISMATCH (rel %.2e > 1e-5)\n" , 200ggml_type_name ((ggml_type )f .gu_type ),tag ,rg );// not rounding (measured 3e-8) 201++ failures ; 202 } 203float * f1 [1 ]= {ffp [0 ]}; 204const int it = 50 ; 205const auto gu = is512 ? cpu::iq512_gu_rows : cpu::iq256_gu_rows ; 206auto t0 = std::chrono::steady_clock::now (); 207for (int i = 0 ;i < it ;++ i )gu (f .gu_type ,blob .data (),f .gu_row ,f .up_off , (int )H ,a ,1 ,f1 ,0 , (int )FF ); 208auto t1 = std::chrono::steady_clock::now (); 209for (int i = 0 ;i < it ;++ i )gu (f .gu_type ,blob .data (),f .gu_row ,f .up_off , (int )H ,a ,NT ,ffp ,0 , (int )FF ); 210auto t2 = std::chrono::steady_clock::now (); 211const double us1 = std::chrono::duration < double , std::micro > (t1 - t0 ).count () /it ; 212const double usn = std::chrono::duration < double , std::micro > (t2 - t1 ).count () /it ; 213 std::printf (" gate+up one token one thread: %s %.0f us (%.2f GB/s), ggml %.0f us (%.2f GB/s)\n" , 214tag ,us1 ,2.0 * f .up_off /us1 /1e3 ,usg ,2.0 * f .up_off /usg /1e3 ); 215 std::printf (" gate+up %d tokens one thread: %s %.0f us vs ggml %d x %.0f us\n" ,NT ,tag ,usn ,NT ,usg ); 216 }; 217if (cpu::cpu_avx512_ok ())check ("avx512" , true);// guarded: the binary runs on AVX-2 CPUs too 218check ("avx2" , false); 219 } 220for (int k = 0 ;k < NT ;++ k ) { 221 cpu::native_quant_h (f ,ff [k ].data (),hq [k ].data ()); 222hp [k ]= hq [k ].data (); 223op [k ]= got_c .data ()+ k * H ; 224 } 225 cpu::native_down_rows (f ,blob .data (),hp ,NT ,op ,0 , (int )H ); 226if (f .d_type == 42 ) { 227// (b2) the GGUF-layout Q2_0 kernel the pool uses for Q2_0 down projections - the AVX-512 one 228// where the CPU has it, the AVX-2 one (q2_avx2.cpp) where it does not. Calling the AVX-512 229// kernel unconditionally faults on a Zen 2/3 CPU. 230 std::vector < cpu::ActQ > a2 (NT ); 231const cpu::ActQ * ap [NT ]; 232 std::vector < float > alt ((size_t )NT * H ); 233float * altp [NT ]; 234for (int k = 0 ;k < NT ;++ k ) { 235 cpu::act_quant_any (ff [k ].data (), (int )FF ,a2 [k ]);// gated: AVX-512 or AVX-2 per CPU 236ap [k ]= & a2 [k ]; 237altp [k ]= alt .data ()+ k * H ; 238 } 239 cpu::q2_rows_any (blob .data ()+ f .down_off ,f .d_row , (int ) (FF /64 ),ap ,NT ,altp ,0 , (int )H ); 240 std::printf (" q2_0 %s down vs ggml down: rel %.2e\n" , 241 cpu::cpu_avx512_ok () ?"AVX-512" :"AVX-2" ,rel (alt ,got_c )); 242 } 243if (f .d_type == 20 ) { 244// (b3) the IQ4_NL multi-token AVX-2 kernel the pool now uses for IQ4_NL down projections, 245// against ggml-cpu's single-token vec_dot on the SAME Q8_0 activations (h), plus timing. 246 std::vector < float > alt ((size_t )NT * H ),refd ((size_t )NT * H ); 247float * altp [NT ]; 248for (int k = 0 ;k < NT ;++ k )altp [k ]= alt .data ()+ k * H ; 249 cpu::iq4nl256_down_rows (blob .data ()+ f .down_off ,f .d_row , (int )FF ,hp ,NT ,altp ,0 , (int )H ); 250const auto * tdc = ggml_get_type_traits_cpu ((ggml_type )f .d_type ); 251for (int k = 0 ;k < NT ;++ k ) 252for (int64_t r = 0 ;r < H ;++ r ) 253tdc -> vec_dot ((int )FF ,refd .data ()+ k * H + r ,0 , 254blob .data ()+ f .down_off + (size_t )r * f .d_row ,0 ,hp [k ],0 ,1 ); 255const double rdn = rel (alt ,refd ); 256 std::printf (" iq4_nl AVX-2 multi-token down vs ggml down: rel %.2e\n" ,rdn ); 257if (rdn > 1e-5 ) {// measured 1e-7; same reasoning as the gate/up rows above 258 std::printf (" iq4_nl down MISMATCH (rel %.2e > 1e-5)\n" ,rdn ); 259++ failures ; 260 } 261const int it = 50 ; 262const auto t0 = std::chrono::steady_clock::now (); 263for (int i = 0 ;i < it ;++ i ) 264 cpu::iq4nl256_down_rows (blob .data ()+ f .down_off ,f .d_row , (int )FF ,hp ,NT ,altp ,0 , (int )H ); 265const auto t1 = std::chrono::steady_clock::now (); 266for (int i = 0 ;i < it ;++ i ) 267for (int k = 0 ;k < NT ;++ k ) 268for (int64_t r = 0 ;r < H ;++ r ) 269tdc -> vec_dot ((int )FF ,refd .data ()+ k * H + r ,0 , 270blob .data ()+ f .down_off + (size_t )r * f .d_row ,0 ,hp [k ],0 ,1 ); 271const auto t2 = std::chrono::steady_clock::now (); 272const double usn = std::chrono::duration < double , std::micro > (t1 - t0 ).count () /it ; 273const double usg = std::chrono::duration < double , std::micro > (t2 - t1 ).count () /it ; 274 std::printf (" down %d tokens one thread: avx2 %.0f us (%.2f GB/s) vs ggml %.0f us (%.2f GB/s)\n" , 275NT ,usn , (double ) (f .bytes - f .down_off ) /usn /1e3 ,usg , 276 (double ) (f .bytes - f .down_off ) /usg /1e3 ); 277 } 278 } 279// (c) the GPU: one group holding the NT entries 280 { 281const auto L = strata::kernels::native_expert_layout (f .gu_type ,f .d_type ,H ,FF ); 282void * dblob ,* dx ,* dxq ,* dscr ; 283float * dout ; 284unsigned long long * dptr ; 285int32_t * dstart ,* dn ,* ddst ,* dtok ; 286dblob = (decltype(dblob )) sycl::malloc_device (blob .size (),* s ); 287dx = (decltype(dx )) sycl::malloc_device (x .size ()* 4 ,* s ); 288dxq = (decltype(dxq )) sycl::malloc_device ((size_t )NT * H /32 * 36 ,* s ); 289dscr = (decltype(dscr )) sycl::malloc_device (strata::kernels::native_expert_scratch_bytes (NT ,FF ),* s ); 290dout = (decltype(dout )) sycl::malloc_device ((size_t )NT * H * 4 ,* s ); 291dptr = (decltype(dptr )) sycl::malloc_device (8 ,* s ); 292dstart = (decltype(dstart )) sycl::malloc_device (8 ,* s ); 293dn = (decltype(dn )) sycl::malloc_device (4 ,* s ); 294ddst = (decltype(ddst )) sycl::malloc_device (NT * 4 ,* s ); 295dtok = (decltype(dtok )) sycl::malloc_device (NT * 4 ,* s ); 296s -> memcpy (dblob ,blob .data (),blob .size ()).wait (); 297s -> memcpy (dx ,x .data (),x .size ()* 4 ).wait (); 298const unsigned long long p = (unsigned long long )dblob ; 299const int32_t st [2 ]= {0 ,NT },one = 1 ,idx [NT ]= {0 ,1 ,2 }; 300s -> memcpy (dptr ,& p ,8 ).wait (); 301s -> memcpy (dstart ,st ,8 ).wait (); 302s -> memcpy (dn ,& one ,4 ).wait (); 303s -> memcpy (ddst ,idx ,NT * 4 ).wait (); 304s -> memcpy (dtok ,idx ,NT * 4 ).wait (); 305 strata::kernels::quantize_q8_1_rows ((const float * )dx ,NT ,H ,dxq ,s ); 306 strata::kernels::native_expert_grouped (L ,dptr ,dstart ,dn ,ddst ,dtok ,1 ,NT ,dxq ,dscr ,dout ,s ); 307s -> wait (); 308s -> memcpy (got_g .data (),dout ,got_g .size ()* 4 ).wait (); 309if (std::getenv ("NATIVE_BENCH" )!= nullptr ) {// SYCL port: one layer's worth of hits, timed 310// G distinct experts (copies of this blob at different addresses), E entries each = a T-token window 311const int G = 10 ,E = 4 ,NE = G * E ,iters = 20 ; 312 std::vector < void *> blobs ((size_t )G ); 313 std::vector < unsigned long long > ptrs ((size_t )G ); 314for (int g = 0 ;g < G ;++ g ) { 315blobs [(size_t )g ]= sycl::malloc_device (blob .size (),* s ); 316s -> memcpy (blobs [(size_t )g ],blob .data (),blob .size ()).wait (); 317ptrs [(size_t )g ]= (unsigned long long )blobs [(size_t )g ]; 318 } 319 std::vector < int32_t > starts ((size_t )G + 1 ),dst ((size_t )NE ),tokv ((size_t )NE ); 320for (int g = 0 ;g <=G ;++ g )starts [(size_t )g ]= g * E ; 321for (int e = 0 ;e < NE ;++ e ) {dst [(size_t )e ]= e ;tokv [(size_t )e ]= e %NT ; } 322unsigned long long * bptr = sycl::malloc_device < unsigned long long > ((size_t )G ,* s ); 323int32_t * bstart = sycl::malloc_device < int32_t > ((size_t )G + 1 ,* s ); 324int32_t * bn = sycl::malloc_device < int32_t > (1 ,* s ); 325int32_t * bdst = sycl::malloc_device < int32_t > ((size_t )NE ,* s ); 326int32_t * btok = sycl::malloc_device < int32_t > ((size_t )NE ,* s ); 327void * bscr = sycl::malloc_device (strata::kernels::native_expert_scratch_bytes (NE ,FF ),* s ); 328float * bout = sycl::malloc_device < float > ((size_t )NE * H ,* s ); 329const int32_t gn = G ; 330s -> memcpy (bptr ,ptrs .data (), (size_t )G * 8 ).wait (); 331s -> memcpy (bstart ,starts .data (), ((size_t )G + 1 )* 4 ).wait (); 332s -> memcpy (bn ,& gn ,4 ).wait (); 333s -> memcpy (bdst ,dst .data (), (size_t )NE * 4 ).wait (); 334s -> memcpy (btok ,tokv .data (), (size_t )NE * 4 ).wait (); 335 strata::kernels::native_expert_grouped (L ,bptr ,bstart ,bn ,bdst ,btok ,G ,NE ,dxq ,bscr ,bout ,s ); 336s -> wait (); 337const auto b0 = std::chrono::steady_clock::now (); 338for (int i = 0 ;i < iters ;++ i ) 339 strata::kernels::native_expert_grouped (L ,bptr ,bstart ,bn ,bdst ,btok ,G ,NE ,dxq ,bscr ,bout ,s ); 340s -> wait (); 341const double ms = std::chrono::duration < double , std::milli > (std::chrono::steady_clock::now ()- b0 ).count () /iters ; 342 std::printf (" GPU grouped: %d experts x %d entries: %.3f ms per layer call (%.1f GB/s of expert bytes)\n" , 343G ,E ,ms , (double )G * (double )blob .size () /ms /1e6 ); 344for (int g = 0 ;g < G ;++ g ) sycl::free (blobs [(size_t )g ],* s ); 345 sycl::free (bptr ,* s ); sycl::free (bstart ,* s ); sycl::free (bn ,* s ); sycl::free (bdst ,* s ); sycl::free (btok ,* s ); 346 sycl::free (bscr ,* s ); sycl::free (bout ,* s ); 347 } 348 sycl::free (dblob ,* s ); sycl::free (dx ,* s ); sycl::free (dxq ,* s ); sycl::free (dscr ,* s ); sycl::free (dout ,* s ); sycl::free (dptr ,* s ); 349 sycl::free (dstart ,* s ); sycl::free (dn ,* s ); sycl::free (ddst ,* s ); sycl::free (dtok ,* s ); 350 } 351const double ec = rel (got_c ,ref ),eg = rel (got_g ,ref ),ecg = rel (got_c ,got_g ); 352const double gpu_limit = f .d_type == 6 ?1.8e-2 :3e-2 ;// Q5_0 down: the quantized-sum offset (round 0214) makes it as accurate as the rest 353const bool ok = ec < 3e-2 && eg < gpu_limit && std::isfinite (ec )&& std::isfinite (eg ); 354 std::printf ("%s %2d %-8s/%-7s blob %8zu cpu rel %.2e gpu rel %.2e cpu-gpu %.2e %s\n" ,synthetic ?"pair " :"layer" ,l , 355ggml_type_name ((ggml_type )f .gu_type ),ggml_type_name ((ggml_type )f .d_type ),f .bytes ,ec ,eg ,ecg , 356ok ?"ok" :"FAIL" ); 357if (!ok )++ failures ; 358 } 359 std::printf ("native_expert_parity: %d failures\n" ,failures ); 360return failures ?1 :0 ; 361}