Skip to content

Commit 7a32fcb

Browse files
authored
ggml : add Q8_0 quantization format (rename the old one to Q8_1) (ARM NEON) (#1179)
* ggml : add Q8_0 quantization format (rename the old one to Q8_1) * tests : fix test-quantize-fns * ggml : finalize Q8_0 implementation * ggml : use q4_0_q8_0 and q4_2_q8_0 * ggml : fix Q8_0 dot product bug (ARM) * ggml : Q8_0 unroll x2 * ggml : fix bug - using wrong block type * ggml : extend quantize_fns_t with "vec_dot_type" * ggml : fix Q8_0 to use 255 values out of 256 * ggml : fix assert using wrong QK4_2 instead of QK4_3
1 parent dd0eabc commit 7a32fcb

File tree

8 files changed

+312
-147
lines changed

8 files changed

+312
-147
lines changed

examples/quantize/quantize.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ int main(int argc, char ** argv) {
1616
fprintf(stderr, " type = %d - q4_1\n", LLAMA_FTYPE_MOSTLY_Q4_1);
1717
fprintf(stderr, " type = %d - q4_2\n", LLAMA_FTYPE_MOSTLY_Q4_2);
1818
fprintf(stderr, " type = %d - q4_3\n", LLAMA_FTYPE_MOSTLY_Q4_3);
19+
fprintf(stderr, " type = %d - q8_0\n", LLAMA_FTYPE_MOSTLY_Q8_0);
1920
return 1;
2021
}
2122

ggml-cuda.cu

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ typedef struct {
3737
} block_q4_3;
3838
static_assert(sizeof(block_q4_3) == 2 * sizeof(ggml_fp16_t) + QK4_3 / 2, "wrong q4_3 block size/padding");
3939

40+
#define QK8_0 32
41+
typedef struct {
42+
float d; // delta
43+
int8_t qs[QK8_0]; // quants
44+
} block_q8_0;
45+
static_assert(sizeof(block_q8_0) == sizeof(float) + QK8_0, "wrong q8_0 block size/padding");
46+
4047
static __global__ void dequantize_block_q4_0(const void * vx, float * y) {
4148
const block_q4_0 * x = (const block_q4_0 *) vx;
4249

@@ -131,6 +138,22 @@ static __global__ void dequantize_block_q4_3(const void * vx, float * y) {
131138
}
132139
}
133140

141+
static __global__ void dequantize_block_q8_0(const void * vx, float * y) {
142+
const block_q8_0 * x = (const block_q8_0 *) vx;
143+
144+
const int i = blockIdx.x;
145+
146+
const float d = x[i].d;
147+
148+
const int8_t * pp = x[i].qs;
149+
150+
for (int l = 0; l < QK8_0; l++) {
151+
const int8_t vi = pp[l];
152+
153+
y[i*QK8_0 + l] = vi*d;
154+
}
155+
}
156+
134157
void dequantize_row_q4_0_cuda(const void * vx, float * y, int k, cudaStream_t stream) {
135158
const int nb = k / QK4_0;
136159
dequantize_block_q4_0<<<nb, 1, 0, stream>>>(vx, y);
@@ -151,6 +174,11 @@ void dequantize_row_q4_3_cuda(const void * vx, float * y, int k, cudaStream_t st
151174
dequantize_block_q4_3<<<nb, 1, 0, stream>>>(vx, y);
152175
}
153176

177+
void dequantize_row_q8_0_cuda(const void * vx, float * y, int k, cudaStream_t stream) {
178+
const int nb = k / QK8_0;
179+
dequantize_block_q8_0<<<nb, 1, 0, stream>>>(vx, y);
180+
}
181+
154182
// buffer pool for cuda
155183
#define MAX_CUDA_BUFFERS 16
156184

ggml-cuda.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ void dequantize_row_q4_0_cuda(const void * vx, float * y, int k, cudaStream_t st
3535
void dequantize_row_q4_1_cuda(const void * vx, float * y, int k, cudaStream_t stream);
3636
void dequantize_row_q4_2_cuda(const void * vx, float * y, int k, cudaStream_t stream);
3737
void dequantize_row_q4_3_cuda(const void * vx, float * y, int k, cudaStream_t stream);
38+
void dequantize_row_q8_0_cuda(const void * vx, float * y, int k, cudaStream_t stream);
3839

3940
#ifdef __cplusplus
4041
}

0 commit comments

Comments
 (0)