diff --git a/ggml/src/ggml-common.h b/ggml/src/ggml-common.h index 83f9118da..087376502 100644 --- a/ggml/src/ggml-common.h +++ b/ggml/src/ggml-common.h @@ -287,6 +287,26 @@ typedef struct { } block_tq2_0; static_assert(sizeof(block_tq2_0) == sizeof(ggml_half) + QK_K / 4, "wrong tq2_0 block size/padding"); +// +// Dual-plane ternary quantization (DT3) +// +// w_i = d[0]*t0_i + d[1]*t1_i, with t in {-1, 0, +1}. Two ternary planes buy +// back most of the quality a single one loses, at 3.5 bpw instead of 1.6875. +// +// Each plane is packed exactly like tq1_0 with every constant halved, since the +// block is 128 elements instead of QK_K: qs 48 -> 24 bytes, qh 4 -> 2 bytes, +// and the two qs passes go over 16 and then 8 bytes instead of 32 and 16. +// +#define QK_DT3 128 + +// 3.5 bpw +typedef struct { + uint8_t qs[2][(QK_DT3 - 4 * QK_DT3 / 64) / 5]; // 2 planes, 5 elements per byte (3^5 = 243 < 256) + uint8_t qh[2][QK_DT3 / 64]; // 2 planes, 4 elements per byte + ggml_half d[2]; // one scale per plane +} block_dt3; +static_assert(sizeof(block_dt3) == 2 * (sizeof(ggml_half) + QK_DT3 / 64 + (QK_DT3 - 4 * QK_DT3 / 64) / 5), "wrong dt3 block size/padding"); + // // Super-block quantization structures //