@@ -60,24 +60,95 @@ typedef sycl::half2 ggml_half2;
60
60
#define static_assert (cond, msg ) struct global_scope_noop_trick
61
61
#endif
62
62
#endif
63
- #endif
63
+ #endif // __cplusplus
64
64
65
65
// QK = number of values after dequantization
66
+ // QK_K = super-block size
67
+
68
+ #ifdef GGML_QKK_64
69
+ #define QK_K 64
70
+ #define K_SCALE_SIZE 4
71
+ #else
72
+ #define QK_K 256
73
+ #define K_SCALE_SIZE 12
74
+ #endif // GGML_QKK_64
75
+
76
+ #if defined(GGML_COMMON_DECL_CUDA) || defined(GGML_COMMON_DECL_HIP)
66
77
// QR = QK / number of values before dequantization
67
78
// QI = number of 32 bit integers before dequantization
68
79
69
- #define QK4_0 32
70
80
#define QI4_0 (QK4_0 / (4 * QR4_0))
71
81
#define QR4_0 2
82
+
83
+ #define QI4_1 (QK4_1 / (4 * QR4_1))
84
+ #define QR4_1 2
85
+
86
+ #define QI5_0 (QK5_0 / (4 * QR5_0))
87
+ #define QR5_0 2
88
+
89
+ #define QI5_1 (QK5_1 / (4 * QR5_1))
90
+ #define QR5_1 2
91
+
92
+ #define QI8_0 (QK8_0 / (4 * QR8_0))
93
+ #define QR8_0 1
94
+
95
+ #define QI8_1 (QK8_1 / (4 * QR8_1))
96
+ #define QR8_1 1
97
+
98
+ #define QI2_K (QK_K / (4 *QR2_K))
99
+ #define QR2_K 4
100
+
101
+ #define QI3_K (QK_K / (4 *QR3_K))
102
+ #define QR3_K 4
103
+
104
+ #define QI4_K (QK_K / (4 *QR4_K))
105
+ #define QR4_K 2
106
+
107
+ #define QI5_K (QK_K / (4 *QR5_K))
108
+ #define QR5_K 2
109
+
110
+ #define QI6_K (QK_K / (4 *QR6_K))
111
+ #define QR6_K 2
112
+
113
+ #define QI2_XXS (QK_K / (4 *QR2_XXS))
114
+ #define QR2_XXS 8
115
+
116
+ #define QI2_XS (QK_K / (4 *QR2_XS))
117
+ #define QR2_XS 8
118
+
119
+ #define QI2_S (QK_K / (4 *QR2_S))
120
+ #define QR2_S 8
121
+
122
+ #define QI3_XXS (QK_K / (4 *QR3_XXS))
123
+ #define QR3_XXS 8
124
+
125
+ #define QI3_XS (QK_K / (4 *QR3_XS))
126
+ #define QR3_XS 8
127
+
128
+ #define QI1_S (QK_K / (4 *QR1_S))
129
+ #define QR1_S 8
130
+
131
+ #define QI4_NL (QK4_NL / (4 *QR4_NL))
132
+ #define QR4_NL 2
133
+
134
+ #if QK_K == 64
135
+ #define QI4_XS QI4_NL
136
+ #define QR4_XS QR4_NL
137
+ #else
138
+ #define QI4_XS (QK_K / (4 *QR4_XS))
139
+ #define QR4_XS 8
140
+ #endif
141
+
142
+ #endif // GGML_COMMON_DECL_CUDA || GGML_COMMON_DECL_HIP
143
+
144
+ #define QK4_0 32
72
145
typedef struct {
73
146
ggml_half d; // delta
74
147
uint8_t qs[QK4_0 / 2 ]; // nibbles / quants
75
148
} block_q4_0;
76
149
static_assert (sizeof (block_q4_0) == sizeof(ggml_half) + QK4_0 / 2, "wrong q4_0 block size/padding");
77
150
78
151
#define QK4_1 32
79
- #define QI4_1 (QK4_1 / (4 * QR4_1))
80
- #define QR4_1 2
81
152
typedef struct {
82
153
union {
83
154
struct {
@@ -91,8 +162,6 @@ typedef struct {
91
162
static_assert (sizeof (block_q4_1) == 2 * sizeof(ggml_half) + QK4_1 / 2, "wrong q4_1 block size/padding");
92
163
93
164
#define QK5_0 32
94
- #define QI5_0 (QK5_0 / (4 * QR5_0))
95
- #define QR5_0 2
96
165
typedef struct {
97
166
ggml_half d; // delta
98
167
uint8_t qh[4 ]; // 5-th bit of quants
@@ -101,8 +170,6 @@ typedef struct {
101
170
static_assert (sizeof (block_q5_0) == sizeof(ggml_half) + sizeof(uint32_t ) + QK5_0 / 2, "wrong q5_0 block size/padding");
102
171
103
172
#define QK5_1 32
104
- #define QI5_1 (QK5_1 / (4 * QR5_1))
105
- #define QR5_1 2
106
173
typedef struct {
107
174
union {
108
175
struct {
@@ -117,17 +184,13 @@ typedef struct {
117
184
static_assert (sizeof (block_q5_1) == 2 * sizeof(ggml_half) + sizeof(uint32_t ) + QK5_1 / 2, "wrong q5_1 block size/padding");
118
185
119
186
#define QK8_0 32
120
- #define QI8_0 (QK8_0 / (4 * QR8_0))
121
- #define QR8_0 1
122
187
typedef struct {
123
188
ggml_half d; // delta
124
189
int8_t qs[QK8_0]; // quants
125
190
} block_q8_0;
126
191
static_assert (sizeof (block_q8_0) == sizeof(ggml_half) + QK8_0, "wrong q8_0 block size/padding");
127
192
128
193
#define QK8_1 32
129
- #define QI8_1 (QK8_1 / (4 * QR8_1))
130
- #define QR8_1 1
131
194
typedef struct {
132
195
union {
133
196
struct {
@@ -144,21 +207,10 @@ static_assert(sizeof(block_q8_1) == 2*sizeof(ggml_half) + QK8_1, "wrong q8_1 blo
144
207
// Super-block quantization structures
145
208
//
146
209
147
- // Super-block size
148
- #ifdef GGML_QKK_64
149
- #define QK_K 64
150
- #define K_SCALE_SIZE 4
151
- #else
152
- #define QK_K 256
153
- #define K_SCALE_SIZE 12
154
- #endif
155
-
156
210
// 2-bit quantization
157
211
// weight is represented as x = a * q + b
158
212
// 16 blocks of 16 elements each
159
213
// Effectively 2.625 bits per weight
160
- #define QI2_K (QK_K / (4 *QR2_K))
161
- #define QR2_K 4
162
214
typedef struct {
163
215
uint8_t scales[QK_K/16 ]; // scales and mins, quantized with 4 bits
164
216
uint8_t qs[QK_K/4 ]; // quants
@@ -176,8 +228,6 @@ static_assert(sizeof(block_q2_K) == 2*sizeof(ggml_half) + QK_K/16 + QK_K/4, "wro
176
228
// weight is represented as x = a * q
177
229
// 16 blocks of 16 elements each
178
230
// Effectively 3.4375 bits per weight
179
- #define QI3_K (QK_K / (4 *QR3_K))
180
- #define QR3_K 4
181
231
#ifdef GGML_QKK_64
182
232
typedef struct {
183
233
uint8_t hmask[QK_K/8 ]; // quants - high bit
@@ -200,8 +250,6 @@ static_assert(sizeof(block_q3_K) == sizeof(ggml_half) + QK_K / 4 + QK_K / 8 + 12
200
250
// 8 blocks of 32 elements each
201
251
// weight is represented as x = a * q + b
202
252
// Effectively 4.5 bits per weight
203
- #define QI4_K (QK_K / (4 *QR4_K))
204
- #define QR4_K 2
205
253
#ifdef GGML_QKK_64
206
254
typedef struct {
207
255
ggml_half d[2 ]; // super-block scales/mins
@@ -228,8 +276,6 @@ static_assert(sizeof(block_q4_K) == 2*sizeof(ggml_half) + K_SCALE_SIZE + QK_K/2,
228
276
// 8 blocks of 32 elements each
229
277
// weight is represented as x = a * q + b
230
278
// Effectively 5.5 bits per weight
231
- #define QI5_K (QK_K / (4 *QR5_K))
232
- #define QR5_K 2
233
279
#ifdef GGML_QKK_64
234
280
typedef struct {
235
281
ggml_half d; // super-block scale
@@ -258,8 +304,6 @@ static_assert(sizeof(block_q5_K) == 2*sizeof(ggml_half) + K_SCALE_SIZE + QK_K/2
258
304
// weight is represented as x = a * q
259
305
// 16 blocks of 16 elements each
260
306
// Effectively 6.5625 bits per weight
261
- #define QI6_K (QK_K / (4 *QR6_K))
262
- #define QR6_K 2
263
307
typedef struct {
264
308
uint8_t ql[QK_K/2 ]; // quants, lower 4 bits
265
309
uint8_t qh[QK_K/4 ]; // quants, upper 2 bits
@@ -279,17 +323,13 @@ static_assert(sizeof(block_q8_K) == sizeof(float) + QK_K + QK_K/16*sizeof(int16_
279
323
// (Almost) "true" 2-bit quantization.
280
324
// Due to the need to use blocks as per ggml design, it ends up using
281
325
// 2.0625 bpw because of the 16-bit scale for each block of 256.
282
- #define QI2_XXS (QK_K / (4 *QR2_XXS))
283
- #define QR2_XXS 8
284
326
typedef struct {
285
327
ggml_half d;
286
328
uint16_t qs[QK_K/8 ];
287
329
} block_iq2_xxs;
288
330
static_assert (sizeof (block_iq2_xxs) == sizeof(ggml_half) + QK_K/8*sizeof(uint16_t ), "wrong iq2_xxs block size/padding");
289
331
290
332
// 2.3125 bpw quants
291
- #define QI2_XS (QK_K / (4 *QR2_XS))
292
- #define QR2_XS 8
293
333
typedef struct {
294
334
ggml_half d;
295
335
uint16_t qs[QK_K/8 ];
@@ -298,8 +338,6 @@ typedef struct {
298
338
static_assert (sizeof (block_iq2_xs) == sizeof(ggml_half) + QK_K/8*sizeof(uint16_t ) + QK_K/32, "wrong iq2_xs block size/padding");
299
339
300
340
// 2.5625 bpw quants
301
- #define QI2_S (QK_K / (4 *QR2_S))
302
- #define QR2_S 8
303
341
typedef struct {
304
342
ggml_half d;
305
343
uint8_t qs[QK_K/4 ];
@@ -311,8 +349,6 @@ static_assert(sizeof(block_iq2_s) == sizeof(ggml_half) + QK_K/4 + QK_K/16, "wron
311
349
// (Almost) "true" 3-bit quantization.
312
350
// Due to the need to use blocks as per ggml design, it ends up using
313
351
// 3.0625 bpw because of the 16-bit scale for each block of 256.
314
- #define QI3_XXS (QK_K / (4 *QR3_XXS))
315
- #define QR3_XXS 8
316
352
typedef struct {
317
353
ggml_half d;
318
354
uint8_t qs[3 *QK_K/8 ];
@@ -325,8 +361,6 @@ static_assert(sizeof(block_iq3_xxs) == sizeof(ggml_half) + 3*(QK_K/8), "wrong iq
325
361
#else
326
362
#define IQ3S_N_SCALE QK_K/64
327
363
#endif
328
- #define QI3_XS (QK_K / (4 *QR3_XS))
329
- #define QR3_XS 8
330
364
typedef struct {
331
365
ggml_half d;
332
366
uint8_t qs[QK_K/4 ];
@@ -336,8 +370,6 @@ typedef struct {
336
370
} block_iq3_s;
337
371
static_assert (sizeof (block_iq3_s) == sizeof(ggml_half) + 13*(QK_K/32 ) + IQ3S_N_SCALE, "wrong iq3_s block size/padding");
338
372
339
- #define QI1_S (QK_K / (4 *QR1_S))
340
- #define QR1_S 8
341
373
typedef struct {
342
374
ggml_half d;
343
375
uint8_t qs[QK_K/8 ];
@@ -347,22 +379,15 @@ static_assert(sizeof(block_iq1_s) == sizeof(ggml_half) + QK_K/8 + QK_K/16, "wron
347
379
348
380
// Non-linear quants
349
381
#define QK4_NL 32
350
- #define QI4_NL (QK4_NL / (4 *QR4_NL))
351
- #define QR4_NL 2
352
382
typedef struct {
353
383
ggml_half d;
354
384
uint8_t qs[QK4_NL/2 ];
355
385
} block_iq4_nl;
356
386
static_assert (sizeof (block_iq4_nl) == sizeof(ggml_half) + QK4_NL/2, "wrong iq4_nl block size/padding");
357
387
358
388
#if QK_K == 64
359
- #define block_iq4_xs block_iq4_nl
360
- #define QI4_XS QI4_NL
361
- #define QR4_XS QR4_NL
362
- // typedef struct block_iq4_nl block_iq4_xs;
389
+ typedef struct block_iq4_nl block_iq4_xs;
363
390
#else
364
- #define QI4_XS (QK_K / (4 *QR4_XS))
365
- #define QR4_XS 8
366
391
typedef struct {
367
392
ggml_half d;
368
393
uint16_t scales_h;
0 commit comments