From 2574f5936571645f784b77623e1f09bad97d948a Mon Sep 17 00:00:00 2001 From: leejet Date: Fri, 3 Jul 2026 00:46:51 +0800 Subject: [PATCH] fix: fallback when backend rejects flash attention (#1732) --- src/core/ggml_extend.hpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/core/ggml_extend.hpp b/src/core/ggml_extend.hpp index ebbed10b..c4138a23 100644 --- a/src/core/ggml_extend.hpp +++ b/src/core/ggml_extend.hpp @@ -1388,6 +1388,9 @@ __STATIC_INLINE__ ggml_tensor* ggml_ext_attention_ext(ggml_context* ctx, } auto out = ggml_flash_attn_ext(ctx, q_in, k_in, v_in, mask_in, scale / kv_scale, 0, 0); + if (!ggml_backend_supports_op(backend, out)) { + return nullptr; + } ggml_flash_attn_ext_set_prec(out, GGML_PREC_F32); if (kv_scale != 1.0f) { out = ggml_ext_scale(ctx, out, 1.0f / kv_scale); @@ -1405,9 +1408,7 @@ __STATIC_INLINE__ ggml_tensor* ggml_ext_attention_ext(ggml_context* ctx, if (can_use_flash_attn) { kqv = build_kqv(q, k, v, mask); - if (!ggml_backend_supports_op(backend, kqv)) { - kqv = nullptr; - } else { + if (kqv != nullptr) { kqv = ggml_view_4d(ctx, kqv, d_head,