@@ -9733,16 +9733,30 @@ static struct ggml_tensor * llm_build_kqv(
9733
9733
cur = ggml_flash_attn_ext(ctx, q, k, v, kq_mask, kq_scale, hparams.f_max_alibi_bias,
9734
9734
hparams.attn_soft_cap ? hparams.f_attn_logit_softcapping : 0.0f);
9735
9735
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
9736
9741
ggml_flash_attn_ext_set_prec(cur, GGML_PREC_F32);
9742
+ #endif
9737
9743
9738
9744
cur = ggml_reshape_2d(ctx, cur, n_embd_head_v*n_head, n_tokens);
9739
9745
} else {
9740
9746
struct ggml_tensor * kq = ggml_mul_mat(ctx, k, q);
9741
9747
cb(kq, "kq", il);
9742
9748
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
9743
9756
// note: this op tends to require high floating point range
9744
9757
// while for some models F16 is enough, for others it is not, so we default to F32 here
9745
9758
ggml_mul_mat_set_prec(kq, GGML_PREC_F32);
9759
+ #endif
9746
9760
9747
9761
if (model.arch == LLM_ARCH_GROK) {
9748
9762
// need to do the following:
0 commit comments