@@ -108,6 +108,32 @@ void quantize_row_tq2_0(const float * GGML_RESTRICT x, void * GGML_RESTRICT vy,
108108 quantize_row_tq2_0_ref (x , y , k );
109109}
110110
111+ // ====================== TurboQuant (TBQ) quantization ========================
112+
113+ void quantize_row_tbq3_0 (const float * GGML_RESTRICT x , void * GGML_RESTRICT vy , int64_t k ) {
114+ assert (k % QK_K == 0 );
115+ block_tbq3_0 * GGML_RESTRICT y = vy ;
116+ quantize_row_tbq3_0_ref (x , y , k );
117+ }
118+
119+ void quantize_row_tbq4_0 (const float * GGML_RESTRICT x , void * GGML_RESTRICT vy , int64_t k ) {
120+ assert (k % QK_K == 0 );
121+ block_tbq4_0 * GGML_RESTRICT y = vy ;
122+ quantize_row_tbq4_0_ref (x , y , k );
123+ }
124+
125+ void quantize_row_tbqp3_0 (const float * GGML_RESTRICT x , void * GGML_RESTRICT vy , int64_t k ) {
126+ assert (k % QK_K == 0 );
127+ block_tbqp3_0 * GGML_RESTRICT y = vy ;
128+ quantize_row_tbqp3_0_ref (x , y , k );
129+ }
130+
131+ void quantize_row_tbqp4_0 (const float * GGML_RESTRICT x , void * GGML_RESTRICT vy , int64_t k ) {
132+ assert (k % QK_K == 0 );
133+ block_tbqp4_0 * GGML_RESTRICT y = vy ;
134+ quantize_row_tbqp4_0_ref (x , y , k );
135+ }
136+
111137//===================================== Q8_K ==============================================
112138
113139void quantize_row_q8_K_generic (const float * GGML_RESTRICT x , void * GGML_RESTRICT y , int64_t k ) {
@@ -456,6 +482,120 @@ void ggml_vec_dot_tq2_0_q8_K_generic(int n, float * GGML_RESTRICT s, size_t bs,
456482 * s = sumf ;
457483}
458484
485+ // ====================== TurboQuant vec_dot (dequant-then-dot reference) ===========
486+ //
487+ // These implementations dequantize the TBQ row to float, then compute the dot
488+ // product with the Q8_K dequantized row. This is the correctness-first approach.
489+
490+ void ggml_vec_dot_tbq3_0_q8_K_generic (int n , float * GGML_RESTRICT s , size_t bs , const void * GGML_RESTRICT vx , size_t bx , const void * GGML_RESTRICT vy , size_t by , int nrc ) {
491+ assert (nrc == 1 );
492+ UNUSED (nrc );
493+ UNUSED (bx );
494+ UNUSED (by );
495+ UNUSED (bs );
496+
497+ // Dequantize TBQ3 to float, then dot with dequantized Q8_K
498+ float * tmp = (float * )malloc (n * sizeof (float ));
499+ dequantize_row_tbq3_0 ((const block_tbq3_0 * )vx , tmp , n );
500+
501+ const block_q8_K * GGML_RESTRICT y = vy ;
502+ const int nb = n / QK_K ;
503+
504+ float sumf = 0.0f ;
505+ int64_t idx = 0 ;
506+ for (int i = 0 ; i < nb ; i ++ ) {
507+ const float d = y [i ].d ;
508+ for (int j = 0 ; j < QK_K ; j ++ ) {
509+ sumf += tmp [idx ] * (d * y [i ].qs [j ]);
510+ idx ++ ;
511+ }
512+ }
513+
514+ free (tmp );
515+ * s = sumf ;
516+ }
517+
518+ void ggml_vec_dot_tbq4_0_q8_K_generic (int n , float * GGML_RESTRICT s , size_t bs , const void * GGML_RESTRICT vx , size_t bx , const void * GGML_RESTRICT vy , size_t by , int nrc ) {
519+ assert (nrc == 1 );
520+ UNUSED (nrc );
521+ UNUSED (bx );
522+ UNUSED (by );
523+ UNUSED (bs );
524+
525+ float * tmp = (float * )malloc (n * sizeof (float ));
526+ dequantize_row_tbq4_0 ((const block_tbq4_0 * )vx , tmp , n );
527+
528+ const block_q8_K * GGML_RESTRICT y = vy ;
529+ const int nb = n / QK_K ;
530+
531+ float sumf = 0.0f ;
532+ int64_t idx = 0 ;
533+ for (int i = 0 ; i < nb ; i ++ ) {
534+ const float d = y [i ].d ;
535+ for (int j = 0 ; j < QK_K ; j ++ ) {
536+ sumf += tmp [idx ] * (d * y [i ].qs [j ]);
537+ idx ++ ;
538+ }
539+ }
540+
541+ free (tmp );
542+ * s = sumf ;
543+ }
544+
545+ void ggml_vec_dot_tbqp3_0_q8_K_generic (int n , float * GGML_RESTRICT s , size_t bs , const void * GGML_RESTRICT vx , size_t bx , const void * GGML_RESTRICT vy , size_t by , int nrc ) {
546+ assert (nrc == 1 );
547+ UNUSED (nrc );
548+ UNUSED (bx );
549+ UNUSED (by );
550+ UNUSED (bs );
551+
552+ float * tmp = (float * )malloc (n * sizeof (float ));
553+ dequantize_row_tbqp3_0 ((const block_tbqp3_0 * )vx , tmp , n );
554+
555+ const block_q8_K * GGML_RESTRICT y = vy ;
556+ const int nb = n / QK_K ;
557+
558+ float sumf = 0.0f ;
559+ int64_t idx = 0 ;
560+ for (int i = 0 ; i < nb ; i ++ ) {
561+ const float d = y [i ].d ;
562+ for (int j = 0 ; j < QK_K ; j ++ ) {
563+ sumf += tmp [idx ] * (d * y [i ].qs [j ]);
564+ idx ++ ;
565+ }
566+ }
567+
568+ free (tmp );
569+ * s = sumf ;
570+ }
571+
572+ void ggml_vec_dot_tbqp4_0_q8_K_generic (int n , float * GGML_RESTRICT s , size_t bs , const void * GGML_RESTRICT vx , size_t bx , const void * GGML_RESTRICT vy , size_t by , int nrc ) {
573+ assert (nrc == 1 );
574+ UNUSED (nrc );
575+ UNUSED (bx );
576+ UNUSED (by );
577+ UNUSED (bs );
578+
579+ float * tmp = (float * )malloc (n * sizeof (float ));
580+ dequantize_row_tbqp4_0 ((const block_tbqp4_0 * )vx , tmp , n );
581+
582+ const block_q8_K * GGML_RESTRICT y = vy ;
583+ const int nb = n / QK_K ;
584+
585+ float sumf = 0.0f ;
586+ int64_t idx = 0 ;
587+ for (int i = 0 ; i < nb ; i ++ ) {
588+ const float d = y [i ].d ;
589+ for (int j = 0 ; j < QK_K ; j ++ ) {
590+ sumf += tmp [idx ] * (d * y [i ].qs [j ]);
591+ idx ++ ;
592+ }
593+ }
594+
595+ free (tmp );
596+ * s = sumf ;
597+ }
598+
459599void ggml_vec_dot_q2_K_q8_K_generic (int n , float * GGML_RESTRICT s , size_t bs , const void * GGML_RESTRICT vx , size_t bx , const void * GGML_RESTRICT vy , size_t by , int nrc ) {
460600 assert (nrc == 1 );
461601 UNUSED (nrc );
0 commit comments