@@ -9618,20 +9618,16 @@ static struct ggml_tensor * llm_build_kqv(
9618
9618
cur = ggml_flash_attn_ext(ctx, q, k, v, kq_mask, kq_scale, hparams.f_max_alibi_bias,
9619
9619
hparams.attn_soft_cap ? hparams.f_attn_logit_softcapping : 0.0f);
9620
9620
9621
- if (model.arch == LLM_ARCH_PHI2 || model.arch == LLM_ARCH_PHI3 || model.arch == LLM_ARCH_GPTNEOX || model.arch == LLM_ARCH_GEMMA2) {
9622
- ggml_flash_attn_ext_set_prec(cur, GGML_PREC_F32);
9623
- }
9621
+ ggml_flash_attn_ext_set_prec(cur, GGML_PREC_F32);
9624
9622
9625
9623
cur = ggml_reshape_2d(ctx, cur, n_embd_head_v*n_head, n_tokens);
9626
9624
} else {
9627
9625
struct ggml_tensor * kq = ggml_mul_mat(ctx, k, q);
9628
9626
cb(kq, "kq", il);
9629
9627
9630
- 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) {
9631
- // for this arch, we need to perform the KQ multiplication with F32 precision, otherwise we get NaNs
9632
- // ref: https://github.com/ggerganov/llama.cpp/pull/4490#issuecomment-1859055847
9633
- ggml_mul_mat_set_prec(kq, GGML_PREC_F32);
9634
- }
9628
+ // note: this op tends to require high floating point range
9629
+ // while for some models F16 is enough, for others it is not, so we default to F32 here
9630
+ ggml_mul_mat_set_prec(kq, GGML_PREC_F32);
9635
9631
9636
9632
if (model.arch == LLM_ARCH_GROK) {
9637
9633
// need to do the following:
@@ -9640,9 +9636,6 @@ static struct ggml_tensor * llm_build_kqv(
9640
9636
// kq = 30 * tanh(kq / 30)
9641
9637
// before the softmax below
9642
9638
9643
- //try from phi2
9644
- //ggml_mul_mat_set_prec(kq, GGML_PREC_F32);
9645
-
9646
9639
kq = ggml_tanh(ctx, ggml_scale(ctx, kq, 0.08838834764831845f/30.0f));
9647
9640
kq = ggml_scale(ctx, kq, 30);
9648
9641
}
0 commit comments