Commit 9a080f44b for llama.cpp

commit 9a080f44b503c64f66c84a6274b9d9ee5d5b09d5
Author: Ravi Panchumarthy <ravi.panchumarthy@intel.com>
Date:   Thu Nov 19 07:22:26 2026 -0800

    ggml-openvino: fix OpenVINO CI, minor fixes and optimizations (#32590)

    * ggml-openvino: round the GPU KV length up to a power of two

    Review notes (follow-ups, not blocking):
    - convert_ggml_input_to_ov pads the KQ mask into a std::vector and then
      copies it into the ov::Tensor. Writing the padded rows straight into
      padded.data() avoids the second allocation and copy (up to 16 MB per
      call at a 16K context).
    - The padding is skipped when the mask is not contiguous, and the KV
      inputs are then sliced to more rows than the mask has columns. Masks
      are always contiguous today; a GGML_ASSERT would make that explicit.
    - compute_llm_params reads GGML_OPENVINO_STATEFUL_EXECUTION directly;
      is_stateful_enabled() is local to ggml-openvino.cpp.

    * ggml-openvino: Optimize model recompiles of prefill stage

    Optimize the model recompiles of prefill stage when attended size
    changed between prompts. This can save model recompile time for
    llama-bench and llama-server.

    * ggml-openvino: Optimize model recompiles of prefill stage

    Optimize the model recompiles of prefill stage when attended size
    changed between prompts. This can save model recompile time for
    llama-bench and llama-server.

    * ggml-openvino: Remove solution C and keep A as default

    * ggml-openvino: match the output count before reusing a compiled NPU prefill

    The static prefill model has a fixed inp_out_ids shape [1,1,1,output_len].
    The new reuse check compared only the attention sizes, so llama-perplexity,
    which alternates 1 and 512 outputs per ubatch, reused the model compiled
    for 512 outputs on a 1-output ubatch and failed with "got [1,1,1,1]
    expecting [1,1,1,512]". Store the output count of the cached prefill
    model and require it to match.

    * ggml-openvino: Fix LFM2 context create on GPU and DSpark speculative decoding

    * ggml-openvino: remove leftovers from merging dev into the LFM2/DSpark fix

    - compute_model_outputs exported OUTPUT-flagged nodes twice: dev's block
      ran before the new one and still exported result_norm, so the
      result_norm exclusion had no effect. Keep only the new block.
    - compute_node_dynamic_dims checked is_activation_input twice in a row.
      Remove the second copy.
    - process_view_input_new created the dynamic Split on split_dim. With
      stateful execution the input drops the leading size-1 axis, so use
      split_axis, which already accounts for the rank difference.

    * ggml-openvino: hash the output flags into the model-cache fingerprint

    The fingerprint hashed the ops, names and weights but not the outputs, so
    a blob compiled with another output set was imported. With the result_norm
    change, an NPU blob written before it gave wrong output, and enabling
    llama_set_embeddings_layer_inp() reused a blob without the layer-input
    outputs. Hash each node's output flag and bump the cache version to 8.

    * ggml-openvino: support f16 SCALE and f16/bf16 TRI

    test-backend-ops now runs SCALE on f16 and TRI on f16 and bf16. Both
    translators built their constants as f32, and Multiply, Add and Select
    need all inputs in one element type, so building the graph threw for
    these cases.

    SCALE now converts a non-f32 input to f32, applies the scale and bias,
    and converts back once, as the CPU backend computes it. TRI creates its
    zero constant in the input's element type. f32 graphs are unchanged.

    * ggml-openvino: [Qwen3.6 A3B]fix static-shape ids view of the last MoE
     layer

    The same-stride single-dim Slice in process_view_input_new was followed by a Reshape
    whose target baked the static chunk size into the token axis. After the output-ids
    GET_ROWS the last layer runs on n_outputs tokens (1 in the prefill graph), so the
    Reshape failed shape validation for qwen35moe with FORCE_STATIC or on the NPU.
    Skip the Reshape in static graphs when the slice already keeps the rank;
    the dynamic graphs are unchanged.

    * enable mamba based models on OV CPU-GPU

    * revert changes in tests

    * docs : add Falcon-H1 to the OpenVINO validated models

    Falcon-H1 runs on CPU and GPU since Mamba SSM support was added. Add its
    row and the known limitations: multi-sequence batches fail, GPU accuracy
    is slightly lower than CPU, and the NPU fails with an element type
    mismatch.

    * ggml-openvino: simplify the SSM_SCAN build check and clean up

    - Drop the SelectiveSSM configure check and its guards: OpenVINO 2026.4.1
      always provides the op. Drop the no-op LANGUAGE CXX source property.
    - Drop the semicolon after OPENVINO_OP("SelectiveSSM"). GCC 15 reports it
      with -Wextra-semi, which fails builds with fatal warnings.
    - Add ggml_openvino_is_static() for the repeated NPU or
      GGML_OPENVINO_FORCE_STATIC check.
    - Share the f16 and f32 KQ mask padding code.
    - Drop the redundant inline on in-class static functions.

    ---------

    Co-authored-by: Suhas Somashekar <suhas.somashekar@intel.com>
    Co-authored-by: yzhou51 <yaowei.zhou@intel.com>
    Co-authored-by: Ananth, Swathi <swathi.ananth@intel.com>
    Co-authored-by: Beheshti <nazanin.beheshti@intel.com>

diff --git a/docs/backend/OPENVINO.md b/docs/backend/OPENVINO.md
index 0b5615ca2..a3a94aa16 100644
--- a/docs/backend/OPENVINO.md
+++ b/docs/backend/OPENVINO.md
@@ -195,6 +195,7 @@ The models below were tested with `llama-cli` and `Q4_K_M` files on an Intel® C
 | [bartowski/prism-ml_Bonsai-8B-unpacked-Q4_K_M](https://huggingface.co/bartowski/prism-ml_Bonsai-8B-unpacked-GGUF) | ✓ | ✓ | ✓ |
 | [LiquidAI/LFM2.5-2.6B-Q4_K_M](https://huggingface.co/LiquidAI/LFM2.5-2.6B-GGUF) | ✓ | ✓ | ✗ |
 | [bartowski/inclusionAI_Ling-mini-2.0-Q4_K_M](https://huggingface.co/bartowski/inclusionAI_Ling-mini-2.0-GGUF) | ✓ | ✓ | ✗ |
+| [tiiuae/Falcon-H1-0.5B-Instruct-Q4_K_M](https://huggingface.co/tiiuae/Falcon-H1-0.5B-Instruct-GGUF) | ✓ | ✓ | ✗ |
 |  |  |  |  |
 | [Qwen/Qwen3-Embedding-0.6B-Q8_0](https://huggingface.co/Qwen/Qwen3-Embedding-0.6B-GGUF) | ✓ | ✓ | ✗ |
 | [ggml-org/bge-m3-Q8_0](https://huggingface.co/ggml-org/bge-m3-Q8_0-GGUF) | ✓ | ✓ | ✗ |
@@ -990,6 +991,7 @@ build\ReleaseOV\bin\llama-simple.exe -m "C:\models\Llama-3.2-1B-Instruct-Q4_K_M.
 - Multimodal features (audio/image/video) are a work in progress.
 - Embedding models: reranking models are not validated.
 - Llama.cpp tool coverage across CPU/GPU/NPU is not uniform.
+- Mamba-based models (e.g. Falcon-H1): `llama-perplexity` with several sequences per batch fails; set `-b` to the same value as `-c`. GPU accuracy is slightly lower than CPU.

 **GPU-specific**

@@ -1012,6 +1014,7 @@ build\ReleaseOV\bin\llama-simple.exe -m "C:\models\Llama-3.2-1B-Instruct-Q4_K_M.
 - `llama-perplexity`: requires `-b 512` or smaller.
 - Flash attention must stay on, which is the default (`-fa auto`). With `-fa off`, the run fails on the NPU.
 - `llama-embedding` fails on the NPU.
+- Mamba-based models (e.g. Falcon-H1) fail on the NPU with `Failed to set tensor` (element type mismatch).
 - Lunar Lake NPU: decode slows down sharply when the context is large. The context size at which this starts depends on the model.
   - **Workaround:** Pass the smallest context that fits the use, e.g. `-c 512`, or `-c 256` for larger models.
 - Panther Lake NPU: the load of a Qwen3.5 model can end with a segmentation fault in the NPU compiler of OpenVINO 2026.4.1.
diff --git a/ggml/src/ggml-openvino/ggml-decoder.cpp b/ggml/src/ggml-openvino/ggml-decoder.cpp
index 38db895c5..519c35bc2 100644
--- a/ggml/src/ggml-openvino/ggml-decoder.cpp
+++ b/ggml/src/ggml-openvino/ggml-decoder.cpp
@@ -107,7 +107,8 @@ GgmlOvDecoder::GgmlOvDecoder(ggml_cgraph * cgraph, std::map<std::string, std::sh
     m_naive = true;
     for (int i = 0; i < cgraph->n_nodes; ++i) {
         if ((cgraph->nodes[i]->op == GGML_OP_GATED_DELTA_NET && cgraph->nodes[i]->op_params[0] > 1) ||
-            is_sampling_view(cgraph->nodes[i]) || is_conv_state_snapshot_writeback(cgraph->nodes[i])) {
+            is_sampling_view(cgraph->nodes[i]) || is_conv_state_snapshot_writeback(cgraph->nodes[i]) ||
+            is_ssm_state_writeback(cgraph->nodes[i])) {
             std::tie(m_model_params, m_compute_params) = compute_llm_params(cgraph, false);
             add_extra_inputs();
             break;
@@ -494,6 +495,10 @@ int GgmlOvDecoder::compute_op_case(const ggml_tensor * node) const {
             }
         } else if (node->ne[0] == 1 && src->ne[0] * src->ne[1] * src->ne[2] == node->ne[1]) {
             op_case = 3;
+        } else if (node->ne[0] * node->ne[1] == src->ne[0] * src->ne[1] && node->ne[2] == src->ne[2] &&
+                   node->ne[3] == src->ne[3]) {
+            // head regroup, e.g. mamba2's [head_dim, n_head, n_tokens, n_seqs] -> [d_inner/n_group, n_group, n_tokens, n_seqs]
+            op_case = 1;
         } else if (name.find("linear_attn_qkv_mixed") == 0 || name.find("alpha") == 0) {
             op_case = 6;
         } else if (name.find("linear_attn_out") == 0) {
@@ -597,6 +602,10 @@ int GgmlOvDecoder::compute_op_case(const ggml_tensor * node) const {
             op_case = 3;
             break;
         }
+        if (is_column_set_rows(node)) {
+            op_case = 4;
+            break;
+        }
         // `-fa off` writes the V cache transposed, through a [1, n] reshape of the cache: one element per row
         if (node->src[2] != nullptr && node->src[2]->op == GGML_OP_RESHAPE && node->src[2]->ne[0] == 1 &&
             is_kvcache(node->src[2]->src[0], nullptr)) {
@@ -797,6 +806,9 @@ int GgmlOvDecoder::compute_op_case(const ggml_tensor * node) const {
                 } else {
                     op_case = 1;
                 }
+            } else if (is_ssm_state_writeback(node)) {
+                op_case = 13;
+                break;
             } else if (GgmlOvDecoder::is_conv_state_writeback(node)) {
                 op_case = 2;
                 break;
@@ -1296,6 +1308,11 @@ std::pair<ModelParams, ComputeParams> GgmlOvDecoder::compute_llm_params(ggml_cgr
             writeback.snapshot_stride = destination->nb[2] / destination->nb[1];
             compute_params.rs_writebacks[get_tensor_ov_name(cgraph, node)] = writeback;
         }
+        if (is_ssm_state_writeback(node)) {
+            ComputeParams::RsWriteback writeback;
+            writeback.slot_begin = (int64_t) (node->src[1]->view_offs / node->src[1]->nb[1]);
+            compute_params.rs_writebacks[get_tensor_ov_name(cgraph, node)] = writeback;
+        }
         if (is_conv_state_snapshot_writeback(node)) {
             const auto source = node->src[0];
             const auto dest = node->src[2];
@@ -1406,6 +1423,14 @@ std::pair<ModelParams, ComputeParams> GgmlOvDecoder::compute_llm_params(ggml_cgr
         compute_params.attention_size =
             ggml_openvino_static_kv_window(compute_params.attention_size, model_params.ctx_per_seq);
     }
+    // The GPU plugin keeps device memory for each KV length it sees, and llama.cpp grows the KV length in steps of
+    // 256. Round it up to a power of two the same way, so that a long context uses a few lengths and not one per
+    // step. The KQ mask input is padded to this length with -inf (convert_ggml_input_to_ov).
+    if (!is_static && ggml_openvino_is_gpu() && !ggml_openvino_getenv_int("GGML_OPENVINO_STATEFUL_EXECUTION") &&
+        !compute_params.mask_name.empty() && compute_params.attention_size > 0 && model_params.ctx_per_seq > 0) {
+        compute_params.attention_size =
+            ggml_openvino_static_kv_window(compute_params.attention_size, model_params.ctx_per_seq);
+    }
     model_params.ctx = model_params.ctx_per_seq * model_params.n_seq;
     return {model_params, compute_params};
 }
@@ -1416,6 +1441,15 @@ void GgmlOvDecoder::validate_cgraph() const {
     }
 }

+bool GgmlOvDecoder::has_inp_embd_leaf_use(const ggml_tensor * tensor) const {
+    for (int i = 0; i < m_cgraph->n_nodes; i++) {
+        if (is_inp_embd_leaf(tensor, m_cgraph->nodes[i])) {
+            return true;
+        }
+    }
+    return false;
+}
+
 ov::PartialShape GgmlOvDecoder::get_graph_input_shape(const ggml_tensor * op,
                                                       const ggml_tensor * input,
                                                       int dynamic_dim_index) const {
@@ -1530,7 +1564,7 @@ ov::PartialShape GgmlOvDecoder::get_graph_input_shape(const ggml_tensor * op,
         // index list has a static length; on CPU/GPU it may change across compiles (defrag).
         input_shape = m_is_static ? ov::PartialShape{get_shape(input)} : ov::PartialShape{1, 1, 1, -1};

-    } else if (input != nullptr && op != nullptr && is_inp_emb(input, op)) {
+    } else if (input != nullptr && op != nullptr && (is_inp_emb(input, op) || has_inp_embd_leaf_use(input))) {
         input_shape = ov::PartialShape{get_shape(input)};
         if (!m_is_static) {
             input_shape[2] = -1;
@@ -1914,7 +1948,11 @@ void GgmlOvDecoder::compute_model_outputs() {
             continue;
         }
         const bool inactive_top_k = is_sampling_top_k(cur_node) && !(cur_node->flags & GGML_TENSOR_FLAG_COMPUTE);
-        if ((cur_node->flags & GGML_TENSOR_FLAG_OUTPUT) || inactive_top_k) {
+        auto cur_node_use_count = m_cgraph->use_counts[ggml_hash_find(&m_cgraph->visited_hash_set, cur_node)];
+        // llama flags result_norm in every graph but reads it only with embeddings on, when it has no consumer
+        // and is kept by the rule below.
+        const bool unread_embd = strcmp(cur_node->name, "result_norm") == 0 && cur_node_use_count > 0;
+        if (((cur_node->flags & GGML_TENSOR_FLAG_OUTPUT) && !unread_embd) || inactive_top_k) {
             const auto name = get_tensor_ov_name(m_cgraph, cur_node);
             m_model_outputs[name] = cur_node;
             m_model_output_names.insert(name);
@@ -1925,7 +1963,12 @@ void GgmlOvDecoder::compute_model_outputs() {
             m_model_outputs[name] = cache;
             m_model_output_names.insert(name);
         }
-        auto cur_node_use_count = m_cgraph->use_counts[ggml_hash_find(&m_cgraph->visited_hash_set, cur_node)];
+        if (is_ssm_state_writeback(cur_node)) {
+            auto * cache = cur_node->view_src;
+            const auto name = get_tensor_ov_name(m_cgraph, cache);
+            m_model_outputs[name] = cache;
+            m_model_output_names.insert(name);
+        }
         if (cur_node_use_count == 0) {
             // The output of in-place ops is the view_src tensor, which is updated in place. We should use the view_src name as the output name to make sure it can be correctly matched with the later ops that use the view_src.
             if (cur_node != nullptr && ::is_inplace_op(cur_node) &&
@@ -2641,6 +2684,10 @@ bool GgmlOvDecoder::is_direct_gdn_view(const ggml_tensor * node) const {

 std::vector<std::string> GgmlOvDecoder::get_output_names(int node_idx) const {
     auto * node = m_node_info_list[node_idx].node;
+    if (is_ssm_state_writeback(node)) {
+        // the written state block plus the full updated cache (see translate_cpy op_case 13)
+        return {m_node_info_list[node_idx].node_name, get_tensor_ov_name(m_cgraph, node->view_src)};
+    }
     if (node->op == GGML_OP_GATED_DELTA_NET && (!m_model_params.has_rs_rollback || node->op_params[0] > 1)) {
         std::string attn_name;
         std::string state_name;
@@ -2669,6 +2716,10 @@ std::vector<std::string> GgmlOvDecoder::get_output_names(int node_idx) const {

 std::string GgmlOvDecoder::get_inplace_op_src(int node_idx) const {
     auto * node = m_node_info_list[node_idx].node;
+    if (is_ssm_state_writeback(node)) {
+        // translate_cpy publishes the updated cache as a second named output
+        return "";
+    }
     // Reset lengths (also in static mode) and dynamic remainder views can become nonempty
     // after compilation. Keep their alias updates in the translated cache chain.
     const bool runtime_recurrent_write = !m_naive && is_recurrent_cache(node->view_src) &&
@@ -2786,7 +2837,7 @@ void GgmlOvDecoder::compute_node_dynamic_dims() {
                     m_node_dynamic_dims[src] = 0;
                     continue;
                 }
-                if (is_inp_scale_rows(src, node)) {
+                if (is_inp_scale_rows(src, node) || is_inp_embd_leaf(src, node)) {
                     m_node_dynamic_dims[src] = 1;
                     continue;
                 }
@@ -2865,6 +2916,11 @@ void GgmlOvDecoder::compute_node_dynamic_dims() {
                 m_node_dynamic_dims[node] = 2;
                 break;
             }
+            if (node->src[0]->op == GGML_OP_SSM_SCAN) {
+                // y part [head_dim, n_head, n_tokens, n_seqs] at offset 0; the state part is token-independent
+                m_node_dynamic_dims[node] = node->view_offs == 0 ? 2 : -1;
+                break;
+            }
             // Use stride-based matching: the stride of a VIEW dimension directly
             // encodes which source dimension it indexes into, so it uniquely
             // identifies the dynamic dim even when two dims share the same size.
@@ -3030,6 +3086,10 @@ void GgmlOvDecoder::compute_node_dynamic_dims() {
         case GGML_OP_GATED_DELTA_NET:
             m_node_dynamic_dims[node] = 1;
             break;
+        case GGML_OP_SSM_SCAN:
+            // packed 1-D [y | state]; the y part grows with tokens
+            m_node_dynamic_dims[node] = 0;
+            break;
         case GGML_OP_RMS_NORM:
         case GGML_OP_L2_NORM:
         case GGML_OP_NORM:
@@ -3080,12 +3140,15 @@ void GgmlOvDecoder::compute_node_dynamic_dims() {
         case GGML_OP_CPY:
         case GGML_OP_SUM:
         case GGML_OP_MEAN:
+        case GGML_OP_ARANGE:
             m_node_dynamic_dims[node] = -1;
             break;
         case GGML_OP_SET_ROWS:
-            // a cache write returns the cache; other rows writes keep the shape of their destination
-            m_node_dynamic_dims[node] = (is_kvcache_write(node) || is_conv_state_snapshot_writeback(node)) ?
-                                           -1 : m_node_dynamic_dims[node->src[2]];
+            // a cache or column write returns its whole buffer; other rows writes keep the shape of their destination
+            m_node_dynamic_dims[node] =
+                (is_kvcache_write(node) || is_conv_state_snapshot_writeback(node) || is_column_set_rows(node)) ?
+                    -1 :
+                    m_node_dynamic_dims[node->src[2]];
             break;
         case GGML_OP_IM2COL: {
             m_node_dynamic_dims[node] = -1;
diff --git a/ggml/src/ggml-openvino/ggml-decoder.h b/ggml/src/ggml-openvino/ggml-decoder.h
index b7ff4b715..12b08cebc 100644
--- a/ggml/src/ggml-openvino/ggml-decoder.h
+++ b/ggml/src/ggml-openvino/ggml-decoder.h
@@ -477,6 +477,21 @@ public:
         return tensor->op == GGML_OP_GET_ROWS && op->op == GGML_OP_RMS_NORM;
     }

+    // Raw float input [n_embd, n_tokens]: DFlash/DSpark/EAGLE3 features into fc, or raw embd batch / EAGLE3 g-embd into RMS_NORM
+    // MUL_MAT needs a weight leaf as src[0], so inp_mean (src[0] is computed) does not match
+    static bool is_inp_embd_leaf(const ggml_tensor * tensor, const ggml_tensor * op) {
+        if (tensor->op != GGML_OP_NONE || !(tensor->flags & GGML_TENSOR_FLAG_INPUT) || tensor->type != GGML_TYPE_F32) {
+            return false;
+        }
+        if (op->op == GGML_OP_MUL_MAT) {
+            return op->src[1] == tensor && op->src[0] != nullptr && op->src[0]->op == GGML_OP_NONE;
+        }
+        return op->op == GGML_OP_RMS_NORM && op->src[0] == tensor;
+    }
+
+    // true if any node of the current graph uses tensor as a raw embd input (see is_inp_embd_leaf)
+    bool has_inp_embd_leaf_use(const ggml_tensor * tensor) const;
+
     static bool is_activation_input(const ggml_tensor * tensor, const ggml_tensor * op) {
         if (tensor == nullptr || op == nullptr || tensor->type != GGML_TYPE_F32 || tensor->ne[2] != 1 ||
             tensor->ne[3] != 1 || (tensor->buffer != nullptr && tensor->buffer->usage == GGML_BACKEND_BUFFER_USAGE_WEIGHTS)) {
@@ -578,11 +593,11 @@ public:

     bool is_direct_gdn_view(const ggml_tensor * node) const;

-    inline static bool is_cache(const ggml_tensor * tensor, const ggml_tensor * op) {
+    static bool is_cache(const ggml_tensor * tensor, const ggml_tensor * op) {
         return is_recurrent_cache(tensor) || is_kvcache(tensor, op);
     }

-    inline static bool is_kvcache(const ggml_tensor * tensor, const ggml_tensor * op) {
+    static bool is_kvcache(const ggml_tensor * tensor, const ggml_tensor * op) {
         if (tensor == nullptr || is_recurrent_cache(tensor)) {
             return false;
         }
@@ -590,27 +605,68 @@ public:
                (op != nullptr && op->op == GGML_OP_SET_ROWS && op->src[2] == tensor);
     }

-    inline static bool is_conv_state_writeback(const ggml_tensor * node) {
+    static bool is_conv_state_writeback(const ggml_tensor * node) {
         return node->op == GGML_OP_CPY && node->view_src != nullptr && is_recurrent_cache(node->view_src) &&
                node->src[0] != nullptr && node->src[0]->op == GGML_OP_VIEW && node->src[0]->src[0] != nullptr &&
                node->src[0]->src[0]->op == GGML_OP_CONCAT && node->src[1] != nullptr &&
                node->src[1]->op == GGML_OP_VIEW && node->src[1]->view_src == node->view_src;
     }

+    // The final-state writeback of SSM_SCAN (K == 1): the state tail of the packed [y | state]
+    // output copied into a slot block of the recurrent cache.
+    static bool is_ssm_state_writeback(const ggml_tensor * node) {
+        if (!(node != nullptr && node->op == GGML_OP_CPY && node->view_src != nullptr && node->src[0] != nullptr &&
+              node->src[0]->op == GGML_OP_VIEW && node->src[0]->src[0] != nullptr &&
+              node->src[0]->src[0]->op == GGML_OP_SSM_SCAN && node->src[0]->src[0]->op_params[0] == 1 &&
+              node->src[1] != nullptr && node->src[1]->op == GGML_OP_VIEW &&
+              node->src[1]->view_src == node->view_src)) {
+            return false;
+        }
+        const auto * scan = node->src[0]->src[0];
+        const auto * src = node->src[0];
+        const auto * dst = node->src[1];
+        if (node->type != GGML_TYPE_F32 || src->type != GGML_TYPE_F32 || dst->type != GGML_TYPE_F32 ||
+            src->ne[2] != 1 || src->ne[3] != 1) {
+            return false;
+        }
+        for (int i = 0; i < GGML_MAX_DIMS; ++i) {
+            if (src->ne[i] != dst->ne[i]) {
+                return false;
+            }
+        }
+        return dst->nb[1] > 0 && dst->view_offs % dst->nb[1] == 0 &&
+               src->view_offs == (size_t) ggml_nelements(scan->src[1]) * ggml_type_size(scan->type);
+    }
+
     // build_conv_state_store writes overlapping [history, window, channel, seq] windows into newest-first rollback planes.
     // Match this layout separately from general SET_ROWS.
     static bool is_conv_state_snapshot_writeback(const ggml_tensor * node);

+    // SET_ROWS into a column range of each row of a plain 2-D buffer, e.g. build_layer_inp_dev(): every enabled layer
+    // input goes to view_2d(layer_inp_dev, n_embd, n_batch, nb1, col * n_embd * elem) at the batch rows of the ubatch.
+    // The buffer sits in a regular device buffer, so is_kvcache() matches it: check this first
+    static bool is_column_set_rows(const ggml_tensor * node) {
+        if (node == nullptr || node->op != GGML_OP_SET_ROWS || node->src[2] == nullptr ||
+            node->src[2]->op != GGML_OP_VIEW) {
+            return false;
+        }
+        const ggml_tensor * dst = node->src[2];
+        const ggml_tensor * buf = dst->view_src;
+        return buf != nullptr && buf->op == GGML_OP_NONE && !is_recurrent_cache(buf) && buf->ne[2] == 1 &&
+               buf->ne[3] == 1 && dst->ne[2] == 1 && dst->ne[3] == 1 && dst->ne[0] < buf->ne[0] &&
+               dst->nb[0] == buf->nb[0] && dst->nb[1] == buf->nb[1] && dst->ne[1] == buf->ne[1];
+    }
+
     // SET_ROWS into a KV cache, directly or through the [1, n] reshape of the transposed V cache with `-fa off`.
     // Other SET_ROWS write rows of a compute tensor, e.g. the MoE expert-group mask
-    inline static bool is_kvcache_write(const ggml_tensor * node) {
+    static bool is_kvcache_write(const ggml_tensor * node) {
         const ggml_tensor * dst = node->src[2];
         return dst != nullptr && is_kvcache(dst->view_src != nullptr ? dst->view_src : dst, nullptr);
     }

     // GET_ROWS batched over ggml dims 2 and 3, e.g. the MoE expert-group scores
     // ggml_get_rows(ggml_reshape_4d(groups, 1, n_exp_per_group, n_groups, n_tokens), top_groups)
-    inline static bool is_get_rows_batched_4d(const ggml_tensor * node) {
+    static bool is_get_rows_batched_4d(const ggml_tensor * node) {
         return node->op == GGML_OP_GET_ROWS && !ggml_is_quantized(node->src[0]->type) &&
                node->src[1]->ne[1] == node->src[0]->ne[2] && node->src[1]->ne[2] == node->src[0]->ne[3] &&
                node->src[1]->ne[3] == 1;
diff --git a/ggml/src/ggml-openvino/ggml-openvino-extra.cpp b/ggml/src/ggml-openvino/ggml-openvino-extra.cpp
index c76b42398..2537f8af3 100644
--- a/ggml/src/ggml-openvino/ggml-openvino-extra.cpp
+++ b/ggml/src/ggml-openvino/ggml-openvino-extra.cpp
@@ -616,6 +616,10 @@ bool ggml_openvino_is_npu() {
     return ggml_openvino_get_device_config().is_npu;
 }

+bool ggml_openvino_is_static() {
+    return ggml_openvino_is_npu() || ggml_openvino_getenv_int("GGML_OPENVINO_FORCE_STATIC");
+}
+
 bool ggml_openvino_is_gpu() {
     return has_prefix(ggml_openvino_get_device_name(), "GPU");
 }
diff --git a/ggml/src/ggml-openvino/ggml-openvino-extra.h b/ggml/src/ggml-openvino/ggml-openvino-extra.h
index 5a64c67ef..406ac6d4c 100644
--- a/ggml/src/ggml-openvino/ggml-openvino-extra.h
+++ b/ggml/src/ggml-openvino/ggml-openvino-extra.h
@@ -134,6 +134,9 @@ bool ggml_openvino_release_weights_enabled();
 // Check if running on NPU
 bool ggml_openvino_is_npu();

+// Static graphs: NPU, or any device with GGML_OPENVINO_FORCE_STATIC
+bool ggml_openvino_is_static();
+
 // KV-cache slicing: bind the KV cache, and size the KQ masks, at the attended length instead of the full context.
 // One mechanism, two modes:
 //   dynamic graphs (CPU/GPU): the KV input is a view over the cache; the graph is not recompiled.
diff --git a/ggml/src/ggml-openvino/ggml-openvino.cpp b/ggml/src/ggml-openvino/ggml-openvino.cpp
index a7f5d177f..98f22cfd7 100644
--- a/ggml/src/ggml-openvino/ggml-openvino.cpp
+++ b/ggml/src/ggml-openvino/ggml-openvino.cpp
@@ -1504,6 +1504,38 @@ static bool has_strides_on_element_grid(const ggml_tensor * t) {
     return true;
 }

+// A VIEW that regroups one contiguous span of every row of its contiguous source, e.g. the z/x/B/C
+// splits of the fused mamba projections. The strides do not nest on an element grid, but
+// process_view_input_new resolves it as a Slice of the source's innermost axis plus a Reshape.
+// Keep in sync with the matching branch there; dynamic execution only.
+static bool is_row_span_view(const ggml_tensor * t) {
+    if (ggml_openvino_is_static() || is_stateful_enabled()) {
+        return false;
+    }
+    const ggml_tensor * src = t->op == GGML_OP_VIEW ? t->src[0] : nullptr;
+    // a RESHAPE source is fine (the translation reads its value); a chained VIEW is not, because
+    // the view metadata then describes the intermediate view instead of the resolved input
+    if (src == nullptr || src->op == GGML_OP_VIEW || !ggml_is_contiguous(src) || t->type != src->type) {
+        return false;
+    }
+    const size_t es = ggml_type_size(t->type);
+    int d = 0;
+    size_t span = 1;
+    while (d < GGML_MAX_DIMS && t->nb[d] == span * es) {
+        span *= t->ne[d];
+        d++;
+    }
+    if (d < 2) {
+        return false;
+    }
+    for (int s = 1; d < GGML_MAX_DIMS; ++d, ++s) {
+        if (t->ne[d] != src->ne[s] || t->nb[d] != src->nb[s]) {
+            return false;
+        }
+    }
+    return t->view_offs % es == 0 && t->view_offs / es + span <= (size_t) src->ne[0];
+}
+
 static bool has_non_contiguous_view_input(const ggml_tensor * op) {
     for (int i = 0; i < GGML_MAX_SRC; i++) {
         if (op->src[i] == nullptr) {
@@ -1624,7 +1656,7 @@ static bool cpy_output_view_is_supported(const ggml_tensor * op) {
     }

     return ggml_nbytes(op) == 0 || ggml_is_contiguous(op) || GgmlOvDecoder::is_conv_state_writeback(op) ||
-           GgmlOvDecoder::is_gdn_snapshot_writeback(op);
+           GgmlOvDecoder::is_gdn_snapshot_writeback(op) || GgmlOvDecoder::is_ssm_state_writeback(op);
 }

 static bool mul_mat_id_requires_large_tmp(const ggml_tensor * op) {
@@ -1727,8 +1759,7 @@ static ggml_openvino_op_support is_op_supported_case(const ggml_tensor * op) {
     }
     case GGML_OP_GET_ROWS:
     case GGML_OP_SET_ROWS: {
-        if (GgmlOvDecoder::is_conv_state_snapshot_writeback(op) &&
-            (ggml_openvino_is_npu() || ggml_openvino_getenv_int("GGML_OPENVINO_FORCE_STATIC"))) {
+        if (GgmlOvDecoder::is_conv_state_snapshot_writeback(op) && ggml_openvino_is_static()) {
             return {false, "convolution snapshots require dynamic execution"};
         }
         if (op->ne[3] != 1 && !GgmlOvDecoder::is_get_rows_batched_4d(op) &&
@@ -2034,7 +2065,7 @@ static ggml_openvino_op_support is_op_supported_case(const ggml_tensor * op) {
             reason = "GATED_DELTA_NET with kda (per-key-dimension gating) is not supported";
         }
         else if (op->op_params[0] > 1) {
-            if (ggml_openvino_is_npu() || ggml_openvino_getenv_int("GGML_OPENVINO_FORCE_STATIC")) {
+            if (ggml_openvino_is_static()) {
                 reason = "GATED_DELTA_NET snapshots require dynamic execution";
             }
         }
@@ -2053,6 +2084,19 @@ static ggml_openvino_op_support is_op_supported_case(const ggml_tensor * op) {
         // return true;
         break;
     }
+    case GGML_OP_SSM_SCAN: {
+        // SelectiveSSM implements the Mamba-2 recurrence: scalar decay per head, one final state
+        if (op->src[3]->ne[0] != 1) {
+            return {false, "SSM_SCAN with Mamba-1 state-wise decay is not supported"};
+        }
+        if (op->op_params[0] > 1) {
+            return {false, "SSM_SCAN with rollback snapshots (K > 1) is not supported"};
+        }
+        if (ggml_openvino_is_static()) {
+            return {false, "SSM_SCAN requires dynamic execution"};
+        }
+        break;
+    }
     case GGML_OP_VIEW: {
         // Skip TOPK_MOE fused tests until it is fully supported.
         // The argsort_top_k VIEW wrapping ARGSORT is named "selected_experts" in test_topk_moe.
@@ -2274,7 +2318,8 @@ static ggml_openvino_op_support ggml_backend_openvino_device_supports_op_impl(gg
         if (supported_types.find(src->type) == supported_types.end()) {
             return {false, "src[" + std::to_string(i) + "] type " + std::string(ggml_type_name(src->type)) + " is not supported"};
         }
-        if (!has_strides_on_element_grid(src) && !(i == 1 && GgmlOvDecoder::is_gdn_snapshot_writeback(op)) &&
+        if (!has_strides_on_element_grid(src) && !is_row_span_view(src) &&
+            !(i == 1 && GgmlOvDecoder::is_gdn_snapshot_writeback(op)) &&
             !(i == 2 && GgmlOvDecoder::is_conv_state_snapshot_writeback(op))) {
             return {false, "src[" + std::to_string(i) + "] strides are not multiples of each other"};
         }
diff --git a/ggml/src/ggml-openvino/model-cache.cpp b/ggml/src/ggml-openvino/model-cache.cpp
index 597233d7e..7bfa7ad08 100644
--- a/ggml/src/ggml-openvino/model-cache.cpp
+++ b/ggml/src/ggml-openvino/model-cache.cpp
@@ -197,8 +197,7 @@ void ggml_openvino_model_cache_init() {
         }
         return;
     }
-    if (cache_only && (ggml_openvino_is_npu() || ggml_openvino_getenv_int("GGML_OPENVINO_FORCE_STATIC") ||
-                       ggml_openvino_getenv_int("GGML_OPENVINO_DISABLE_CACHE") ||
+    if (cache_only && (ggml_openvino_is_static() || ggml_openvino_getenv_int("GGML_OPENVINO_DISABLE_CACHE") ||
                        ggml_openvino_getenv_int("GGML_OPENVINO_ENABLE_FALLBACK"))) {
         GGML_ABORT("ggml-openvino: cache-only mode requires dynamic CPU/GPU execution with caching and without fallback");
     }
@@ -368,7 +367,8 @@ uint64_t ggml_openvino_model_fingerprint(const ggml_cgraph * cgraph,
     // Version 5 requantizes K-quant MoE experts to Q4_1_64 on GPU by default.
     // Version 6 clears recurrent-cache slots with Select, so a NaN in a cleared slot does not survive.
     // Version 7 reads ROPE frequency factors named other than rope_freqs.weight as a Constant, not a Parameter.
-    h = fnv1a_u64(h, 7);
+    // Version 8 drops result_norm from the outputs when it has a consumer, and hashes the output flags.
+    h = fnv1a_u64(h, 8);
     h = fnv1a(h, graph_signature.data(), graph_signature.size());
     for (const char * name : cache_settings) {
         const char * value = ggml_openvino_getenv_str(name, "");
@@ -391,6 +391,8 @@ uint64_t ggml_openvino_model_fingerprint(const ggml_cgraph * cgraph,
         const ggml_tensor * node = cgraph->nodes[i];
         h = fnv1a_u64(h, static_cast<uint64_t>(node->op));
         h = fnv1a(h, node->name, strlen(node->name));
+        // Each output is a Result of the model; llama_set_embeddings_layer_inp() changes only the flags.
+        h = fnv1a_u64(h, (node->flags & GGML_TENSOR_FLAG_OUTPUT) ? 1u : 0u);
         has_gdn = has_gdn || node->op == GGML_OP_GATED_DELTA_NET;
     }
     if (has_gdn && ggml_openvino_is_npu()) {
diff --git a/ggml/src/ggml-openvino/openvino/op/cpy.cpp b/ggml/src/ggml-openvino/openvino/op/cpy.cpp
index 0bb6bd054..e0d63ac95 100644
--- a/ggml/src/ggml-openvino/openvino/op/cpy.cpp
+++ b/ggml/src/ggml-openvino/openvino/op/cpy.cpp
@@ -75,6 +75,28 @@ OutputVector translate_cpy(const NodeContext & context) {
         return rename_outputs_with_suffix({result}, context.get_name());
     }

+    if (op_case == 13) {
+        // SSM_SCAN final-state writeback: output the written state block and the full updated cache
+        auto src = process_view_input_new(context, 0);
+        auto base = context.get_input(1);
+        if (src.get_element_type() != context.get_output_type()) {
+            src = std::make_shared<ov::op::v0::Convert>(src, context.get_output_type());
+        }
+        auto zero = ov::op::v0::Constant::create(ov::element::i64, {1}, {0});
+        auto one = ov::op::v0::Constant::create(ov::element::i64, {1}, {1});
+        auto int_max = ov::op::v0::Constant::create(ov::element::i64, {1}, {INT_MAX});
+        auto axis = ov::op::v0::Constant::create(ov::element::i64, {1}, {2});
+        auto begin = context.get_input("rs_slot_begin_" + context.get_name());
+        auto src_len = std::make_shared<ov::op::v8::Gather>(
+            std::make_shared<ov::op::v3::ShapeOf>(src, ov::element::i64), axis,
+            ov::op::v0::Constant::create(ov::element::i64, {}, {0}));
+        auto end = std::make_shared<ov::op::v1::Add>(begin, src_len);
+        auto head_part = std::make_shared<ov::op::v8::Slice>(base, zero, begin, one, axis);
+        auto tail_part = std::make_shared<ov::op::v8::Slice>(base, end, int_max, one, axis);
+        auto updated = std::make_shared<ov::op::v0::Concat>(ov::OutputVector{head_part, src, tail_part}, 2);
+        return rename_outputs_with_suffix({src, updated}, context.get_name());
+    }
+
     if (op_case == 4) {
         auto src = process_view_input_new(context, 0);
         auto base = context.get_input(1);
diff --git a/ggml/src/ggml-openvino/openvino/op/scale.cpp b/ggml/src/ggml-openvino/openvino/op/scale.cpp
index f77d8ce58..e0d0ea182 100644
--- a/ggml/src/ggml-openvino/openvino/op/scale.cpp
+++ b/ggml/src/ggml-openvino/openvino/op/scale.cpp
@@ -4,6 +4,7 @@

 #include <openvino/op/add.hpp>
 #include <openvino/op/constant.hpp>
+#include <openvino/op/convert.hpp>
 #include <openvino/op/multiply.hpp>
 #include <vector>

@@ -26,15 +27,20 @@ OutputVector translate_scale(const NodeContext & context) {
         return translate_recurrent_cache_reset(context);
     }

-    auto scaled = std::make_shared<ov::op::v1::Multiply>(process_view_input_new(context, 0), scale_node);
-
-    std::shared_ptr<ov::Node> res;
+    // Multiply and Add need matching types; compute f16 input in f32 and round once, as the CPU backend does.
+    auto input = process_view_input_new(context, 0);
+    const auto input_type = input.get_element_type();
+    if (input_type != ov::element::f32) {
+        input = std::make_shared<ov::op::v0::Convert>(input, ov::element::f32);
+    }
+    ov::Output<ov::Node> res = std::make_shared<ov::op::v1::Multiply>(input, scale_node);
     if (bias != 0.0f) {
         auto bias_node =
             std::make_shared<ov::op::v0::Constant>(ov::element::f32, ov::Shape{}, std::vector<float>{bias});
-        res = std::make_shared<ov::op::v1::Add>(scaled, bias_node);
-    } else {
-        res = scaled;
+        res = std::make_shared<ov::op::v1::Add>(res, bias_node);
+    }
+    if (input_type != ov::element::f32) {
+        res = std::make_shared<ov::op::v0::Convert>(res, input_type);
     }

     return rename_outputs_with_suffix({res}, context.get_name());
diff --git a/ggml/src/ggml-openvino/openvino/op/selective_ssm.hpp b/ggml/src/ggml-openvino/openvino/op/selective_ssm.hpp
new file mode 100644
index 000000000..509b43e00
--- /dev/null
+++ b/ggml/src/ggml-openvino/openvino/op/selective_ssm.hpp
@@ -0,0 +1,42 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+// Local mirror of OpenVINO's ov::op::internal::SelectiveSSM declaration
+// (src/core/dev_api/openvino/op/selective_ssm.hpp). The implementation comes from the linked
+// OpenVINO runtime; the class layout must stay in sync with the runtime's declaration.
+#pragma once
+
+#include "openvino/op/op.hpp"
+
+namespace ov::op::internal {
+/// Mamba2 selective state-space recurrence (arXiv:2405.21060).
+/// dA = exp(A * dt), dtB = dt * B; per token t:
+/// dBx_t = x_t (x) dtB_t, state_t = state_{t-1} * dA_t + dBx_t, y_t = sum(state_t * C_t).
+/// B and C are grouped and shared across heads: head h reads group h / (num_heads / num_groups).
+class OPENVINO_API SelectiveSSM : public ov::op::Op {
+public:
+    OPENVINO_OP("SelectiveSSM")
+
+    SelectiveSSM() = default;
+    /// \param A (Negative) log-decay rates per head [num_heads].
+    /// \param dt Per-token, per-head time steps [batch_size, seq_len, num_heads].
+    /// \param B Grouped input projection [batch_size, seq_len, num_groups, state_size].
+    /// \param x Input hidden states [batch_size, seq_len, num_heads, head_dim].
+    /// \param C Grouped output projection [batch_size, seq_len, num_groups, state_size].
+    /// \param recurrent_state Initial state [batch_size, num_heads, head_dim, state_size].
+    SelectiveSSM(const Output<Node> & A,
+                 const Output<Node> & dt,
+                 const Output<Node> & B,
+                 const Output<Node> & x,
+                 const Output<Node> & C,
+                 const Output<Node> & recurrent_state);
+
+    /// \param args Input tensor vector in order: A, dt, B, x, C, recurrent_state.
+    explicit SelectiveSSM(const ov::OutputVector & args);
+
+    void validate_and_infer_types() override;
+    bool visit_attributes(AttributeVisitor & visitor) override;
+    std::shared_ptr<ov::Node> clone_with_new_inputs(const ov::OutputVector & new_args) const override;
+};
+
+}  // namespace ov::op::internal
diff --git a/ggml/src/ggml-openvino/openvino/op/set_rows.cpp b/ggml/src/ggml-openvino/openvino/op/set_rows.cpp
index 1eae9408b..476890911 100644
--- a/ggml/src/ggml-openvino/openvino/op/set_rows.cpp
+++ b/ggml/src/ggml-openvino/openvino/op/set_rows.cpp
@@ -90,12 +90,71 @@ static OutputVector translate_conv_snapshots(const NodeContext & context) {
     return rename_outputs_with_suffix({result}, name);
 }

+// SET_ROWS into a column range of a plain 2-D buffer (see GgmlOvDecoder::is_column_set_rows). The result is the
+// whole buffer: the indexed rows get the new columns, the other columns and rows keep their values, so the next
+// write into another column range of the same buffer reads this one.
+static OutputVector translate_column_set_rows(const NodeContext & context) {
+    using namespace ov::op;
+    auto i64_const = [](const std::vector<int64_t> & values) {
+        return v0::Constant::create(ov::element::i64, {values.size()}, values);
+    };
+
+    const auto view_shape = context.get_view_input_ggml_shape(2, 0);  // [1, 1, rows, width]
+    FRONT_END_OP_CONVERSION_CHECK(view_shape.size() == 4, "SET_ROWS column write needs a 4-D destination view");
+    const int64_t width = (int64_t) view_shape[3];
+
+    auto base = context.get_input(2);
+    const auto base_shape = base.get_partial_shape();
+    FRONT_END_OP_CONVERSION_CHECK(base_shape.rank().is_static() && base_shape[base_shape.size() - 1].is_static(),
+                                  "SET_ROWS column write needs a static buffer row size");
+    const int64_t row_size = base_shape[base_shape.size() - 1].get_length();
+    const size_t elem_size = context.get_output_type().size();
+    const int64_t col_begin = (int64_t) (context.get_view_input_offset(2, 0) / elem_size) % row_size;
+    const int64_t col_end = col_begin + width;
+    FRONT_END_OP_CONVERSION_CHECK(col_end <= row_size, "SET_ROWS column range is out of bounds");
+
+    Output<Node> data = std::make_shared<v1::Reshape>(process_view_input_new(context, 0), i64_const({1, 1, -1, width}),
+                                                      false);
+    if (data.get_element_type() != context.get_output_type()) {
+        data = std::make_shared<v0::Convert>(data, context.get_output_type());
+    }
+    Output<Node> rows = std::make_shared<v1::Reshape>(process_view_input_new(context, 1), i64_const({-1}), false);
+    if (rows.get_element_type() != ov::element::i64) {
+        rows = std::make_shared<v0::Convert>(rows, ov::element::i64);
+    }
+
+    auto axis = v0::Constant::create(ov::element::i64, {}, {2});
+    auto buffer = std::make_shared<v1::Reshape>(base, i64_const({1, 1, -1, row_size}), false);
+    Output<Node> updates = data;
+    if (width < row_size) {
+        auto existing = std::make_shared<v8::Gather>(buffer, rows, axis);
+        auto col_axis = i64_const({3});
+        OutputVector parts;
+        if (col_begin > 0) {
+            parts.push_back(std::make_shared<v8::Slice>(existing, i64_const({0}), i64_const({col_begin}),
+                                                        i64_const({1}), col_axis));
+        }
+        parts.push_back(data);
+        if (col_end < row_size) {
+            parts.push_back(std::make_shared<v8::Slice>(existing, i64_const({col_end}), i64_const({row_size}),
+                                                        i64_const({1}), col_axis));
+        }
+        updates = std::make_shared<v0::Concat>(parts, 3);
+    }
+    auto updated = std::make_shared<v3::ScatterUpdate>(buffer, rows, updates, axis);
+    auto res = std::make_shared<v1::Reshape>(updated, std::make_shared<v3::ShapeOf>(base, ov::element::i64), false);
+    return rename_outputs_with_suffix({res}, context.get_name());
+}
+
 OutputVector translate_set_rows(const NodeContext & context) {
     num_inputs_check(context, 3, 3);

     if (context.get_op_case() == 3) {
         return translate_conv_snapshots(context);
     }
+    if (context.get_op_case() == 4) {
+        return translate_column_set_rows(context);
+    }

     auto data = process_view_input_new(context, 0);
     auto indices = process_view_input_new(context, 1);
diff --git a/ggml/src/ggml-openvino/openvino/op/ssm_scan.cpp b/ggml/src/ggml-openvino/openvino/op/ssm_scan.cpp
new file mode 100644
index 000000000..fce8e111e
--- /dev/null
+++ b/ggml/src/ggml-openvino/openvino/op/ssm_scan.cpp
@@ -0,0 +1,63 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+// Adapted from OpenVINO's GGUF frontend (src/frontends/gguf/src/op/ssm_scan.cpp).
+
+#include "../node_context.h"
+#include "../op_table.h"
+#include "../utils.h"
+#include "selective_ssm.hpp"
+
+#include <openvino/op/concat.hpp>
+#include <openvino/op/constant.hpp>
+#include <openvino/op/gather.hpp>
+#include <openvino/op/reshape.hpp>
+#include <openvino/op/shape_of.hpp>
+#include <openvino/op/softplus.hpp>
+
+namespace ov {
+namespace frontend {
+namespace ggml {
+namespace op {
+
+OutputVector translate_ssm_scan(const NodeContext & context) {
+    num_inputs_check(context, 7, 7);
+    using namespace ov::op;
+
+    // ggml: s [slots,H,D,S], x [B,T,H,D], dt [1,B,T,H], A [1,1,H,1],
+    // B/C [B,T,G,S], ids [1,1,1,B]. Only Mamba2 has scalar decay per head.
+    const auto a_shape = context.get_input_shape(3);
+    FRONT_END_OP_CONVERSION_CHECK(a_shape.rank() == 4 && a_shape[0] == 1 && a_shape[1] == 1 && a_shape[3] == 1,
+                                  "SSM_SCAN: SelectiveSSM requires Mamba2 scalar decay per head; "
+                                  "Mamba1 state-wise decay is not supported");
+    const auto x = process_view_input_new(context, 1);
+    const auto flat = v0::Constant::create(element::i64, {1}, {-1});
+    const auto axis0 = v0::Constant::create(element::i64, {}, {0});
+    const auto ids = std::make_shared<v1::Reshape>(process_view_input_new(context, 6), flat, false);
+    const auto state = std::make_shared<v8::Gather>(process_view_input_new(context, 0), ids, axis0);
+    const auto a = std::make_shared<v1::Reshape>(process_view_input_new(context, 3), flat, false);
+    const auto dt_shape = std::make_shared<v8::Gather>(std::make_shared<v3::ShapeOf>(x),
+                                                       v0::Constant::create(element::i64, {3}, {0, 1, 2}),
+                                                       axis0);
+    const auto dt =
+        std::make_shared<v4::SoftPlus>(std::make_shared<v1::Reshape>(process_view_input_new(context, 2), dt_shape, false));
+    const auto ssm = std::make_shared<internal::SelectiveSSM>(a,
+                                                              dt,
+                                                              process_view_input_new(context, 4),
+                                                              x,
+                                                              process_view_input_new(context, 5),
+                                                              state);
+    // Pack directly in GGML layout so whole-part views can select either Concat input.
+    const auto packed_shape = v0::Constant::create(element::i64, {4}, {1, 1, 1, -1});
+    const auto y = std::make_shared<v1::Reshape>(ssm->output(0), packed_shape, false);
+    const auto s = std::make_shared<v1::Reshape>(ssm->output(1), packed_shape, false);
+    const auto result = std::make_shared<v0::Concat>(OutputVector{y, s}, 3);
+    result->get_rt_info()[GGML_OV_SSM_SCAN_PACKED] = true;
+    return rename_outputs_with_suffix({result}, context.get_name());
+}
+
+}  // namespace op
+}  // namespace ggml
+}  // namespace frontend
+}  // namespace ov
+
diff --git a/ggml/src/ggml-openvino/openvino/op/tri.cpp b/ggml/src/ggml-openvino/openvino/op/tri.cpp
index 9b7774a38..ba2efdc0b 100644
--- a/ggml/src/ggml-openvino/openvino/op/tri.cpp
+++ b/ggml/src/ggml-openvino/openvino/op/tri.cpp
@@ -70,7 +70,8 @@ OutputVector translate_tri(const NodeContext & context) {
             throw std::runtime_error("translate_tri: invalid tri_type " + std::to_string(tri_type));
     }

-    auto zero = ov::op::v0::Constant::create(ov::element::f32, {}, {0.0f});
+    // Select needs the zero in the input's type (f32, f16 or bf16).
+    auto zero = ov::op::v0::Constant::create(x.get_element_type(), {}, {0.0f});
     auto res  = std::make_shared<ov::op::v1::Select>(mask, x, zero);

     return rename_outputs_with_suffix({res}, context.get_name());
diff --git a/ggml/src/ggml-openvino/openvino/op_table.cpp b/ggml/src/ggml-openvino/openvino/op_table.cpp
index 399c17ac0..defc428d1 100644
--- a/ggml/src/ggml-openvino/openvino/op_table.cpp
+++ b/ggml/src/ggml-openvino/openvino/op_table.cpp
@@ -98,6 +98,7 @@ std::unordered_map<std::string, CreatorFunction> get_supported_ops() {
         {"GGML_OP_PAD",             op::translate_pad                              },
         {"GGML_OP_TOP_K",           op::translate_top_k                            },
         {"GGML_OP_SSM_CONV",        op::translate_ssm_conv                         },
+        {"GGML_OP_SSM_SCAN",        op::translate_ssm_scan                         },
         {"GGML_OP_GATED_DELTA_NET", op::translate_gated_delta_net                  },
         {"GGML_OP_REPEAT",          op::translate_repeat                           },
         {"GGML_OP_CUMSUM",          op::translate_cumsum                           },
diff --git a/ggml/src/ggml-openvino/openvino/op_table.h b/ggml/src/ggml-openvino/openvino/op_table.h
index 206966a93..54c60c634 100644
--- a/ggml/src/ggml-openvino/openvino/op_table.h
+++ b/ggml/src/ggml-openvino/openvino/op_table.h
@@ -49,6 +49,7 @@ GGML_OP_CONVERTER(translate_flash_attn_ext);
 GGML_OP_CONVERTER(translate_clamp);
 GGML_OP_CONVERTER(translate_pad);
 GGML_OP_CONVERTER(translate_ssm_conv);
+GGML_OP_CONVERTER(translate_ssm_scan);
 GGML_OP_CONVERTER(translate_gated_delta_net);
 #ifdef GGML_OPENVINO_HAS_CACHE_UPDATE
 OutputVector translate_recurrent_gated_delta_net(const NodeContext & context, const OutputVector & cache_inputs);
diff --git a/ggml/src/ggml-openvino/openvino/utils.cpp b/ggml/src/ggml-openvino/openvino/utils.cpp
index ec7513951..e82a6c92f 100644
--- a/ggml/src/ggml-openvino/openvino/utils.cpp
+++ b/ggml/src/ggml-openvino/openvino/utils.cpp
@@ -465,6 +465,25 @@ ov::Output<ov::Node> process_view_input_new(const NodeContext & context, int inp
         return input;
     }

+    // A VIEW over the packed SSM_SCAN output selects one whole Concat part: y at offset 0, the
+    // final state after it. The y length is token-dependent, so a static Slice of the flat
+    // tensor would bake in the captured token count; return the native part instead.
+    if (view_input_size == 1 && input.get_node_shared_ptr()->get_rt_info().count(GGML_OV_SSM_SCAN_PACKED)) {
+        const bool is_y = context.get_view_input_offset(input_index, 0) == 0;
+        auto part = input.get_node_shared_ptr()->input_value(is_y ? 0 : 1).get_node_shared_ptr()->input_value(0);
+        if (is_y) {
+            // y keeps its native [n_seqs, n_tokens, n_head, head_dim] layout
+            return part;
+        }
+        // state [n_seqs, n_head, head_dim, d_state] -> view layout [1, 1, n_seqs, d_state * d_inner]
+        auto n_seqs = get_dimensions(std::make_shared<ov::op::v3::ShapeOf>(part, ov::element::i64), {0});
+        auto target = std::make_shared<ov::op::v0::Concat>(
+            ov::OutputVector{ov::op::v0::Constant::create(ov::element::i64, {2}, {1, 1}), n_seqs,
+                             ov::op::v0::Constant::create(ov::element::i64, {1}, {-1})},
+            0);
+        return std::make_shared<ov::op::v1::Reshape>(part, target, false);
+    }
+
     // Integer router views can share these strides when their row count is zero.
     // Packed projections can store query and gate in separate halves of each head.
     if (!context.is_static() && view_input_size == 1 && input.get_element_type().is_real()) {
@@ -534,6 +553,70 @@ ov::Output<ov::Node> process_view_input_new(const NodeContext & context, int inp
         }
     }

+    // A VIEW that regroups one contiguous span of every source row, e.g. the z/x/B/C splits of the
+    // fused mamba projections: [head_dim, n_head, nt, ns] over [d_in_proj, nt, ns] rows. The span
+    // dims are packed and the remaining dims carry the source's outer strides, so the view is a
+    // Slice of the source's innermost axis plus a Reshape.
+    if (!context.is_static() && view_input_size == 1 && input.get_element_type().is_real()) {
+        const auto source = context.get_view_input_src_ggml_shape(input_index, 0);
+        const auto view = context.get_view_input_ggml_shape(input_index, 0);
+        const auto source_stride = context.get_view_input_src_stride(input_index, 0);
+        const auto view_stride = context.get_view_input_stride(input_index, 0);
+        const auto in_rank = input.get_partial_shape().rank();
+        const size_t nd = view.size();
+        if (nd == 4 && source.size() == nd && view_stride.size() == nd && source_stride.size() == nd &&
+            in_rank.is_static() && in_rank.get_length() == static_cast<int64_t>(nd) &&
+            view_stride[nd - 1] == source_stride[nd - 1] && source_stride[nd - 1] > 0) {
+            const size_t es = source_stride[nd - 1];
+            int j = static_cast<int>(nd) - 1;
+            size_t span = 1;
+            while (j >= 0 && view_stride[j] == span * es) {
+                span *= view[j];
+                --j;
+            }
+            // at least two packed dims replace the source's innermost dim; a one-dim span keeps the
+            // source rank and is handled by the generic paths below
+            const int shift = static_cast<int>(nd) - 2 - j;
+            bool matches = j >= 0 && shift >= 1;
+            for (int t = 0; matches && t <= j; ++t) {
+                matches = view[t] == source[t + shift] && view_stride[t] == source_stride[t + shift];
+            }
+            for (int t = 0; matches && t < shift; ++t) {
+                matches = source[t] == 1;
+            }
+            const size_t offset = context.get_view_input_offset(input_index, 0);
+            const size_t src_offset = context.get_view_input_src_offset(input_index, 0);
+            if (matches && offset >= src_offset && (offset - src_offset) % es == 0) {
+                const int64_t begin = static_cast<int64_t>((offset - src_offset) / es);
+                if (begin + static_cast<int64_t>(span) <= static_cast<int64_t>(source[nd - 1])) {
+                    auto sliced = std::make_shared<ov::op::v8::Slice>(
+                        input, ov::op::v0::Constant::create(ov::element::i64, {1}, {begin}),
+                        ov::op::v0::Constant::create(ov::element::i64, {1}, {begin + static_cast<int64_t>(span)}),
+                        ov::op::v0::Constant::create(ov::element::i64, {1}, {1}),
+                        ov::op::v0::Constant::create(ov::element::i64, {1}, {static_cast<int64_t>(nd) - 1}));
+                    const auto view_ov_shape = context.get_view_input_ov_shape(input_index, 0);
+                    std::vector<int64_t> pattern(nd);
+                    size_t dynamic_dims = 0;
+                    for (size_t i = 0; i < nd; ++i) {
+                        if (view_ov_shape.rank().is_static() && view_ov_shape[i].is_static()) {
+                            pattern[i] = view_ov_shape[i].get_length();
+                        } else {
+                            pattern[i] = -1;
+                            ++dynamic_dims;
+                        }
+                    }
+                    if (dynamic_dims > 1) {
+                        for (size_t i = 0; i < nd; ++i) {
+                            pattern[i] = static_cast<int64_t>(view[i]);
+                        }
+                    }
+                    return std::make_shared<ov::op::v1::Reshape>(
+                        sliced, ov::op::v0::Constant::create(ov::element::i64, {nd}, pattern), false);
+                }
+            }
+        }
+    }
+
     // A row range of a 2D weight (BERT's token type row): slice the rows of the [rows, row_size] Constant
     if (view_input_size == 1 && input.get_partial_shape().rank().is_static() &&
         input.get_partial_shape().rank().get_length() == 2 &&
@@ -671,14 +754,17 @@ ov::Output<ov::Node> process_view_input_new(const NodeContext & context, int inp
                         exact_chunk = i == static_cast<size_t>(split_dim) || view_ggml_shape[i] == 1 ||
                                       view_stride_v[i] == view_src_stride_v[i];
                     }
-                    // stateful execution drops the leading size-1 axis, so the input can be one rank lower than the
-                    // ggml metadata
-                    const auto input_rank = input.get_partial_shape().rank();
-                    const int64_t rank_shift = input_rank.is_static() ?
-                                                   static_cast<int64_t>(ndims) - input_rank.get_length() :
-                                                   static_cast<int64_t>(ndims);
+                    // num_splits is the captured source size: on a dynamic axis (e.g. the token axis of DSpark's
+                    // result_norm, read one block position at a time) the graph is reused with other sizes, and
+                    // each Split output would then hold several rows or the wrong one
+                    const auto input_shape = input.get_partial_shape();
+                    const int64_t split_axis = input_shape.rank().is_static() ?
+                                                   split_dim - (int64_t) ndims + input_shape.rank().get_length() :
+                                                   -1;
+                    const bool split_axis_static = split_axis >= 0 && input_shape[split_axis].is_static() &&
+                                                   input_shape[split_axis].get_length() == num_splits;
                     if (split_index >= 0 && split_index < num_splits && dynamic_split && exact_chunk &&
-                        split_dim >= rank_shift) {
+                        split_axis_static) {
                         // the Split keeps its input alive, so only keep a weak reference to it on the input
                         auto src_node = input.get_node_shared_ptr();
                         std::string rt_key =
@@ -689,8 +775,7 @@ ov::Output<ov::Node> process_view_input_new(const NodeContext & context, int inp
                             split_node = rt_info[rt_key].as<std::weak_ptr<ov::Node>>().lock();
                         }
                         if (split_node == nullptr) {
-                            auto axis_const = ov::op::v0::Constant::create(
-                                ov::element::i64, {}, {static_cast<int64_t>(split_dim) - rank_shift});
+                            auto axis_const = ov::op::v0::Constant::create(ov::element::i64, {}, {split_axis});
                             split_node =
                                 std::make_shared<ov::op::v1::Split>(input, axis_const, static_cast<size_t>(num_splits));
                             split_node->set_friendly_name(src_node->get_friendly_name() + "_split");
@@ -722,7 +807,8 @@ ov::Output<ov::Node> process_view_input_new(const NodeContext & context, int inp

     // Lambda function to process a single view operation
     auto process_single_view =
-        [](ov::Output<ov::Node> current, size_t view_offset, const std::vector<size_t> & view_stride,
+        [is_static = context.is_static()](
+           ov::Output<ov::Node> current, size_t view_offset, const std::vector<size_t> & view_stride,
            const ov::Shape & view_ggml_shape, const ov::PartialShape & view_ov_shape, const std::string & view_name,
            size_t view_src_offset, const std::vector<size_t> & view_src_stride, const ov::Shape & view_src_ggml_shape,
            const ov::PartialShape & view_src_ov_shape, const std::string & view_src_name) -> ov::Output<ov::Node> {
@@ -847,7 +933,12 @@ ov::Output<ov::Node> process_view_input_new(const NodeContext & context, int inp
                             ov::op::v0::Constant::create(ov::element::i64, {1}, {1}),
                             ov::op::v0::Constant::create(ov::element::i64, {1}, {slice_dim - axis_shift}));

-                        if (view_ov_shape.is_static()) {
+                        // In a static graph a rank-preserving slice (diff_dims has one entry) already has the view
+                        // shape. Skip the Reshape: its target bakes the static chunk size into the token axis, which
+                        // is wrong after the output-ids GET_ROWS of the last layer (1 token in the prefill graph).
+                        const bool rank_kept = is_static && current_rank.is_static() &&
+                                               static_cast<size_t>(current_rank.get_length()) == ndims;
+                        if (view_ov_shape.is_static() && !rank_kept) {
                             auto reshaped = std::make_shared<ov::op::v1::Reshape>(
                                 sliced,
                                 ov::op::v0::Constant::create(ov::element::i64, {ndims}, view_ov_shape.to_shape()),
diff --git a/ggml/src/ggml-openvino/openvino/utils.h b/ggml/src/ggml-openvino/openvino/utils.h
index 10344675b..aaee05116 100644
--- a/ggml/src/ggml-openvino/openvino/utils.h
+++ b/ggml/src/ggml-openvino/openvino/utils.h
@@ -97,6 +97,9 @@ constexpr const char * GGML_OV_GROUPED_ROWS = "ggml_ov_grouped_rows";
 // rt_info key on the stateful V cache read with `-fa off` (permute): V is [.., kv, head_size], not transposed
 constexpr const char * GGML_OV_V_TOKEN_MAJOR = "ggml_ov_v_token_major";

+// rt_info key on the packed SSM_SCAN output Concat [1, 1, 1, y | state]; whole-part VIEWs select one Concat input
+constexpr const char * GGML_OV_SSM_SCAN_PACKED = "ggml_ov_ssm_scan_packed";
+
 namespace op {
 template <typename T> OutputVector translate_1to1_match_2_inputs(const NodeContext & context) {
     num_inputs_check(context, 2, 2);
diff --git a/ggml/src/ggml-openvino/utils.cpp b/ggml/src/ggml-openvino/utils.cpp
index 7c5f6b756..c959ce0d9 100644
--- a/ggml/src/ggml-openvino/utils.cpp
+++ b/ggml/src/ggml-openvino/utils.cpp
@@ -657,6 +657,30 @@ ov::Tensor convert_ggml_input_to_ov(const std::shared_ptr<GgmlOvDecoder> & ggml_
         return *sliced;
     }

+    // KQ mask with fewer columns than the rounded KV length (see compute_llm_params): pad it with -inf
+    const auto & compute_params = ggml_decoder->get_compute_params();
+    if (!ggml_decoder->is_static() && name == compute_params.mask_name &&
+        compute_params.attention_size > ggml_tensor->ne[0] && ggml_is_contiguous(ggml_tensor)) {
+        const size_t rows = ggml_nrows(ggml_tensor);
+        const size_t cols = ggml_tensor->ne[0];
+        const size_t padded_cols = compute_params.attention_size;
+        ov::Shape shape = GgmlOvDecoder::get_shape(ggml_tensor);
+        shape.back() = padded_cols;
+        ov::Tensor padded(GgmlOvDecoder::get_ov_type(ggml_tensor), shape);
+        auto pad = [&](auto fill) {
+            using T = decltype(fill);
+            auto data = pad_input<T>((const T *) ggml_tensor->data, rows, cols, rows, padded_cols, fill);
+            std::memcpy(padded.data(), data.data(), padded.get_byte_size());
+        };
+        if (ggml_tensor->type == GGML_TYPE_F16) {
+            pad(GGML_FP32_TO_FP16(-INFINITY));
+        } else {
+            GGML_ASSERT(ggml_tensor->type == GGML_TYPE_F32);
+            pad(-INFINITY);
+        }
+        return padded;
+    }
+
     if (ggml_decoder->is_static() &&
         GgmlOvDecoder::is_kvcache(ggml_tensor, ggml_decoder->get_tensor_used_op(ggml_tensor))) {
         const auto type = ggml_decoder->get_ov_type(ggml_tensor);
@@ -2192,8 +2216,21 @@ enum ggml_status ov_graph_compute_static(ggml_cgraph * cgraph, const std::shared
         old_m_params = ggml_decoder->get_model_params();
         cache_hit = old_m_params.can_reuse_statically(m_params);
         if (cache_hit && is_prefill && ggml_openvino_kv_slice_enabled()) {
-            cache_hit = entry->prefill_attention_size == c_params.attention_size &&
-                        entry->prefill_attention_size_swa == c_params.attention_size_swa;
+            // A larger compiled prefill also serves a smaller attended length: the extra KV rows are masked, as with
+            // the power-of-two rounding. Without this, a new prompt walks up the sizes again, and since only one
+            // prefill model is kept, every prompt longer than one chunk recompiles. Head-major KV is bound at the
+            // storage size, so it keeps the exact match.
+            // The output count is part of the static prefill shape (more than 1 only for llama-perplexity).
+            const bool reuse_larger = !ggml_openvino_npu_kv_head_major_enabled();
+            cache_hit = entry->prefill_output_len == c_params.output_len &&
+                        (reuse_larger ? entry->prefill_attention_size >= c_params.attention_size &&
+                                            entry->prefill_attention_size_swa >= c_params.attention_size_swa :
+                                        entry->prefill_attention_size == c_params.attention_size &&
+                                            entry->prefill_attention_size_swa == c_params.attention_size_swa);
+            if (cache_hit) {
+                c_params.attention_size = entry->prefill_attention_size;
+                c_params.attention_size_swa = entry->prefill_attention_size_swa;
+            }
             prefill_size_changed = !cache_hit;
         }
     }
@@ -2260,6 +2297,7 @@ enum ggml_status ov_graph_compute_static(ggml_cgraph * cgraph, const std::shared
             entry->ptr = ggml_decoder;
             entry->prefill_attention_size = c_params.attention_size;
             entry->prefill_attention_size_swa = c_params.attention_size_swa;
+            entry->prefill_output_len = c_params.output_len;
             entry->decode_attention_size = compiled.decode_attention_size;
             entry->shared_key = shared_key;
             entry->decode_window_requests.clear();
@@ -2274,6 +2312,10 @@ enum ggml_status ov_graph_compute_static(ggml_cgraph * cgraph, const std::shared
             r_ctx->ov_output_names_cache_prefill[key] = compiled.prefill_output_names;
             decoder_end_time = conversion_end_time = compile_end_time = ggml_time_us();
             GGML_LOG_DEBUG("ggml-openvino: shared compiled model HIT (static)\n");
+            if (prefill_size_changed) {
+                GGML_LOG_INFO("ggml-openvino: reuse the compiled prefill model of attention size %d\n",
+                              c_params.attention_size);
+            }
         } else {
             auto decode_c_params = c_params;
             if (ggml_openvino_kv_slice_enabled()) {
@@ -2600,6 +2642,7 @@ enum ggml_status ov_graph_compute_static(ggml_cgraph * cgraph, const std::shared
             entry->ptr = ggml_decoder;
             entry->prefill_attention_size = c_params.attention_size;
             entry->prefill_attention_size_swa = c_params.attention_size_swa;
+            entry->prefill_output_len = c_params.output_len;
             entry->decode_attention_size = decode_c_params.attention_size;
             entry->shared_key = shared_key;
             entry->decode_window_requests.clear();
@@ -3180,7 +3223,7 @@ enum ggml_status ov_graph_compute(ggml_cgraph * cgraph, ggml_backend_t backend)
             GgmlOvDecoder::dump_cgraph(cgraph, filename);
         }

-        const auto is_static = ggml_openvino_is_npu() || ggml_openvino_getenv_int("GGML_OPENVINO_FORCE_STATIC");
+        const auto is_static = ggml_openvino_is_static();

         GGML_ASSERT(ctx->runtime_context != nullptr);
         std::shared_ptr<ov_runtime_context> r_ctx = std::static_pointer_cast<ov_runtime_context>(ctx->runtime_context);
diff --git a/ggml/src/ggml-openvino/utils.h b/ggml/src/ggml-openvino/utils.h
index 31fa7abc2..c4450a387 100644
--- a/ggml/src/ggml-openvino/utils.h
+++ b/ggml/src/ggml-openvino/utils.h
@@ -42,6 +42,11 @@ struct graph_key {
             if (GgmlOvDecoder::is_sampling_view(node)) {
                 input_srcs.push_back("sampling_row_" + std::string(node->name) + "#n" + std::to_string(i));
             }
+            // The output set is part of the model (one Result per output). Enabling outputs on an existing graph,
+            // e.g. llama_set_embeddings_layer_inp() for a DFlash/DSpark drafter, changes only the flags.
+            if (node->flags & GGML_TENSOR_FLAG_OUTPUT) {
+                input_srcs.push_back("output_" + std::string(node->name) + "#n" + std::to_string(i));
+            }
         }

         static const bool full_key = ggml_openvino_getenv_int("GGML_OPENVINO_FULL_GRAPH_KEY") != 0;
@@ -95,9 +100,11 @@ struct decoder_runtime_ctx {

     std::shared_ptr<std::mutex> mutex;
     std::shared_ptr<GgmlOvDecoder> ptr;
-    // Attention sizes the cached prefill model was built with; decode calls overwrite the decoder's.
+    // Attention sizes and output count the cached prefill model was built with; decode calls overwrite the
+    // decoder's.
     int prefill_attention_size = -1;
     int prefill_attention_size_swa = -1;
+    int prefill_output_len = -1;
     // KV window of the decode model in the compiled pair (GGML_OPENVINO_NPU_BLOB_PREBUILD).
     int decode_attention_size = -1;
     std::string shared_key;