Skip to content

Commit c7e351b

Browse files
committed
add exception for ibm granite, then keep using f16 kq mul for HIPBLAS only for now pending ROCM investigation re ggml-org#10015
1 parent 5233e8e commit c7e351b

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/llama.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9733,16 +9733,30 @@ static struct ggml_tensor * llm_build_kqv(
97339733
cur = ggml_flash_attn_ext(ctx, q, k, v, kq_mask, kq_scale, hparams.f_max_alibi_bias,
97349734
hparams.attn_soft_cap ? hparams.f_attn_logit_softcapping : 0.0f);
97359735

9736+
#if defined(GGML_USE_HIPBLAS) //workaround for speed regression on rocm
9737+
if (model.arch == LLM_ARCH_PHI2 || model.arch == LLM_ARCH_PHI3 || model.arch == LLM_ARCH_GPTNEOX || model.arch == LLM_ARCH_GEMMA2 || model.arch == LLM_ARCH_GRANITE || model.arch == LLM_ARCH_GRANITE_MOE) {
9738+
ggml_flash_attn_ext_set_prec(cur, GGML_PREC_F32);
9739+
}
9740+
#else
97369741
ggml_flash_attn_ext_set_prec(cur, GGML_PREC_F32);
9742+
#endif
97379743

97389744
cur = ggml_reshape_2d(ctx, cur, n_embd_head_v*n_head, n_tokens);
97399745
} else {
97409746
struct ggml_tensor * kq = ggml_mul_mat(ctx, k, q);
97419747
cb(kq, "kq", il);
97429748

9749+
#if defined(GGML_USE_HIPBLAS) //workaround for speed regression on rocm
9750+
if (model.arch == LLM_ARCH_PHI2 || model.arch == LLM_ARCH_PHI3 || model.arch == LLM_ARCH_GPTNEOX || model.arch == LLM_ARCH_QWEN2 || model.arch == LLM_ARCH_NEMOTRON || model.arch == LLM_ARCH_CHATGLM || model.arch == LLM_ARCH_GRANITE || model.arch == LLM_ARCH_GRANITE_MOE) {
9751+
// for this arch, we need to perform the KQ multiplication with F32 precision, otherwise we get NaNs
9752+
// ref: https://github.com/ggerganov/llama.cpp/pull/4490#issuecomment-1859055847
9753+
ggml_mul_mat_set_prec(kq, GGML_PREC_F32);
9754+
}
9755+
#else
97439756
// note: this op tends to require high floating point range
97449757
// while for some models F16 is enough, for others it is not, so we default to F32 here
97459758
ggml_mul_mat_set_prec(kq, GGML_PREC_F32);
9759+
#endif
97469760

97479761
if (model.arch == LLM_ARCH_GROK) {
97489762
// need to do the following:

0 commit comments

Comments
 (0)