Skip to content

Commit 6d23495

Browse files
ikawrakowIwan Kawrakow
andauthored
On Zen4 repack fp16 models to bf16_r16 when run-time-repacking is requested (#174)
This massively improves performance. As this is opt-in, we do not worry about possible precision loss in the f16 -> bf16 conversion. Co-authored-by: Iwan Kawrakow <[email protected]>
1 parent 3c5f872 commit 6d23495

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

ggml/src/iqk/iqk_quantize.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5260,6 +5260,7 @@ inline ggml_bf16_t to_bf16(const float& x) {
52605260
helper.f = x;
52615261
return ggml_bf16_t{(uint16_t)(helper.u >> 16)};
52625262
}
5263+
inline ggml_bf16_t to_bf16(const ggml_half& x) { return to_bf16(GGML_FP16_TO_FP32(x)); }
52635264
inline ggml_bf16_t to_bf16(const ggml_bf16_t& x) { return x; }
52645265
template <typename T>
52655266
void repack_bf16(int nrows, int n_per_row, const T * x, ggml_bf16_t * y) {
@@ -6082,7 +6083,8 @@ void iqk_repack_tensor(struct ggml_tensor * tensor) {
60826083
{ GGML_TYPE_Q8_0, { GGML_TYPE_Q8_0_R4, 4, (Repack::repack_func)repack_q8_0} },
60836084
{ GGML_TYPE_Q8_K, { GGML_TYPE_Q8_K_R8, 8, (Repack::repack_func)repack_q8_k} },
60846085
#ifdef __AVX512BF16__
6085-
{ GGML_TYPE_BF16, { GGML_TYPE_BF16_R16, 16, (Repack::repack_func)repack_bf16<ggml_bf16_t>} },
6086+
{ GGML_TYPE_BF16, { GGML_TYPE_BF16_R16, 16, (Repack::repack_func)repack_bf16<ggml_bf16_t>}},
6087+
{ GGML_TYPE_F16, { GGML_TYPE_BF16_R16, 16, (Repack::repack_func)repack_bf16<ggml_half>} },
60866088
#endif
60876089
};
60886090

0 commit comments

Comments
 (0)