@@ -22,11 +22,20 @@ static_assert(sizeof(block_q4_1) == sizeof(float) * 2 + QK4_1 / 2, "wrong q4_1 b
22
22
23
23
#define QK4_2 16
24
24
typedef struct {
25
- __half d; // delta
25
+ __half d; // delta
26
26
uint8_t qs[QK4_2 / 2 ]; // nibbles / quants
27
27
} block_q4_2;
28
28
static_assert (sizeof (block_q4_2) == sizeof(ggml_fp16_t ) + QK4_2 / 2, "wrong q4_2 block size/padding");
29
29
30
+ #define QK4_3 16
31
+ typedef struct {
32
+ __half d; // delta
33
+ __half m; // min
34
+ uint8_t qs[QK4_3 / 2 ]; // nibbles / quants
35
+ } block_q4_3;
36
+ static_assert (sizeof (block_q4_3) == 2 * sizeof(ggml_fp16_t ) + QK4_3 / 2, "wrong q4_3 block size/padding");
37
+
38
+
30
39
31
40
static __global__ void dequantize_block_q4_0 (const void * vx, float * y) {
32
41
const block_q4_0 * x = (const block_q4_0 *) vx;
@@ -98,6 +107,30 @@ static __global__ void dequantize_block_q4_2(const void * vx, float * y) {
98
107
}
99
108
}
100
109
110
+ static __global__ void dequantize_block_q4_3 (const void * vx, float * y) {
111
+ const block_q4_3 * x = (const block_q4_3 *) vx;
112
+
113
+ const int i = blockIdx .x ;
114
+
115
+ const float d = x[i].d ;
116
+ const float m = x[i].m ;
117
+
118
+ const uint8_t * pp = x[i].qs ;
119
+
120
+ for (int l = 0 ; l < QK4_3; l += 2 ) {
121
+ const uint8_t vi = pp[l/2 ];
122
+
123
+ const int8_t vi0 = vi & 0xf ;
124
+ const int8_t vi1 = vi >> 4 ;
125
+
126
+ const float v0 = vi0*d + m;
127
+ const float v1 = vi1*d + m;
128
+
129
+ y[i*QK4_3 + l + 0 ] = v0;
130
+ y[i*QK4_3 + l + 1 ] = v1;
131
+ }
132
+ }
133
+
101
134
extern " C" {
102
135
__host__ void dequantize_row_q4_0_cuda (const void * vx, float * y, int k, cudaStream_t stream) {
103
136
const int nb = k / QK4_0;
@@ -113,4 +146,9 @@ extern "C" {
113
146
const int nb = k / QK4_2;
114
147
dequantize_block_q4_2<<<nb, 1 , 0 , stream>>> (vx, y);
115
148
}
149
+
150
+ __host__ void dequantize_row_q4_3_cuda (const void * vx, float * y, int k, cudaStream_t stream) {
151
+ const int nb = k / QK4_3;
152
+ dequantize_block_q4_3<<<nb, 1 , 0 , stream>>> (vx, y);
153
+ }
116
154
}
0 commit comments