diff options
author | Kawrakow <iwankawrakow@gmail.com> | 2025-01-10 18:18:04 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-10 18:18:04 +0200 |
commit | 7553989dd88749de028853f9c0ea39651aad92a3 (patch) | |
tree | 71783a2c138437c940492ca2b6f0e218f20a7b4c /ggml/src/iqk/iqk_quantize.cpp | |
parent | b1363b6177661556750c110cf876e044e61af365 (diff) |
Be able to re-quantize MS BitNet I2_S models (#169)
Co-authored-by: Iwan Kawrakow <iwan.kawrakow@gmail.com>
Diffstat (limited to 'ggml/src/iqk/iqk_quantize.cpp')
-rw-r--r-- | ggml/src/iqk/iqk_quantize.cpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/ggml/src/iqk/iqk_quantize.cpp b/ggml/src/iqk/iqk_quantize.cpp index cdb564f5..2404246d 100644 --- a/ggml/src/iqk/iqk_quantize.cpp +++ b/ggml/src/iqk/iqk_quantize.cpp @@ -5874,3 +5874,23 @@ void iqk_repack_tensor(struct ggml_tensor * tensor) { tensor->type = r.new_type; } +void dequantize_row_ms_i2s(const void * vx, float * y, int64_t k) { + constexpr int kBlockSize = 128; + constexpr int kGroupSize = kBlockSize/4; + GGML_ASSERT(k % kBlockSize == 0); + const uint8_t * x = (const uint8_t *)vx; + const float * dptr = (const float *)(x + k/4); + const float d = dptr[0]; + int nb = k/kBlockSize; + for (int ib = 0; ib < nb; ++ib) { + for (int ig = 0; ig < kBlockSize/kGroupSize; ++ig) { + int shift = 6 - 2*ig; + for (int j = 0; j < kGroupSize; ++j) { + y[j] = d * (((x[j] >> shift) & 3) - 1); + } + y += kGroupSize; + } + x += kGroupSize; + } +} + |