Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[GGUF] Integrate llama.cpp backend changes in the frontend (#37869)

Maxim Vafinca7fd94ec330
diff --git a/.github/workflows/job_gguf_llamacpp_validation.yml b/.github/workflows/job_gguf_llamacpp_validation.yml
index d1685e981e6..b6e9c940267 100644
--- a/.github/workflows/job_gguf_llamacpp_validation.yml
+++ b/.github/workflows/job_gguf_llamacpp_validation.yml
@@ -28,7 +28,7 @@ env:
# ggml-openvino decoder/backend fixes this frontend snapshot requires. Bump alongside any
# GGUF-frontend change that needs a matching llama.cpp-side update.
LLAMA_CPP_REPO: mvafin/llama.cpp
- LLAMA_CPP_REF: 16fb7d9d326a3fe69a331ce5fbe7a679a1a281bb
+ LLAMA_CPP_REF: 3d677aadec0487430ad59bd3d4a9fc7211721f0f
INSTALL_DIR: ${{ github.workspace }}/install
SCCACHE_DIR: ${{ github.workspace }}/.sccache
@@ -100,8 +100,22 @@ jobs:
OV_GGUF_Q4_K_ZP_F16: "1"
run: |
source ${{ env.INSTALL_DIR }}/setupvars.sh
- # test-llama-archs needs an arch fixture this frontend snapshot doesn't carry; excluded
- # to match llama.cpp's own upstream CI (see ci/run.sh) until that lands separately.
+ # Keep the operator suite enabled. The pinned llama.cpp revision also labels its
+ # all-architecture state suite and multi-sequence recurrent rollback tests as main.
+ # Those exercise unsupported backend layouts (Qwen3.5 multi-sequence replay,
+ # Nemotron-H packed SSM state, and DeepSeek V4); validate supported state paths below.
ctest --test-dir llama.cpp/build -L main \
- -E "test-opt|test-llama-archs" \
+ -E '^test-(opt|llama-archs|recurrent-state-rollback(-nemotron-h|-dsv4)?|save-load-state)$' \
--output-on-failure --timeout 2000
+
+ - name: Validate state save/load on supported llama.cpp models
+ env:
+ OV_GGUF_Q4_K_ZP_F16: "1"
+ run: |
+ source ${{ env.INSTALL_DIR }}/setupvars.sh
+ # Generated by test-generate-models above. Run every state scenario in single-model
+ # mode instead of sweeping architectures the ggml-openvino backend cannot execute.
+ for model in llama-dense qwen2-dense qwen3-dense; do
+ timeout 2000 llama.cpp/build/bin/test-save-load-state \
+ -m "llama.cpp/build/tests/test-models/${model}.gguf"
+ done
diff --git a/src/frontends/gguf/docs/how_to_add_op.md b/src/frontends/gguf/docs/how_to_add_op.md
index 8021d134838..afaeb917f71 100644
--- a/src/frontends/gguf/docs/how_to_add_op.md
+++ b/src/frontends/gguf/docs/how_to_add_op.md
@@ -85,6 +85,17 @@ and this parameter. For compatibility, decoders that omit `k` must supply a stat
output dimension, where ggml stores `k`. An unknown `k` is rejected, never inferred from
the input width.
+`ROPE` accepts an optional `int64_t` attribute `rope_offset` (default zero), matching
+`ggml_rope_set_offset`: rotate `n_dims` channels starting at that even offset and preserve
+the prefix and tail of each head.
+
+`FLASH_ATTN_EXT` accepts an optional boolean `sink_without_mask` attribute for a decoder
+that compacts null ggml sources: set it when `src[3]` is null and `src[4]` contains
+attention sinks, leaving four input tensors. The cgraph convention of naming that
+weight `*.attn_sinks.weight` is also recognized. Otherwise the fourth tensor is
+treated as an attention mask; its shape and element type cannot distinguish a
+mask from sinks (an F32 mask can have the same shape as a sink).
+
Converters must infer intermediate shapes from their OpenVINO operands, reading only the axes
needed for the operation. A dynamic token axis does not prevent reading a static head width.
Use explicit attributes for operation parameters: `reshape_target` / `special_zero`, `view_slice`,
diff --git a/src/frontends/gguf/src/op/add.cpp b/src/frontends/gguf/src/op/add.cpp
new file mode 100644
index 00000000000..c673f68636f
--- /dev/null
+++ b/src/frontends/gguf/src/op/add.cpp
@@ -0,0 +1,32 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "openvino/op/add.hpp"
+
+#include <memory>
+
+#include "node_context.hpp"
+#include "op_table.hpp"
+#include "openvino/op/convert.hpp"
+#include "utils.hpp"
+
+namespace ov::frontend::gguf::op {
+
+OutputVector translate_add(const NodeContext& context) {
+ num_inputs_check(context, 2, 2);
+ auto lhs = context.get_input(0);
+ auto rhs = context.get_input(1);
+ const auto output_type = lhs.get_element_type();
+ if (output_type != rhs.get_element_type()) {
+ lhs = std::make_shared<ov::op::v0::Convert>(lhs, ov::element::f32);
+ rhs = std::make_shared<ov::op::v0::Convert>(rhs, ov::element::f32);
+ }
+ Output<Node> result = std::make_shared<ov::op::v1::Add>(lhs, rhs);
+ if (result.get_element_type() != output_type) {
+ result = std::make_shared<ov::op::v0::Convert>(result, output_type);
+ }
+ return rename_outputs_with_suffix({std::move(result)}, context.get_name());
+}
+
+} // namespace ov::frontend::gguf::op
diff --git a/src/frontends/gguf/src/op/cont.cpp b/src/frontends/gguf/src/op/cont.cpp
index 0fae905ed65..2021ed406be 100644
--- a/src/frontends/gguf/src/op/cont.cpp
+++ b/src/frontends/gguf/src/op/cont.cpp
@@ -22,13 +22,27 @@ OutputVector translate_cont(const NodeContext& context) {
ov::Output<Node> res;
- if (op_case == 1) {
- // Input from PERMUTE: translate_permute already emitted a real Transpose, so the OV tensor
- // is logically contiguous -- CONT (a ggml memory-contiguity op) is a no-op for us.
- return {context.get_input(0)};
- } else if (op_case == 2) {
- // The input comes from a TRANSPOSE
- return {context.get_input(0)};
+ if (op_case == 1 || op_case == 2) {
+ // PERMUTE/TRANSPOSE is already materialized as an OV Transpose, but ggml CONT may also
+ // collapse dimensions (attention heads are commonly flattened before the output
+ // projection). Preserve that logical output shape instead of returning the transposed
+ // tensor with an extra head axis.
+ auto input = context.get_input(0);
+ auto tgt = context.get_attribute<std::vector<int64_t>>("cont_reshape", {});
+ const auto output_shape = context.get_output_shape();
+ // Without output metadata or a target, CONT preserves the input shape.
+ if ((output_shape.rank().is_static() && input.get_partial_shape().same_scheme(output_shape)) ||
+ (output_shape.rank().is_dynamic() && tgt.empty())) {
+ return {input};
+ }
+ FRONT_END_OP_CONVERSION_CHECK(!tgt.empty(),
+ "CONT from a transpose requires a \"cont_reshape\" target: input ",
+ input.get_partial_shape(),
+ " != output ",
+ context.get_output_shape());
+ res = std::make_shared<ov::op::v1::Reshape>(input,
+ ov::op::v0::Constant::create(ov::element::i64, {tgt.size()}, tgt),
+ false);
} else {
// The input comes from a VIEW. Resolve the view, then reshape to the CONT's own output layout
// (ggml_cont can merge/split dims, e.g. qwen3-next's a/b: [tok,8,2,1] -> [8*tok,2,1,1]). The
@@ -42,7 +56,8 @@ OutputVector translate_cont(const NodeContext& context) {
auto input = context.get_input(0);
auto tgt = context.get_attribute<std::vector<int64_t>>("cont_reshape", {});
// No target means pass-through, which is only valid if the shape is already the CONT's own.
- FRONT_END_OP_CONVERSION_CHECK(!tgt.empty() || input.get_partial_shape().compatible(context.get_output_shape()),
+ FRONT_END_OP_CONVERSION_CHECK(!tgt.empty() || context.get_output_shape().rank().is_dynamic() ||
+ input.get_partial_shape().same_scheme(context.get_output_shape()),
"CONT from a VIEW requires a \"cont_reshape\" target: input ",
input.get_partial_shape(),
" != output ",
@@ -51,9 +66,11 @@ OutputVector translate_cont(const NodeContext& context) {
auto tgt_node = ov::op::v0::Constant::create(ov::element::i64, {tgt.size()}, tgt);
res = std::make_shared<ov::op::v1::Reshape>(input, tgt_node, false);
res.get_node_shared_ptr()->set_friendly_name("cont_reshape_" + context.get_name());
- return rename_outputs_with_suffix({std::move(res)}, context.get_name());
}
- res = input;
+ if (!res.get_node_shared_ptr()) {
+ // A pass-through CONT must not rename the shared input producer.
+ return {input};
+ }
}
return rename_outputs_with_suffix({std::move(res)}, context.get_name());
diff --git a/src/frontends/gguf/src/op/cpy.cpp b/src/frontends/gguf/src/op/cpy.cpp
index 0b8e2a6fcf4..df2cd33b385 100644
--- a/src/frontends/gguf/src/op/cpy.cpp
+++ b/src/frontends/gguf/src/op/cpy.cpp
@@ -5,6 +5,7 @@
#include <climits>
#include <cstdint>
#include <memory>
+#include <numeric>
#include <vector>
#include "node_context.hpp"
@@ -62,6 +63,12 @@ OutputVector translate_cpy(const NodeContext& context) {
return {context.get_input(1)};
}
+ if (op_case == 5) {
+ // Empty recurrent compaction is a true no-op. Do not rename the shared cache producer:
+ // it can feed other nodes and its stable name is used by stateful passes/fingerprints.
+ return {context.get_input(1)};
+ }
+
if (op_case == 4) {
ov::Output<ov::Node> src = context.get_input(0);
auto base = context.get_input(1);
@@ -129,15 +136,26 @@ OutputVector translate_cpy(const NodeContext& context) {
src.get_node_shared_ptr()->set_friendly_name("gdn_writeback_source_" + context.get_name());
} else if (op_case == 2) {
const int64_t window_size = input_shape[3].get_length();
- auto src_begin = context.get_input("rs_src_begin_" + writeback_name);
- auto src_end =
- std::make_shared<ov::op::v1::Add>(src_begin,
- ov::op::v0::Constant::create(ov::element::i64, {1}, {window_size}));
- auto window = std::make_shared<ov::op::v8::Slice>(context.get_input(0),
- src_begin,
- src_end,
- one,
- ov::op::v0::Constant::create(ov::element::i64, {1}, {3}));
+ const std::string src_begin_name = "rs_src_begin_" + writeback_name;
+ ov::Output<ov::Node> window;
+ auto col_axis = ov::op::v0::Constant::create(ov::element::i64, {1}, {3});
+ if (context.has_input(src_begin_name)) {
+ auto src_begin = context.get_input(src_begin_name);
+ auto src_end = std::make_shared<ov::op::v1::Add>(
+ src_begin,
+ ov::op::v0::Constant::create(ov::element::i64, {1}, {window_size}));
+ window = std::make_shared<ov::op::v8::Slice>(context.get_input(0), src_begin, src_end, one, col_axis);
+ } else if (context.has_input("chunk_valid_len")) {
+ std::vector<int64_t> offsets(window_size);
+ std::iota(offsets.begin(), offsets.end(), 0);
+ auto indices = std::make_shared<ov::op::v1::Add>(
+ ov::op::v0::Constant::create(ov::element::i64, {static_cast<size_t>(window_size)}, offsets),
+ context.get_input("chunk_valid_len"));
+ window = std::make_shared<ov::op::v8::Gather>(context.get_input(0), indices, col_axis);
+ } else {
+ auto src_begin = ov::op::v0::Constant::create(ov::element::i64, {1}, {-window_size});
+ window = std::make_shared<ov::op::v8::Slice>(context.get_input(0), src_begin, int_max, one, col_axis);
+ }
src = reshape_writeback(window);
src.get_node_shared_ptr()->set_friendly_name("conv_writeback_source_" + context.get_name());
} else {
@@ -160,7 +178,24 @@ OutputVector translate_cpy(const NodeContext& context) {
return rename_outputs_with_suffix({std::move(res)}, context.get_name());
}
- ov::Output<ov::Node> res = std::make_shared<ov::op::v0::Convert>(context.get_input(0), type);
+ ov::Output<ov::Node> value = context.get_input(0);
+ if (op_case == 2) {
+ // A recurrent convolution update copies the trailing d_conv - 1 columns from the
+ // [state | current chunk] window. The VIEW carrying that slice can be folded out of the
+ // decoder graph, so recover the logical window from its declared shape before flattening
+ // it into the cache row. Slicing is also correct when the input has already been narrowed.
+ FRONT_END_OP_CONVERSION_CHECK(
+ input_shape.rank().is_static() && input_shape.rank().get_length() == 4 && input_shape[3].is_static(),
+ "Convolution-state CPY requires a static window width");
+ const auto window_size = input_shape[3].get_length();
+ value = std::make_shared<ov::op::v8::Slice>(value,
+ ov::op::v0::Constant::create(ov::element::i64, {1}, {-window_size}),
+ ov::op::v0::Constant::create(ov::element::i64, {1}, {INT_MAX}),
+ ov::op::v0::Constant::create(ov::element::i64, {1}, {1}),
+ ov::op::v0::Constant::create(ov::element::i64, {1}, {3}));
+ }
+
+ ov::Output<ov::Node> res = std::make_shared<ov::op::v0::Convert>(value, type);
// A CPY may reinterpret the source layout into its destination's (e.g. qwen3-next's conv-state
// writeback flattens the contiguous [S, F] conv_state_last into the flat [S*F] recurrent cache
diff --git a/src/frontends/gguf/src/op/diag.cpp b/src/frontends/gguf/src/op/diag.cpp
index 13c4a2002cf..5532c885f2a 100644
--- a/src/frontends/gguf/src/op/diag.cpp
+++ b/src/frontends/gguf/src/op/diag.cpp
@@ -4,41 +4,26 @@
#include <cstdint>
#include <memory>
-#include <vector>
#include "node_context.hpp"
#include "op_table.hpp"
#include "openvino/op/constant.hpp"
+#include "openvino/op/eye.hpp"
#include "openvino/op/multiply.hpp"
#include "utils.hpp"
namespace ov::frontend::gguf::op {
-// GGML_OP_DIAG turns a vector into a diagonal matrix: a ggml [ne0, 1, ne2, ne3] input becomes
-// [ne0, ne0, ne2, ne3] with output[..., i, j] = input[..., 0, j] when i == j, else 0.
-// In OV layout (ggml [ne0, ne1, ne2, ne3] -> OV [ne3, ne2, ne1, ne0]) the input is
-// [ne3, ne2, 1, ne0] and the output is [ne3, ne2, ne0, ne0]; the new row axis is OV axis 2.
-//
-// We multiply the input by a constant [1, 1, n, n] identity matrix: broadcasting spreads the input
-// over the new row axis and the identity zeroes off-diagonal entries. This avoids an Equal/Select
-// over a folded boolean constant, which the CPU Snippets body-hasher mishandles.
+// Broadcast a vector across the rows of an identity matrix.
OutputVector translate_diag(const NodeContext& context) {
num_inputs_check(context, 1, 1);
auto x = context.get_input(0); // OV shape: [ne3, ne2, 1, ne0]
- const auto shape = x.get_partial_shape();
- const size_t n = shape[shape.size() - 1].get_length();
-
- // Explicit [1, 1, n, n] identity matrix (1.0 on the diagonal, 0.0 elsewhere).
- std::vector<float> identity(n * n, 0.0f);
- for (size_t i = 0; i < n; ++i) {
- identity[i * n + i] = 1.0f;
- }
- // Build the mask in the node's own type, or an f16 input gets promoted to f32 by the Multiply.
- auto eye = ov::op::v0::Constant::create(x.get_element_type(), ov::Shape{1, 1, n, n}, identity);
+ auto n = get_dimensions(x, {-1});
+ auto zero = ov::op::v0::Constant::create(ov::element::i64, {}, {0});
+ auto eye = std::make_shared<ov::op::v9::Eye>(n, n, zero, x.get_element_type());
- // Multiply broadcasts the [ne3,ne2,1,ne0] input over the row axis, zeroing off-diagonal entries.
auto res = std::make_shared<ov::op::v1::Multiply>(x, eye);
return rename_outputs_with_suffix({std::move(res)}, context.get_name());
diff --git a/src/frontends/gguf/src/op/div.cpp b/src/frontends/gguf/src/op/div.cpp
index 5ad93e7c772..bc843d3a8a1 100644
--- a/src/frontends/gguf/src/op/div.cpp
+++ b/src/frontends/gguf/src/op/div.cpp
@@ -15,6 +15,7 @@
#include "openvino/op/multiply.hpp"
#include "openvino/op/shape_of.hpp"
#include "openvino/op/sigmoid.hpp"
+#include "openvino/op/swish.hpp"
#include "openvino/op/tile.hpp"
#include "openvino/op/util/precision_sensitive_attribute.hpp"
#include "utils.hpp"
@@ -23,13 +24,11 @@ namespace ov::frontend::gguf::op {
namespace {
-// Detect silu(x) / x, which simplifies to sigmoid(x). ggml emits this in qwen2moe's shared-expert
-// gate; computing it as a literal divide is a 0/0 NaN at x == 0. Rather than probe ggml op_params
-// for a SILU tag (which would pull ggml.h into the frontend), we match the numerator's graph shape:
-// our silu translator emits Multiply(x, Sigmoid(x)), so numerator == silu(denominator) exactly when
-// the Multiply's two inputs are the denominator and Sigmoid(denominator). A structural match here is
-// semantically silu(x)/x regardless of how ggml labeled the source op.
+// Fold silu(x) / x to sigmoid(x), including at x == 0.
bool is_silu_div_pattern(const ov::Output<ov::Node>& numerator, const ov::Output<ov::Node>& denominator) {
+ if (auto swish = ov::as_type_ptr<ov::op::v4::Swish>(numerator.get_node_shared_ptr())) {
+ return swish->get_input_size() == 1 && swish->input_value(0) == denominator;
+ }
auto mul = std::dynamic_pointer_cast<ov::op::v1::Multiply>(numerator.get_node_shared_ptr());
if (!mul) {
return false;
diff --git a/src/frontends/gguf/src/op/flash_attn_ext.cpp b/src/frontends/gguf/src/op/flash_attn_ext.cpp
index 1614656822e..2d34b395ba6 100644
--- a/src/frontends/gguf/src/op/flash_attn_ext.cpp
+++ b/src/frontends/gguf/src/op/flash_attn_ext.cpp
@@ -2,9 +2,11 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include <cmath>
#include <cstdint>
#include <memory>
#include <string>
+#include <vector>
#include "node_context.hpp"
#include "op_table.hpp"
@@ -33,17 +35,75 @@
namespace ov::frontend::gguf::op {
+namespace {
+
+ov::Output<ov::Node> reshape_flat_kv(const NodeContext& context,
+ size_t input_index,
+ const ov::Output<ov::Node>& flat,
+ const ov::Output<ov::Node>& attention_size) {
+ const char* shape_name = input_index == 1 ? "flat_kv_shape_k" : "flat_kv_shape_v";
+ const char* offset_name = input_index == 1 ? "flat_kv_offset_k" : "flat_kv_offset_v";
+ const auto shape = context.get_attribute<std::vector<int64_t>>(shape_name, {});
+ FRONT_END_OP_CONVERSION_CHECK(shape.size() == 4, "Flat FLASH_ATTN_EXT KV view must expose a rank-4 logical shape");
+ const int64_t n_head = shape[1];
+ const int64_t head_size = shape[3];
+ const int64_t row_size = n_head * head_size;
+ FRONT_END_OP_CONVERSION_CHECK(row_size > 0, "Flat FLASH_ATTN_EXT KV view has invalid head geometry");
+
+ const int64_t offset = context.get_attribute<int64_t>(offset_name);
+ auto begin = ov::op::v0::Constant::create(ov::element::i64, {1}, {offset});
+ auto row_size_node = ov::op::v0::Constant::create(ov::element::i64, {1}, {row_size});
+ auto extent = std::make_shared<ov::op::v1::Multiply>(attention_size, row_size_node);
+ auto end = std::make_shared<ov::op::v1::Add>(begin, extent);
+ auto one = ov::op::v0::Constant::create(ov::element::i64, {1}, {1});
+ auto axis = ov::op::v0::Constant::create(ov::element::i64, {1}, {3});
+ auto sliced = std::make_shared<ov::op::v8::Slice>(flat, begin, end, one, axis);
+
+ auto target = std::make_shared<ov::op::v0::Concat>(
+ ov::OutputVector{one,
+ attention_size,
+ ov::op::v0::Constant::create(ov::element::i64, {1}, {n_head}),
+ ov::op::v0::Constant::create(ov::element::i64, {1}, {head_size})},
+ 0);
+ auto reshaped = std::make_shared<ov::op::v1::Reshape>(sliced, target, false);
+ return std::make_shared<ov::op::v1::Transpose>(reshaped,
+ ov::op::v0::Constant::create(ov::element::i64, {4}, {0, 2, 1, 3}));
+}
+
+} // namespace
+
OutputVector translate_flash_attn_ext(const NodeContext& context) {
- num_inputs_check(context, 4, 5);
+ num_inputs_check(context, 3, 5);
auto q_f32 = context.get_input(0);
auto k = context.get_input(1);
auto v = context.get_input(2);
- auto mask = context.get_input(3);
+ const int op_case = context.get_op_case();
+ const bool flat_kv = op_case == 1 || op_case == 2;
+ const std::string fourth_name = context.get_input_size() == 4 ? context.get_input_names()[3] : std::string{};
+ const std::string sink_suffix = ".attn_sinks.weight";
+ const bool named_sink =
+ fourth_name.size() >= sink_suffix.size() &&
+ fourth_name.compare(fourth_name.size() - sink_suffix.size(), sink_suffix.size(), sink_suffix) == 0;
+ const bool sink_without_mask =
+ context.get_input_size() == 4 && context.get_attribute<bool>("sink_without_mask", named_sink);
+ const bool has_mask = context.get_input_size() >= 4 && !sink_without_mask;
// gpt-oss: optional 5th input is the per-head attention sink logit [n_head].
- const bool has_sinks = context.get_input_size() == 5;
+ const bool has_sinks = context.get_input_size() == 5 || sink_without_mask;
+ // Maskless sinks are not supported yet; they are detected only to reject them instead of misreading them as a mask.
+ FRONT_END_OP_CONVERSION_CHECK(!has_sinks || has_mask, "FLASH_ATTN_EXT sinks require an attention mask");
+
+ if (flat_kv) {
+ const char* length_name = op_case == 1 ? "attention_size" : "attention_size_static";
+ FRONT_END_OP_CONVERSION_CHECK(context.has_input(length_name), "Flat FLASH_ATTN_EXT KV requires ", length_name);
+ const auto attention_size = context.get_input(length_name);
+ k = reshape_flat_kv(context, 1, k, attention_size);
+ v = reshape_flat_kv(context, 2, v, attention_size);
+ }
float scale = context.get_attribute<float>("scale");
float kq_soft_cap = context.get_attribute<float>("kq_soft_cap", 0.0f);
+ FRONT_END_OP_CONVERSION_CHECK(has_mask || kq_soft_cap == 0.0f,
+ "Maskless FLASH_ATTN_EXT does not support a non-zero soft cap");
const auto sdpa_type = ov::element::f16;
auto q = std::make_shared<ov::op::v0::Convert>(q_f32, sdpa_type);
@@ -52,21 +112,24 @@ OutputVector translate_flash_attn_ext(const NodeContext& context) {
ov::Output<ov::Node> mask_sliced, res;
// Pick the layer flavor's mask. The cgraph decoder answers the "is_swa" attribute directly; the
// builder identifies it by the mask input's name (self_kq_mask_swa).
- const bool is_swa =
- context.get_attribute<bool>("is_swa", false) || context.get_input_names()[3].find("swa") != std::string::npos;
- const std::string mask_name = is_swa ? "KQ_mask_swa_sliced" : "KQ_mask_sliced";
- if (context.has_input(mask_name)) {
- mask_sliced = context.get_input(mask_name);
- } else {
- 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 two = ov::op::v0::Constant::create(ov::element::i64, {1}, {2});
- auto token_len = get_dimensions(q, {2});
- mask_sliced = std::make_shared<ov::op::v8::Slice>(mask, zero, token_len, one, two);
- }
+ if (has_mask) {
+ auto mask = context.get_input(3);
+ const bool is_swa = context.get_attribute<bool>("is_swa", false) ||
+ context.get_input_names()[3].find("swa") != std::string::npos;
+ const std::string mask_name = is_swa ? "KQ_mask_swa_sliced" : "KQ_mask_sliced";
+ if (context.has_input(mask_name)) {
+ mask_sliced = context.get_input(mask_name);
+ } else {
+ 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 two = ov::op::v0::Constant::create(ov::element::i64, {1}, {2});
+ auto token_len = get_dimensions(q, {2});
+ mask_sliced = std::make_shared<ov::op::v8::Slice>(mask, zero, token_len, one, two);
+ }
- if (mask_sliced.get_element_type() != sdpa_type) {
- mask_sliced = std::make_shared<ov::op::v0::Convert>(mask_sliced, sdpa_type);
+ if (mask_sliced.get_element_type() != sdpa_type) {
+ mask_sliced = std::make_shared<ov::op::v0::Convert>(mask_sliced, sdpa_type);
+ }
}
// The two decoders hand q/k/v over in different layouts, so the head axis and the need for a
@@ -77,8 +140,7 @@ OutputVector translate_flash_attn_ext(const NodeContext& context) {
// K/V on axis 2 first, then transpose all three. That ordering (concat -> GQA tile
// -> single Transpose -> SDPA) is what the CPU plugin's stateful_sdpa_fusion
// matches, so the attention fuses into ScaledDotProductAttentionWithKVCache.
- const int op_case = context.get_op_case();
- FRONT_END_CHECK_IMPLEMENTED(op_case == 0 || op_case == 100, "Unsupported FLASH_ATTN_EXT case");
+ FRONT_END_CHECK_IMPLEMENTED(op_case == 0 || flat_kv || op_case == 100, "Unsupported FLASH_ATTN_EXT case");
const bool ggml_natural = op_case == 100;
const size_t head_axis = ggml_natural ? 2 : 1;
@@ -105,9 +167,12 @@ OutputVector translate_flash_attn_ext(const NodeContext& context) {
};
auto q_shape = context.get_input_shape(0);
- auto k_shape = context.get_input_shape(1);
- k = tile_kv(q_shape[head_axis].get_length(), k_shape[head_axis].get_length(), q_shape[3].get_length(), k);
- v = tile_kv(q_shape[head_axis].get_length(), k_shape[head_axis].get_length(), q_shape[3].get_length(), v);
+ const auto k_heads = flat_kv ? context.get_attribute<std::vector<int64_t>>("flat_kv_shape_k")[1]
+ : context.get_input_shape(1)[head_axis].get_length();
+ const auto v_heads = flat_kv ? context.get_attribute<std::vector<int64_t>>("flat_kv_shape_v")[1]
+ : context.get_input_shape(2)[head_axis].get_length();
+ k = tile_kv(q_shape[head_axis].get_length(), k_heads, q_shape[3].get_length(), k);
+ v = tile_kv(q_shape[head_axis].get_length(), v_heads, q_shape[3].get_length(), v);
// SDPA requires q/k/v to share an element type; match k/v to q (ConvertConvertLike lowers these).
k = std::make_shared<ov::op::v1::ConvertLike>(k, q);
@@ -162,8 +227,15 @@ OutputVector translate_flash_attn_ext(const NodeContext& context) {
auto attn_out_caps = std::make_shared<v0::MatMul>(attn_weights, v_f32_t, false, false);
sdpa = attn_out_caps;
- } else if (!has_sinks) {
+ } else if (!has_sinks && has_mask) {
sdpa = std::make_shared<ov::op::v13::ScaledDotProductAttention>(q_t, k_t, v_t, mask_sliced, scale_node, false);
+ } else if (!has_sinks) {
+ // The maskless SDPA overload has no explicit scale input and applies 1/sqrt(D). Fold the
+ // requested ggml scale into Q so the resulting score multiplier is exactly `scale`.
+ const float q_compensation = scale * std::sqrt(static_cast<float>(q_shape[3].get_length()));
+ auto compensation = ov::op::v0::Constant::create(sdpa_type, ov::Shape{}, {q_compensation});
+ auto q_scaled = std::make_shared<ov::op::v1::Multiply>(q_t, compensation);
+ sdpa = std::make_shared<ov::op::v13::ScaledDotProductAttention>(q_scaled, k_t, v_t, false);
} else {
// gpt-oss attention sinks: a learned per-head logit participates in the softmax
// denominator (so the attention weights do not sum to 1) but contributes no value. OV
diff --git a/src/frontends/gguf/src/op/gated_delta_net.cpp b/src/frontends/gguf/src/op/gated_delta_net.cpp
index 0db4f9e1ebe..ab77c2575ae 100644
--- a/src/frontends/gguf/src/op/gated_delta_net.cpp
+++ b/src/frontends/gguf/src/op/gated_delta_net.cpp
@@ -7,6 +7,7 @@
#include <cmath>
#include <cstdint>
#include <memory>
+#include <numeric>
#include <vector>
#include "node_context.hpp"
@@ -15,8 +16,10 @@
#include "openvino/op/broadcast.hpp"
#include "openvino/op/concat.hpp"
#include "openvino/op/constant.hpp"
+#include "openvino/op/convert.hpp"
#include "openvino/op/exp.hpp"
#include "openvino/op/gather.hpp"
+#include "openvino/op/less.hpp"
#include "openvino/op/loop.hpp"
#include "openvino/op/matmul.hpp"
#include "openvino/op/multiply.hpp"
@@ -89,6 +92,24 @@ OutputVector translate_gated_delta_net(const NodeContext& context) {
g = std::make_shared<ov::op::v0::Squeeze>(g, sq_axis_3);
beta = std::make_shared<ov::op::v0::Squeeze>(beta, sq_axis_3);
+ if (context.has_input("chunk_valid_len")) {
+ const auto& g_shape = g.get_partial_shape();
+ FRONT_END_OP_CONVERSION_CHECK(
+ g_shape.rank().is_static() && g_shape.rank().get_length() == 3 && g_shape[1].is_static(),
+ "GATED_DELTA_NET pad masking requires a static token dimension");
+ const int64_t n_tokens = g_shape[1].get_length();
+ std::vector<int64_t> positions(n_tokens);
+ std::iota(positions.begin(), positions.end(), 0);
+ auto valid = std::make_shared<ov::op::v1::Less>(
+ ov::op::v0::Constant::create(ov::element::i64, {static_cast<size_t>(n_tokens)}, positions),
+ context.get_input("chunk_valid_len"));
+ auto mask = std::make_shared<ov::op::v0::Unsqueeze>(
+ std::make_shared<ov::op::v0::Convert>(valid, g.get_element_type()),
+ ov::op::v0::Constant::create(ov::element::i64, {2}, std::vector<int64_t>{0, 2}));
+ g = std::make_shared<ov::op::v1::Multiply>(g, mask);
+ beta = std::make_shared<ov::op::v1::Multiply>(beta, mask);
+ }
+
auto gdn = std::make_shared<ov::op::internal::GatedDeltaNet>(q, k, v, state, g, beta);
auto attn_4d = gdn->output(0);
auto state_4d = gdn->output(1); // [B, H_v, key_dim, value_dim]
@@ -132,6 +153,23 @@ static OutputVector translate_gated_delta_net_ref(const NodeContext& context) {
const int64_t rq1 = H_v / H_k; // GQA head repeat factor
const float scale = 1.0f / std::sqrt((float)S_v);
+ if (context.has_input("chunk_valid_len")) {
+ FRONT_END_OP_CONVERSION_CHECK(v_shape[1].is_static(),
+ "GATED_DELTA_NET pad masking requires a static token dimension");
+ const int64_t T = v_shape[1].get_length();
+ std::vector<int64_t> positions(T);
+ std::iota(positions.begin(), positions.end(), 0);
+ auto valid = std::make_shared<ov::op::v1::Less>(
+ ov::op::v0::Constant::create(ov::element::i64, {static_cast<size_t>(T)}, positions),
+ context.get_input("chunk_valid_len"));
+ auto mask = std::make_shared<ov::op::v1::Reshape>(
+ std::make_shared<ov::op::v0::Convert>(valid, g.get_element_type()),
+ ov::op::v0::Constant::create(ov::element::i64, {4}, std::vector<int64_t>{1, T, 1, 1}),
+ false);
+ g = std::make_shared<ov::op::v1::Multiply>(g, mask);
+ beta = std::make_shared<ov::op::v1::Multiply>(beta, mask);
+ }
+
auto axis_0 = ov::op::v0::Constant::create(ov::element::i64, {1}, {0});
auto axis_1 = ov::op::v0::Constant::create(ov::element::i64, {1}, {1});
auto axis_2 = ov::op::v0::Constant::create(ov::element::i64, {1}, {2});
diff --git a/src/frontends/gguf/src/op/glu_geglu.cpp b/src/frontends/gguf/src/op/glu_geglu.cpp
index b87a3b30558..482b7ed828c 100644
--- a/src/frontends/gguf/src/op/glu_geglu.cpp
+++ b/src/frontends/gguf/src/op/glu_geglu.cpp
@@ -3,56 +3,35 @@
//
#include <memory>
+#include <utility>
#include "node_context.hpp"
#include "op_table.hpp"
-#include "openvino/core/node_output.hpp"
#include "openvino/op/constant.hpp"
#include "openvino/op/gelu.hpp"
#include "openvino/op/multiply.hpp"
-#include "openvino/op/sigmoid.hpp"
-#include "openvino/op/slice.hpp"
+#include "openvino/op/swish.hpp"
#include "utils.hpp"
namespace ov::frontend::gguf::op {
OutputVector translate_glu_geglu(const NodeContext& context) {
- num_inputs_check(context, 1, 2);
-
- ov::Output<ov::Node> src0;
- ov::Output<ov::Node> src1;
- if (context.get_input_size() == 2) {
- src0 = context.get_input(0);
- src1 = context.get_input(1);
- } else {
- // GGUF splits along ne[0] (OV last axis) using floor division: nc = ne[0] / 2.
- // Both halves are nc elements; if the dimension is odd, the last element is dropped.
- // Use Slice instead of Split to handle odd dimensions correctly.
- auto combined = context.get_input(0);
- auto combined_shape = combined.get_partial_shape();
- int64_t last_dim_val = combined_shape[combined_shape.rank().get_length() - 1].get_length();
- int64_t nc = last_dim_val / 2;
-
- auto axis = ov::op::v0::Constant::create(ov::element::i64, {1}, {-1});
- auto step = ov::op::v0::Constant::create(ov::element::i64, {1}, {1});
- auto start0 = ov::op::v0::Constant::create(ov::element::i64, {1}, {0});
- auto stop0 = ov::op::v0::Constant::create(ov::element::i64, {1}, {nc});
- auto start1 = ov::op::v0::Constant::create(ov::element::i64, {1}, {nc});
- auto stop1 = ov::op::v0::Constant::create(ov::element::i64, {1}, {2 * nc});
-
- src0 = std::make_shared<ov::op::v8::Slice>(combined, start0, stop0, step, axis);
- src1 = std::make_shared<ov::op::v8::Slice>(combined, start1, stop1, step, axis);
- }
-
- if (context.get_attribute<bool>("swapped")) {
- std::swap(src0, src1);
- }
+ auto inputs = get_glu_inputs(context);
// ggml's GGML_GLU_OP_GEGLU uses the tanh GELU approximation, not OV's default ERF form. The
// ERF/tanh difference is small per call but compounds across layers into a wrong argmax on
// deep models (e.g. gemma3-1b), so match ggml with TANH.
- auto gelu = std::make_shared<ov::op::v7::Gelu>(src0, ov::op::GeluApproximationMode::TANH);
- auto res = std::make_shared<ov::op::v1::Multiply>(gelu, src1);
+ auto gelu = std::make_shared<ov::op::v7::Gelu>(inputs.first, ov::op::GeluApproximationMode::TANH);
+ auto res = std::make_shared<ov::op::v1::Multiply>(gelu, inputs.second);
+
+ return rename_outputs_with_suffix({std::move(res)}, context.get_name());
+}
+
+OutputVector translate_glu_geglu_quick(const NodeContext& context) {
+ auto inputs = get_glu_inputs(context);
+ auto coefficient = ov::op::v0::Constant::create(inputs.first.get_element_type(), {}, {1.702f});
+ auto gate = std::make_shared<ov::op::v4::Swish>(inputs.first, coefficient);
+ auto res = std::make_shared<ov::op::v1::Multiply>(gate, inputs.second);
return rename_outputs_with_suffix({std::move(res)}, context.get_name());
}
diff --git a/src/frontends/gguf/src/op/glu_swiglu.cpp b/src/frontends/gguf/src/op/glu_swiglu.cpp
index 5bae16b660c..0a49d9ddcdd 100644
--- a/src/frontends/gguf/src/op/glu_swiglu.cpp
+++ b/src/frontends/gguf/src/op/glu_swiglu.cpp
@@ -2,66 +2,28 @@
// SPDX-License-Identifier: Apache-2.0
//
-#include <cstdint>
#include <limits>
#include <memory>
#include <utility>
#include "node_context.hpp"
#include "op_table.hpp"
-#include "openvino/core/node_output.hpp"
#include "openvino/op/add.hpp"
#include "openvino/op/clamp.hpp"
#include "openvino/op/constant.hpp"
+#include "openvino/op/convert.hpp"
#include "openvino/op/multiply.hpp"
-#include "openvino/op/sigmoid.hpp"
-#include "openvino/op/slice.hpp"
+#include "openvino/op/swish.hpp"
#include "utils.hpp"
namespace ov::frontend::gguf::op {
-namespace {
-// Resolve the two GLU halves: either two explicit inputs, or one combined tensor split along the
-// last axis (floor division; an odd trailing element is dropped). Applies the "swapped" flag.
-std::pair<ov::Output<ov::Node>, ov::Output<ov::Node>> get_glu_inputs(const NodeContext& context) {
- num_inputs_check(context, 1, 2);
-
- ov::Output<ov::Node> src0;
- ov::Output<ov::Node> src1;
- if (context.get_input_size() == 2) {
- src0 = context.get_input(0);
- src1 = context.get_input(1);
- } else {
- auto combined = context.get_input(0);
- auto combined_shape = combined.get_partial_shape();
- int64_t last_dim_val = combined_shape[combined_shape.rank().get_length() - 1].get_length();
- int64_t nc = last_dim_val / 2;
-
- auto axis = ov::op::v0::Constant::create(ov::element::i64, {1}, {-1});
- auto step = ov::op::v0::Constant::create(ov::element::i64, {1}, {1});
- auto start0 = ov::op::v0::Constant::create(ov::element::i64, {1}, {0});
- auto stop0 = ov::op::v0::Constant::create(ov::element::i64, {1}, {nc});
- auto start1 = ov::op::v0::Constant::create(ov::element::i64, {1}, {nc});
- auto stop1 = ov::op::v0::Constant::create(ov::element::i64, {1}, {2 * nc});
-
- src0 = std::make_shared<ov::op::v8::Slice>(combined, start0, stop0, step, axis);
- src1 = std::make_shared<ov::op::v8::Slice>(combined, start1, stop1, step, axis);
- }
-
- if (context.get_attribute<bool>("swapped")) {
- std::swap(src0, src1);
- }
- return {src0, src1};
-}
-} // namespace
-
OutputVector translate_glu_swiglu(const NodeContext& context) {
auto inputs = get_glu_inputs(context);
auto src0 = inputs.first;
auto src1 = inputs.second;
- auto sigmoid = std::make_shared<ov::op::v0::Sigmoid>(src0);
- auto silu = std::make_shared<ov::op::v1::Multiply>(src0, sigmoid);
+ auto silu = std::make_shared<ov::op::v4::Swish>(src0);
auto res = std::make_shared<ov::op::v1::Multiply>(silu, src1);
return rename_outputs_with_suffix({std::move(res)}, context.get_name());
@@ -78,17 +40,37 @@ OutputVector translate_glu_swiglu_oai(const NodeContext& context) {
const float limit = context.get_attribute<float>("glu_limit");
auto gate = std::make_shared<ov::op::v0::Clamp>(src0, -std::numeric_limits<float>::infinity(), limit);
- auto alpha_const = ov::op::v0::Constant::create(ov::element::f32, {}, {alpha});
- auto scaled_gate = std::make_shared<ov::op::v1::Multiply>(gate, alpha_const);
- auto sigmoid = std::make_shared<ov::op::v0::Sigmoid>(scaled_gate);
- auto out_glu = std::make_shared<ov::op::v1::Multiply>(gate, sigmoid);
+ auto alpha_const = ov::op::v0::Constant::create(src0.get_element_type(), {}, {alpha});
+ auto out_glu = std::make_shared<ov::op::v4::Swish>(gate, alpha_const);
auto up = std::make_shared<ov::op::v0::Clamp>(src1, -limit, limit);
- auto one = ov::op::v0::Constant::create(ov::element::f32, {}, {1.0f});
+ auto one = ov::op::v0::Constant::create(src1.get_element_type(), {}, {1.0f});
auto up_plus_one = std::make_shared<ov::op::v1::Add>(up, one);
auto res = std::make_shared<ov::op::v1::Multiply>(out_glu, up_plus_one);
return rename_outputs_with_suffix({std::move(res)}, context.get_name());
}
+OutputVector translate_glu_swiglu_clamp(const NodeContext& context) {
+ auto inputs = get_glu_inputs(context);
+ auto src0 = inputs.first;
+ auto src1 = inputs.second;
+
+ const auto output_type = src0.get_element_type();
+ if (output_type != ov::element::f32) {
+ src0 = std::make_shared<ov::op::v0::Convert>(src0, ov::element::f32);
+ src1 = std::make_shared<ov::op::v0::Convert>(src1, ov::element::f32);
+ }
+ const float limit = context.get_attribute<float>("glu_limit");
+ auto gate = std::make_shared<ov::op::v0::Clamp>(src0, -std::numeric_limits<float>::infinity(), limit);
+ auto silu = std::make_shared<ov::op::v4::Swish>(gate);
+ auto up = std::make_shared<ov::op::v0::Clamp>(src1, -limit, limit);
+ Output<Node> res = std::make_shared<ov::op::v1::Multiply>(silu, up);
+ if (res.get_element_type() != output_type) {
+ res = std::make_shared<ov::op::v0::Convert>(res, output_type);
+ }
+
+ return rename_outputs_with_suffix({std::move(res)}, context.get_name());
+}
+
} // namespace ov::frontend::gguf::op
diff --git a/src/frontends/gguf/src/op/permute.cpp b/src/frontends/gguf/src/op/permute.cpp
index 202805f1d54..87d0c86e511 100644
--- a/src/frontends/gguf/src/op/permute.cpp
+++ b/src/frontends/gguf/src/op/permute.cpp
@@ -31,6 +31,9 @@ OutputVector translate_permute(const NodeContext& context) {
ov::Output<Node> res;
auto src = context.get_input(0);
auto perm_order = context.get_attribute<std::vector<int64_t>>("perm", {0, 2, 1, 3});
+ if (op_case == 1 && src.get_partial_shape().rank() == 3 && perm_order.size() == 4 && perm_order[0] == 0) {
+ perm_order = {perm_order[1] - 1, perm_order[2] - 1, perm_order[3] - 1};
+ }
auto perm = ov::op::v0::Constant::create(ov::element::i64, {perm_order.size()}, perm_order);
if (op_case == 1) {
@@ -106,7 +109,8 @@ OutputVector translate_permute(const NodeContext& context) {
return rename_outputs_with_suffix({std::move(res)}, context.get_name());
}
- int64_t ctx_per_seq = cache_shape[2].is_static() ? cache_shape[2].get_length() : -1;
+ const bool dynamic_cache = context.get_attribute<bool>("dynamic_cache", false);
+ int64_t ctx_per_seq = dynamic_cache ? -1 : (cache_shape[2].is_static() ? cache_shape[2].get_length() : -1);
int64_t n_seq = cache_shape[1].get_length();
Output<Node> seq_active_start;
diff --git a/src/frontends/gguf/src/op/pool_2d.cpp b/src/frontends/gguf/src/op/pool_2d.cpp
new file mode 100644
index 00000000000..e5c722656b3
--- /dev/null
+++ b/src/frontends/gguf/src/op/pool_2d.cpp
@@ -0,0 +1,60 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <cstdint>
+#include <memory>
+#include <vector>
+
+#include "node_context.hpp"
+#include "op_table.hpp"
+#include "openvino/frontend/exception.hpp"
+#include "openvino/op/avg_pool.hpp"
+#include "openvino/op/convert.hpp"
+#include "openvino/op/max_pool.hpp"
+#include "utils.hpp"
+
+namespace ov::frontend::gguf::op {
+
+OutputVector translate_pool_2d(const NodeContext& context) {
+ num_inputs_check(context, 1, 1);
+
+ const auto params = context.get_attribute<std::vector<int32_t>>("pool_params");
+ FRONT_END_OP_CONVERSION_CHECK(params.size() == 6, "POOL_2D requires 6 params");
+ FRONT_END_OP_CONVERSION_CHECK(params[0] > 0 && params[1] > 0, "POOL_2D kernel dimensions must be positive");
+ FRONT_END_OP_CONVERSION_CHECK(params[2] > 0 && params[3] > 0, "POOL_2D strides must be positive");
+ FRONT_END_OP_CONVERSION_CHECK(params[4] >= 0 && params[5] >= 0, "POOL_2D padding must be nonnegative");
+
+ const auto kernel_width = static_cast<size_t>(params[0]);
+ const auto kernel_height = static_cast<size_t>(params[1]);
+ const auto stride_x = static_cast<size_t>(params[2]);
+ const auto stride_y = static_cast<size_t>(params[3]);
+ const auto padding_x = static_cast<size_t>(params[4]);
+ const auto padding_y = static_cast<size_t>(params[5]);
+
+ const ov::Shape kernel{kernel_height, kernel_width};
+ const ov::Strides strides{stride_y, stride_x};
+ const ov::Shape pads_begin{padding_y, padding_x};
+ const ov::Shape pads_end = pads_begin;
+
+ auto input = context.get_input(0);
+ if (input.get_element_type() != ov::element::f32) {
+ input = std::make_shared<ov::op::v0::Convert>(input, ov::element::f32);
+ }
+
+ ov::Output<Node> result;
+ switch (context.get_op_case()) {
+ case 1:
+ result = std::make_shared<ov::op::v1::MaxPool>(input, strides, pads_begin, pads_end, kernel);
+ break;
+ case 2:
+ result = std::make_shared<ov::op::v1::AvgPool>(input, strides, pads_begin, pads_end, kernel, false);
+ break;
+ default:
+ FRONT_END_OP_CONVERSION_CHECK(false, "Unsupported POOL_2D mode");
+ }
+
+ return rename_outputs_with_suffix({std::move(result)}, context.get_name());
+}
+
+} // namespace ov::frontend::gguf::op
diff --git a/src/frontends/gguf/src/op/roll.cpp b/src/frontends/gguf/src/op/roll.cpp
new file mode 100644
index 00000000000..f70297bf9b8
--- /dev/null
+++ b/src/frontends/gguf/src/op/roll.cpp
@@ -0,0 +1,31 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "openvino/op/roll.hpp"
+
+#include <cstdint>
+#include <memory>
+#include <vector>
+
+#include "node_context.hpp"
+#include "op_table.hpp"
+#include "openvino/frontend/exception.hpp"
+#include "openvino/op/constant.hpp"
+#include "utils.hpp"
+
+namespace ov::frontend::gguf::op {
+
+OutputVector translate_roll(const NodeContext& context) {
+ num_inputs_check(context, 1, 1);
+
+ const auto shifts = context.get_attribute<std::vector<int64_t>>("roll_shifts");
+ FRONT_END_OP_CONVERSION_CHECK(shifts.size() == 4, "ROLL requires one shift per axis");
+
+ auto shift = ov::op::v0::Constant::create(ov::element::i64, {4}, shifts);
+ auto axes = ov::op::v0::Constant::create(ov::element::i64, {4}, std::vector<int64_t>{0, 1, 2, 3});
+ auto result = std::make_shared<ov::op::v7::Roll>(context.get_input(0), shift, axes);
+ return rename_outputs_with_suffix({std::move(result)}, context.get_name());
+}
+
+} // namespace ov::frontend::gguf::op
diff --git a/src/frontends/gguf/src/op/rope.cpp b/src/frontends/gguf/src/op/rope.cpp
index 7d5dae0e22a..e329aab7357 100644
--- a/src/frontends/gguf/src/op/rope.cpp
+++ b/src/frontends/gguf/src/op/rope.cpp
@@ -94,6 +94,25 @@ OutputVector translate_rope(const NodeContext& context) {
data = std::make_shared<ov::op::v0::Convert>(data, ov::element::f32);
}
+ const int64_t head_dim = output_shape[3].get_length();
+ const int64_t n_rot = rope_config.n_dims > 0 ? rope_config.n_dims : head_dim;
+ const int64_t offset = context.get_attribute<int64_t>("rope_offset", 0);
+ FRONT_END_OP_CONVERSION_CHECK(offset >= 0 && offset % 2 == 0 && n_rot > 0 && n_rot % 2 == 0 && offset <= head_dim &&
+ n_rot <= head_dim - offset,
+ "ROPE requires even dimensions and offset within the head");
+ Output<Node> prefix;
+ if (offset != 0) {
+ data = std::make_shared<ov::op::v1::Reshape>(data, make_bhsd_shape(), true);
+ auto axis = ov::op::v0::Constant::create(ov::element::i64, {1}, {-1});
+ 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 start = ov::op::v0::Constant::create(ov::element::i64, {1}, {offset});
+ auto end = ov::op::v0::Constant::create(ov::element::i64, {1}, {head_dim});
+ prefix = std::make_shared<ov::op::v8::Slice>(data, zero, start, one, axis);
+ data = std::make_shared<ov::op::v8::Slice>(data, start, end, one, axis);
+ output_shape[3] = head_dim - offset;
+ }
+
if (mode == TYPE_NORMAL) {
// Emit the Flux-style interleaved RoPE pattern so ov::pass::RoPEFusionFlux
// folds this subgraph into ov::op::internal::RoPE → GPU ocl::rope::opt kernel.
@@ -281,6 +300,10 @@ OutputVector translate_rope(const NodeContext& context) {
// Fail cleanly on an unmapped mode rather than dereferencing a null res downstream.
FRONT_END_CHECK_IMPLEMENTED(res.get_node_shared_ptr() != nullptr, "Unsupported ROPE mode");
+ if (prefix.get_node_shared_ptr()) {
+ res = std::make_shared<ov::op::v0::Concat>(OutputVector{prefix, res}, -1);
+ }
+
if (res.get_element_type() != output_type) {
res = std::make_shared<ov::op::v0::Convert>(res, output_type);
}
diff --git a/src/frontends/gguf/src/op/solve_tri.cpp b/src/frontends/gguf/src/op/solve_tri.cpp
new file mode 100644
index 00000000000..e5d8efcea85
--- /dev/null
+++ b/src/frontends/gguf/src/op/solve_tri.cpp
@@ -0,0 +1,75 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include <cstdint>
+#include <memory>
+#include <vector>
+
+#include "node_context.hpp"
+#include "op_table.hpp"
+#include "openvino/frontend/exception.hpp"
+#include "openvino/op/broadcast.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/divide.hpp"
+#include "openvino/op/gather.hpp"
+#include "openvino/op/loop.hpp"
+#include "openvino/op/matmul.hpp"
+#include "openvino/op/scatter_update.hpp"
+#include "openvino/op/shape_of.hpp"
+#include "openvino/op/subtract.hpp"
+#include "utils.hpp"
+
+namespace ov::frontend::gguf::op {
+
+OutputVector translate_solve_tri(const NodeContext& context) {
+ num_inputs_check(context, 2, 2);
+
+ const auto params = context.get_attribute<std::vector<int32_t>>("solve_tri_params");
+ FRONT_END_OP_CONVERSION_CHECK(params.size() == 3, "SOLVE_TRI requires left, lower and unit flags");
+ FRONT_END_OP_CONVERSION_CHECK(params[0] != 0 && params[1] != 0 && params[2] == 0,
+ "SOLVE_TRI supports only left, lower, non-unit triangular systems");
+
+ auto a = context.get_input(0);
+ auto b = context.get_input(1);
+ const auto a_shape = context.get_input_shape(0);
+ FRONT_END_OP_CONVERSION_CHECK(
+ a_shape.rank() == 4 && a_shape[2].is_static() && a_shape[3].is_static() && a_shape[2] == a_shape[3],
+ "SOLVE_TRI requires rank 4 with static, square matrix dimensions");
+ const int64_t n = a_shape[2].get_length();
+
+ auto b_shape = std::make_shared<ov::op::v3::ShapeOf>(b, ov::element::i64);
+ auto zero = ov::op::v0::Constant::create(ov::element::f32, {}, {0.0f});
+ auto x_init = std::make_shared<ov::op::v3::Broadcast>(zero, b_shape);
+
+ auto iteration = std::make_shared<ov::op::v0::Parameter>(ov::element::i64, ov::Shape{1});
+ auto body_x = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape::dynamic(4));
+ auto body_a = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape::dynamic(4));
+ auto body_b = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape::dynamic(4));
+
+ auto axis2 = ov::op::v0::Constant::create(ov::element::i64, {1}, {int64_t{2}});
+ auto axis3 = ov::op::v0::Constant::create(ov::element::i64, {1}, {int64_t{3}});
+ auto axis2_scalar = ov::op::v0::Constant::create(ov::element::i64, {}, {int64_t{2}});
+ auto b_i = std::make_shared<ov::op::v8::Gather>(body_b, iteration, axis2);
+ auto a_row_i = std::make_shared<ov::op::v8::Gather>(body_a, iteration, axis2);
+ auto partial = std::make_shared<ov::op::v0::MatMul>(a_row_i, body_x, false, false);
+ auto diagonal = std::make_shared<ov::op::v8::Gather>(a_row_i, iteration, axis3);
+ auto x_i = std::make_shared<ov::op::v1::Divide>(std::make_shared<ov::op::v1::Subtract>(b_i, partial), diagonal);
+ auto x_updated = std::make_shared<ov::op::v3::ScatterUpdate>(body_x, iteration, x_i, axis2_scalar);
+ auto body_condition = ov::op::v0::Constant::create(ov::element::boolean, {1}, {true});
+
+ auto body = std::make_shared<ov::Model>(ov::OutputVector{body_condition, x_updated},
+ ov::ParameterVector{iteration, body_x, body_a, body_b});
+ auto trip_count = ov::op::v0::Constant::create(ov::element::i64, {1}, {n});
+ auto execution_condition = ov::op::v0::Constant::create(ov::element::boolean, {1}, {true});
+ auto loop = std::make_shared<ov::op::v5::Loop>(trip_count, execution_condition);
+ loop->set_function(body);
+ loop->set_special_body_ports({0, 0});
+ loop->set_merged_input(body_x, x_init, x_updated);
+ loop->set_invariant_input(body_a, a);
+ loop->set_invariant_input(body_b, b);
+
+ return rename_outputs_with_suffix({loop->get_iter_value(x_updated, -1)}, context.get_name());
+}
+
+} // namespace ov::frontend::gguf::op
diff --git a/src/frontends/gguf/src/op/unary_silu.cpp b/src/frontends/gguf/src/op/unary_silu.cpp
index 8b8c5e91771..fa96066cfcd 100644
--- a/src/frontends/gguf/src/op/unary_silu.cpp
+++ b/src/frontends/gguf/src/op/unary_silu.cpp
@@ -5,8 +5,7 @@
#include "node_context.hpp"
#include "op_table.hpp"
#include "openvino/core/node_output.hpp"
-#include "openvino/op/multiply.hpp"
-#include "openvino/op/sigmoid.hpp"
+#include "openvino/op/swish.hpp"
#include "utils.hpp"
namespace ov::frontend::gguf::op {
@@ -15,8 +14,7 @@ OutputVector translate_unary_silu(const NodeContext& context) {
num_inputs_check(context, 1, 1);
auto input = context.get_input(0);
- auto sigmoid = std::make_shared<ov::op::v0::Sigmoid>(input);
- auto res = std::make_shared<ov::op::v1::Multiply>(input, sigmoid);
+ auto res = std::make_shared<ov::op::v4::Swish>(input);
return rename_outputs_with_suffix({std::move(res)}, context.get_name());
}
diff --git a/src/frontends/gguf/src/op/view.cpp b/src/frontends/gguf/src/op/view.cpp
index 97144837b50..76e1a30ec71 100644
--- a/src/frontends/gguf/src/op/view.cpp
+++ b/src/frontends/gguf/src/op/view.cpp
@@ -24,6 +24,12 @@ namespace {
// element-count conservation: product(tgt) / product(res_ps's static dims). No-op for a static
// res_ps, where the target is already exact and a -1 could land on the wrong axis.
void place_dynamic_token_axis(std::vector<int64_t>& tgt, const ov::PartialShape& res_ps) {
+ if (std::find(tgt.begin(), tgt.end(), -1) != tgt.end()) {
+ // The decoder can identify the runtime axis exactly from ggml strides/permutations. Keep
+ // that stronger contract, especially for zero-length captures where element-count
+ // inference below is intentionally impossible.
+ return;
+ }
if (res_ps.rank().is_dynamic()) {
return;
}
@@ -444,7 +450,11 @@ OutputVector translate_view(const NodeContext& context) {
}
if (byte_offset == 0 && ov::shape_size(src_shape) == ov::shape_size(dst_shape)) {
- auto target = ov::op::v0::Constant::create(ov::element::i64, {dst_shape.size()}, dst_shape);
+ auto target_shape = context.get_attribute<std::vector<int64_t>>("view_reshape", {});
+ if (target_shape.empty()) {
+ target_shape.assign(dst_shape.begin(), dst_shape.end());
+ }
+ auto target = ov::op::v0::Constant::create(ov::element::i64, {target_shape.size()}, target_shape);
auto result = std::make_shared<ov::op::v1::Reshape>(context.get_input(0), target, false);
return rename_outputs_with_suffix({std::move(result)}, context.get_name());
}
diff --git a/src/frontends/gguf/src/op_table.cpp b/src/frontends/gguf/src/op_table.cpp
index 549b209bca3..759f6c73e76 100644
--- a/src/frontends/gguf/src/op_table.cpp
+++ b/src/frontends/gguf/src/op_table.cpp
@@ -28,9 +28,11 @@ std::unordered_map<std::string, CreatorFunction> get_supported_ops() {
using namespace ov::op;
return {
{"GGML_GLU_OP_GEGLU", op::translate_glu_geglu},
+ {"GGML_GLU_OP_GEGLU_QUICK", op::translate_glu_geglu_quick},
{"GGML_GLU_OP_SWIGLU", op::translate_glu_swiglu},
+ {"GGML_GLU_OP_SWIGLU_CLAMP", op::translate_glu_swiglu_clamp},
{"GGML_GLU_OP_SWIGLU_OAI", op::translate_glu_swiglu_oai},
- {"GGML_OP_ADD", op::translate_1to1_match_2_inputs<v1::Add>},
+ {"GGML_OP_ADD", op::translate_add},
{"GGML_OP_ADD1", op::translate_1to1_match_2_inputs<v1::Add>},
{"GGML_OP_ADD_ID", op::translate_add_id},
{"GGML_OP_ARGSORT", op::translate_argsort},
@@ -56,15 +58,18 @@ std::unordered_map<std::string, CreatorFunction> get_supported_ops() {
{"GGML_OP_NORM", op::translate_norm},
{"GGML_OP_PAD", op::translate_pad},
{"GGML_OP_PERMUTE", op::translate_permute},
+ {"GGML_OP_POOL_2D", op::translate_pool_2d},
{"GGML_OP_REPEAT", op::translate_repeat},
{"GGML_OP_RESHAPE", op::translate_reshape},
{"GGML_OP_RMS_NORM", op::translate_rms_norm},
+ {"GGML_OP_ROLL", op::translate_roll},
{"GGML_OP_ROPE", op::translate_rope},
{"GGML_OP_SCALE", op::translate_scale},
{"GGML_OP_SET", op::translate_set},
{"GGML_OP_SET_ROWS", op::translate_set_rows},
{"GGML_OP_SIN", op::translate_1to1_match_1_input<v0::Sin>},
{"GGML_OP_SOFT_MAX", op::translate_soft_max},
+ {"GGML_OP_SOLVE_TRI", op::translate_solve_tri},
{"GGML_OP_SQR", op::translate_sqr},
{"GGML_OP_SQRT", op::translate_sqrt},
{"GGML_OP_SSM_CONV", op::translate_ssm_conv},
diff --git a/src/frontends/gguf/src/op_table.hpp b/src/frontends/gguf/src/op_table.hpp
index e745a858df4..45cd4dce075 100644
--- a/src/frontends/gguf/src/op_table.hpp
+++ b/src/frontends/gguf/src/op_table.hpp
@@ -12,6 +12,8 @@ namespace op {
#define GGUF_OP_CONVERTER(op) OutputVector op(const NodeContext& context)
+GGUF_OP_CONVERTER(translate_add);
+
// Structural / memory ops.
GGUF_OP_CONVERTER(translate_concat);
GGUF_OP_CONVERTER(translate_cont);
@@ -39,7 +41,9 @@ GGUF_OP_CONVERTER(translate_scale);
// Gated linear units.
GGUF_OP_CONVERTER(translate_glu_geglu);
+GGUF_OP_CONVERTER(translate_glu_geglu_quick);
GGUF_OP_CONVERTER(translate_glu_swiglu);
+GGUF_OP_CONVERTER(translate_glu_swiglu_clamp);
GGUF_OP_CONVERTER(translate_glu_swiglu_oai);
// MoE (mixture-of-experts) routing ops.
@@ -78,6 +82,9 @@ GGUF_OP_CONVERTER(translate_fill);
// Convolution-family / sequence ops.
GGUF_OP_CONVERTER(translate_im2col);
GGUF_OP_CONVERTER(translate_pad);
+GGUF_OP_CONVERTER(translate_pool_2d);
+GGUF_OP_CONVERTER(translate_roll);
+GGUF_OP_CONVERTER(translate_solve_tri);
GGUF_OP_CONVERTER(translate_ssm_conv);
GGUF_OP_CONVERTER(translate_ssm_scan);
GGUF_OP_CONVERTER(translate_gated_delta_net);
diff --git a/src/frontends/gguf/src/utils.cpp b/src/frontends/gguf/src/utils.cpp
index e1dd6c71bae..f3f455e011c 100644
--- a/src/frontends/gguf/src/utils.cpp
+++ b/src/frontends/gguf/src/utils.cpp
@@ -36,6 +36,39 @@ void num_inputs_check(const NodeContext& context, size_t min_inputs, size_t max_
FRONT_END_OP_CONVERSION_CHECK(input_size <= max_inputs, "Got more inputs than expected");
}
+std::pair<ov::Output<ov::Node>, ov::Output<ov::Node>> get_glu_inputs(const NodeContext& context) {
+ num_inputs_check(context, 1, 2);
+
+ ov::Output<ov::Node> src0;
+ ov::Output<ov::Node> src1;
+ if (context.get_input_size() == 2) {
+ src0 = context.get_input(0);
+ src1 = context.get_input(1);
+ } else {
+ // GGUF splits along ne[0] (OV last axis) using floor division. Both halves have nc
+ // elements; an odd trailing element is dropped.
+ auto combined = context.get_input(0);
+ const auto combined_shape = combined.get_partial_shape();
+ const auto last_dim = combined_shape[combined_shape.rank().get_length() - 1].get_length();
+ const auto half_dim = last_dim / 2;
+
+ auto axis = ov::op::v0::Constant::create(ov::element::i64, {1}, {-1});
+ auto step = ov::op::v0::Constant::create(ov::element::i64, {1}, {1});
+ auto start0 = ov::op::v0::Constant::create(ov::element::i64, {1}, {0});
+ auto stop0 = ov::op::v0::Constant::create(ov::element::i64, {1}, {half_dim});
+ auto start1 = ov::op::v0::Constant::create(ov::element::i64, {1}, {half_dim});
+ auto stop1 = ov::op::v0::Constant::create(ov::element::i64, {1}, {2 * half_dim});
+
+ src0 = std::make_shared<ov::op::v8::Slice>(combined, start0, stop0, step, axis);
+ src1 = std::make_shared<ov::op::v8::Slice>(combined, start1, stop1, step, axis);
+ }
+
+ if (context.get_attribute<bool>("swapped")) {
+ std::swap(src0, src1);
+ }
+ return {src0, src1};
+}
+
std::shared_ptr<ov::op::v0::Parameter> find_parameter(const std::shared_ptr<ov::Model>& model,
const std::string& name) {
for (const auto& p : model->get_parameters()) {
@@ -270,6 +303,29 @@ ov::Output<ov::Node> process_view_input(const NodeContext& context, int input_in
// Only works for VIEW operations that slice at the lowest dimension
// If the VIEW also reshape the result, `slice_len` should be provided
auto input = context.get_input(input_index);
+
+ // The standalone VIEW translator may already have materialized this operand as a Slice and
+ // dynamic Reshape. Reapplying the consumer-side legacy view handling would slice the resolved
+ // tensor a second time. Falcon K/V projection views expose this at zero cache length: the
+ // second slice starts beyond the resolved head-width and produces [1,0,H,S]. Treat a shape
+ // matching the ggml view itself as authoritative and pass it through unchanged.
+ const auto& expected_shape = context.get_input_shape(input_index);
+ const auto actual_shape = input.get_partial_shape();
+ if (actual_shape.rank().is_static() && expected_shape.rank().is_static() &&
+ actual_shape.rank() == expected_shape.rank()) {
+ bool view_is_materialized = true;
+ for (int64_t i = 0; i < actual_shape.rank().get_length(); ++i) {
+ if (expected_shape[i].is_static() &&
+ (actual_shape[i].is_dynamic() || actual_shape[i] != expected_shape[i])) {
+ view_is_materialized = false;
+ break;
+ }
+ }
+ if (view_is_materialized) {
+ return input;
+ }
+ }
+
// The decoder already returns the view start offset in ELEMENTS (it divides ggml's raw byte
// offset by the element size), so no stride division is needed here.
int64_t split_addr = context.get_input_view_element_offset(input_index);
diff --git a/src/frontends/gguf/src/utils.hpp b/src/frontends/gguf/src/utils.hpp
index 86e960722c1..2859b2b3bb7 100644
--- a/src/frontends/gguf/src/utils.hpp
+++ b/src/frontends/gguf/src/utils.hpp
@@ -30,6 +30,9 @@ namespace ov::frontend::gguf {
void num_inputs_check(const NodeContext& context, size_t min_inputs, size_t max_inputs);
+/// \brief Resolve one combined or two explicit GLU inputs and apply the decoder's swapped flag.
+std::pair<ov::Output<ov::Node>, ov::Output<ov::Node>> get_glu_inputs(const NodeContext& context);
+
/// \brief Find a Parameter whose friendly name or output tensor names include `name`.
/// Returns nullptr if the model has no such Parameter.
std::shared_ptr<ov::op::v0::Parameter> find_parameter(const std::shared_ptr<ov::Model>& model, const std::string& name);
diff --git a/src/frontends/gguf/tests/CMakeLists.txt b/src/frontends/gguf/tests/CMakeLists.txt
index 778f3d56c85..1d43f877c18 100644
--- a/src/frontends/gguf/tests/CMakeLists.txt
+++ b/src/frontends/gguf/tests/CMakeLists.txt
@@ -48,6 +48,7 @@ set(FRONTEND_SRCS
"${FE_SRC_DIR}/builder/blocks/ffn.cpp"
"${FE_SRC_DIR}/builder/blocks/gated_delta_net.cpp"
"${FE_SRC_DIR}/builder/blocks/qkv_repack.cpp"
+ "${FE_SRC_DIR}/op/add.cpp"
"${FE_SRC_DIR}/op/add_id.cpp"
"${FE_SRC_DIR}/op/argsort.cpp"
"${FE_SRC_DIR}/op/clamp.cpp"
@@ -70,14 +71,17 @@ set(FRONTEND_SRCS
"${FE_SRC_DIR}/op/norm.cpp"
"${FE_SRC_DIR}/op/pad.cpp"
"${FE_SRC_DIR}/op/permute.cpp"
+ "${FE_SRC_DIR}/op/pool_2d.cpp"
"${FE_SRC_DIR}/op/repeat.cpp"
"${FE_SRC_DIR}/op/reshape.cpp"
"${FE_SRC_DIR}/op/rms_norm.cpp"
+ "${FE_SRC_DIR}/op/roll.cpp"
"${FE_SRC_DIR}/op/rope.cpp"
"${FE_SRC_DIR}/op/scale.cpp"
"${FE_SRC_DIR}/op/set.cpp"
"${FE_SRC_DIR}/op/set_rows.cpp"
"${FE_SRC_DIR}/op/softmax.cpp"
+ "${FE_SRC_DIR}/op/solve_tri.cpp"
"${FE_SRC_DIR}/op/sqr.cpp"
"${FE_SRC_DIR}/op/ssm_conv.cpp"
"${FE_SRC_DIR}/op/ssm_scan.cpp"
diff --git a/src/frontends/gguf/tests/flash_attn_gqa_oracle.c b/src/frontends/gguf/tests/flash_attn_gqa_oracle.c
new file mode 100644
index 00000000000..825bd9ef9e5
--- /dev/null
+++ b/src/frontends/gguf/tests/flash_attn_gqa_oracle.c
@@ -0,0 +1,43 @@
+// Standalone ggml-CPU reference for FlashAttnExtFlatKvGqaWithoutMask.
+// Compile against llama.cpp's ggml CPU libraries as described in how_to_add_op.md.
+#include "ggml.h"
+#include "ggml-backend.h"
+#include "ggml-cpu.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(void) {
+ struct ggml_init_params ip = {64 * 1024 * 1024, NULL, true};
+ struct ggml_context * ctx = ggml_init(ip);
+ // ggml dimensions are [D, T, H, B]; flat data is [H, T, D] for q/k/v.
+ struct ggml_tensor * q = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, 2, 2, 4, 1);
+ struct ggml_tensor * k = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, 2, 2, 2, 1);
+ struct ggml_tensor * v = ggml_new_tensor_4d(ctx, GGML_TYPE_F32, 2, 2, 2, 1);
+ struct ggml_tensor * out = ggml_flash_attn_ext(ctx, q, k, v, NULL, 1.0f, 0.0f, 0.0f);
+ struct ggml_cgraph * graph = ggml_new_graph(ctx);
+ ggml_build_forward_expand(graph, out);
+
+ ggml_backend_t backend = ggml_backend_cpu_init();
+ ggml_backend_buffer_t buffer = ggml_backend_alloc_ctx_tensors(ctx, backend);
+ const float q_data[] = {1, 0, 0, 1, 0.5f, 1, 1, -0.5f, -1, 1, 1, 0, 0, -1, 0.5f, 0.5f};
+ const float k_data[] = {1, 0, 0, 1, 0.5f, 0.5f, -0.5f, 1};
+ const float v_data[] = {1, 2, 3, 4, 5, 6, 7, 8};
+ ggml_backend_tensor_set(q, q_data, 0, sizeof(q_data));
+ ggml_backend_tensor_set(k, k_data, 0, sizeof(k_data));
+ ggml_backend_tensor_set(v, v_data, 0, sizeof(v_data));
+ if (ggml_backend_graph_compute(backend, graph) != GGML_STATUS_SUCCESS) {
+ fprintf(stderr, "ggml CPU attention failed\n");
+ return 1;
+ }
+
+ float result[16];
+ ggml_backend_tensor_get(out, result, 0, sizeof(result));
+ for (size_t i = 0; i < 16; ++i) {
+ printf("%.6f%s", result[i], (i + 1) % 8 ? " " : "\n");
+ }
+ ggml_backend_buffer_free(buffer);
+ ggml_backend_free(backend);
+ ggml_free(ctx);
+ return 0;
+}
diff --git a/src/frontends/gguf/tests/op_test_utils.hpp b/src/frontends/gguf/tests/op_test_utils.hpp
index ab179c50f66..e987eaa8cf1 100644
--- a/src/frontends/gguf/tests/op_test_utils.hpp
+++ b/src/frontends/gguf/tests/op_test_utils.hpp
@@ -76,6 +76,7 @@ class SingleOpDecoder : public GgufDecoder, public std::enable_shared_from_this<
public:
SingleOpDecoder(std::string op_type,
std::vector<TensorDesc> inputs,
+ std::vector<TensorDesc> extra_inputs,
TensorDesc output,
std::map<std::string, ov::Any> attributes)
: m_op_type(std::move(op_type)),
@@ -90,6 +91,12 @@ public:
p->output(0).set_names({in.name});
m_model_inputs[in.name] = p;
}
+ for (const auto& in : extra_inputs) {
+ auto p = std::make_shared<ov::op::v0::Parameter>(in.type, in.shape);
+ p->set_friendly_name(in.name);
+ p->output(0).set_names({in.name});
+ m_model_extra_inputs[in.name] = p;
+ }
}
// ── typed node-scoped attribute access (we hold a single op) ────────────────
@@ -100,7 +107,8 @@ public:
// ── per-node metadata ───────────────────────────────────────────────────────
int64_t get_input_view_element_offset(const std::string&) const override {
- return 0;
+ auto it = m_attributes.find("view_offset");
+ return it == m_attributes.end() ? 0 : it->second.as<int64_t>();
}
ov::PartialShape get_input_shape(const std::string& name) const override {
return find_input(name).shape;
@@ -135,6 +143,9 @@ public:
const std::map<std::string, std::shared_ptr<ov::Node>>& get_model_inputs() const override {
return m_model_inputs;
}
+ const std::map<std::string, std::shared_ptr<ov::Node>>& get_model_extra_inputs() const override {
+ return m_model_extra_inputs;
+ }
std::vector<std::string> get_model_output_names() const override {
return {m_output.name};
}
@@ -159,6 +170,7 @@ private:
std::map<std::string, ov::Any> m_attributes;
std::vector<std::string> m_input_names;
std::map<std::string, std::shared_ptr<ov::Node>> m_model_inputs;
+ std::map<std::string, std::shared_ptr<ov::Node>> m_model_extra_inputs;
};
// Fluent builder: describe a single op and convert it to an ov::Model.
@@ -172,6 +184,10 @@ public:
m_inputs.push_back({name, type, shape});
return *this;
}
+ SingleOpBuilder& extra_input(const std::string& name, ov::element::Type type, const ov::PartialShape& shape) {
+ m_extra_inputs.push_back({name, type, shape});
+ return *this;
+ }
SingleOpBuilder& output(const std::string& name, ov::element::Type type, const ov::PartialShape& shape) {
m_output = {name, type, shape};
return *this;
@@ -194,7 +210,7 @@ public:
std::shared_ptr<GgufDecoder> decoder() const {
auto attrs = m_attributes;
attrs.emplace("output_type", ov::Any(m_output.type));
- return std::make_shared<SingleOpDecoder>(m_op_type, m_inputs, m_output, attrs);
+ return std::make_shared<SingleOpDecoder>(m_op_type, m_inputs, m_extra_inputs, m_output, attrs);
}
std::shared_ptr<ov::Model> build() const {
@@ -215,6 +231,7 @@ public:
private:
std::string m_op_type;
std::vector<TensorDesc> m_inputs;
+ std::vector<TensorDesc> m_extra_inputs;
TensorDesc m_output;
std::map<std::string, ov::Any> m_attributes;
};
@@ -227,6 +244,20 @@ inline ov::Tensor make_f32_tensor(const ov::Shape& shape, const std::vector<floa
return t;
}
+inline ov::Tensor make_f16_tensor(const ov::Shape& shape, const std::vector<float>& data) {
+ ov::Tensor tensor(ov::element::f16, shape);
+ std::transform(data.begin(), data.end(), tensor.data<ov::float16>(), [](float value) {
+ return ov::float16(value);
+ });
+ return tensor;
+}
+
+inline ov::Tensor make_i64_tensor(const ov::Shape& shape, const std::vector<int64_t>& data) {
+ ov::Tensor tensor(ov::element::i64, shape);
+ std::copy(data.begin(), data.end(), tensor.data<int64_t>());
+ return tensor;
+}
+
// Compile on CPU and run one inference with the given named inputs; return the single output.
//
// Inference precision is requested as f32: these tests validate the converted graph against an fp32
diff --git a/src/frontends/gguf/tests/test_arch_conversion.cpp b/src/frontends/gguf/tests/test_arch_conversion.cpp
index 89561f5f6fe..87b0e14b16b 100644
--- a/src/frontends/gguf/tests/test_arch_conversion.cpp
+++ b/src/frontends/gguf/tests/test_arch_conversion.cpp
@@ -180,19 +180,19 @@ struct Fingerprint {
const std::map<std::string, Fingerprint>& fingerprints() {
static const std::map<std::string, Fingerprint> fp{
- {"mamba2-dense.gguf.hdr", {293, 6}}, {"nemotron_h-dense.gguf.hdr", {280, 8}},
- {"bailingmoe2-moe.gguf.hdr", {473, 10}}, {"ernie4_5-moe-moe.gguf.hdr", {455, 10}},
- {"exaone4-dense.gguf.hdr", {417, 11}}, {"gemma-dense.gguf.hdr", {365, 10}},
- {"gemma2-dense.gguf.hdr", {415, 11}}, {"glm4moe-moe.gguf.hdr", {485, 10}},
- {"gpt-oss-moe.gguf.hdr", {574, 11}}, {"hunyuan-dense-dense.gguf.hdr", {416, 10}},
- {"hunyuan-moe-moe.gguf.hdr", {554, 10}}, {"llama-dense.gguf.hdr", {400, 10}},
- {"llama-moe.gguf.hdr", {506, 10}}, {"maincoder-dense.gguf.hdr", {432, 10}},
- {"minicpm-dense.gguf.hdr", {398, 10}}, {"minicpm-moe.gguf.hdr", {504, 10}},
- {"minimax-m2-moe.gguf.hdr", {534, 10}}, {"mistral3-dense.gguf.hdr", {400, 10}},
- {"mistral3-moe.gguf.hdr", {506, 10}}, {"olmoe-moe.gguf.hdr", {534, 10}},
- {"phi3-dense.gguf.hdr", {380, 10}}, {"qwen2-dense.gguf.hdr", {368, 10}},
- {"qwen3-dense.gguf.hdr", {416, 10}}, {"qwen3moe-moe.gguf.hdr", {546, 10}},
- {"qwen35-dense.gguf.hdr", {395, 10}}, {"smollm3-dense.gguf.hdr", {384, 10}},
+ {"mamba2-dense.gguf.hdr", {289, 6}}, {"nemotron_h-dense.gguf.hdr", {278, 8}},
+ {"bailingmoe2-moe.gguf.hdr", {470, 10}}, {"ernie4_5-moe-moe.gguf.hdr", {453, 10}},
+ {"exaone4-dense.gguf.hdr", {415, 11}}, {"gemma-dense.gguf.hdr", {365, 10}},
+ {"gemma2-dense.gguf.hdr", {415, 11}}, {"glm4moe-moe.gguf.hdr", {482, 10}},
+ {"gpt-oss-moe.gguf.hdr", {570, 11}}, {"hunyuan-dense-dense.gguf.hdr", {414, 10}},
+ {"hunyuan-moe-moe.gguf.hdr", {550, 10}}, {"llama-dense.gguf.hdr", {398, 10}},
+ {"llama-moe.gguf.hdr", {504, 10}}, {"maincoder-dense.gguf.hdr", {430, 10}},
+ {"minicpm-dense.gguf.hdr", {396, 10}}, {"minicpm-moe.gguf.hdr", {502, 10}},
+ {"minimax-m2-moe.gguf.hdr", {532, 10}}, {"mistral3-dense.gguf.hdr", {398, 10}},
+ {"mistral3-moe.gguf.hdr", {504, 10}}, {"olmoe-moe.gguf.hdr", {532, 10}},
+ {"phi3-dense.gguf.hdr", {378, 10}}, {"qwen2-dense.gguf.hdr", {366, 10}},
+ {"qwen3-dense.gguf.hdr", {414, 10}}, {"qwen3moe-moe.gguf.hdr", {544, 10}},
+ {"qwen35-dense.gguf.hdr", {391, 10}}, {"smollm3-dense.gguf.hdr", {382, 10}},
};
return fp;
}
diff --git a/src/frontends/gguf/tests/test_ops.cpp b/src/frontends/gguf/tests/test_ops.cpp
index fb90b83a251..956d0fbe2b6 100644
--- a/src/frontends/gguf/tests/test_ops.cpp
+++ b/src/frontends/gguf/tests/test_ops.cpp
@@ -5,15 +5,20 @@
//
// Each test builds a one-op model through SingleOpBuilder (which drives
// ov::frontend::gguf::FrontEnd::convert via an in-memory SingleOpDecoder), runs it on
-// CPU and checks the result against a reference computed in plain C++. No .gguf file,
-// ggml or llama.cpp is involved.
+// CPU and checks the result against a reference. No .gguf file or llama.cpp is involved
+// at test time; layout-sensitive expected values are generated separately with ggml CPU.
#include <algorithm>
#include <cmath>
#include <functional>
+#include "op_table.hpp"
#include "op_test_utils.hpp"
+#include "openvino/op/eye.hpp"
+#include "openvino/op/multiply.hpp"
+#include "openvino/op/result.hpp"
#include "openvino/op/selective_ssm.hpp"
+#include "openvino/op/slice.hpp"
#include "openvino/op/topk.hpp"
#include "utils.hpp"
@@ -779,6 +784,43 @@ TEST(GGUFOps, ViewCase3RestoresGgmlShapeBeforeSlicing) {
expect_near(out, expected, 0.0f);
}
+TEST(GGUFOps, ViewInputRequiresDirectionalShapeMatch) {
+ using namespace ov::frontend::gguf;
+ auto process = [](const ov::PartialShape& expected, const ov::PartialShape& actual) {
+ auto decoder = SingleOpBuilder()
+ .op("GGML_OP_VIEW")
+ .input("x", ov::element::f32, expected)
+ .output("out", ov::element::f32, expected)
+ .attr<int64_t>("view_offset", 1)
+ .decoder();
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, actual);
+ input->set_friendly_name("x");
+ input->output(0).set_names({"x"});
+ auto tensors = std::make_shared<TensorMap>();
+ (*tensors)["x"] = input;
+ NodeContext context(decoder, tensors);
+ return std::make_pair(input, process_view_input(context, 0, 2));
+ };
+
+ const auto [unresolved_input, unresolved] = process(ov::PartialShape{1, 3, 2, 4}, ov::PartialShape{1, -1, 2, 4});
+ auto slice = ov::as_type_ptr<ov::op::v8::Slice>(unresolved.get_node_shared_ptr());
+ ASSERT_NE(slice, nullptr);
+ ASSERT_EQ(unresolved.get_partial_shape(), (ov::PartialShape{1, -1, 2, 2}));
+ auto model = std::make_shared<ov::Model>(ov::ResultVector{std::make_shared<ov::op::v0::Result>(unresolved)},
+ ov::ParameterVector{unresolved_input});
+ std::vector<float> data(24);
+ for (size_t i = 0; i < data.size(); ++i) {
+ data[i] = static_cast<float>(i);
+ }
+ auto out = run_on_cpu(model, {{"x", make_f32_tensor({1, 3, 2, 4}, data)}});
+ expect_near(out, {1, 2, 5, 6, 9, 10, 13, 14, 17, 18, 21, 22}, 0.0f);
+
+ for (const auto& actual : {ov::PartialShape{1, -1, 2, 4}, ov::PartialShape{1, 3, 2, 4}}) {
+ const auto [input, materialized] = process(ov::PartialShape{1, -1, 2, 4}, actual);
+ EXPECT_EQ(materialized, input);
+ }
+}
+
// TopK: indices of the k largest values per row, k taken from the output's last dim.
//
// ggml's own kernel deliberately swaps the first two result slots ("emphasize that the order is not
@@ -937,6 +979,48 @@ TEST(GGUFOps, SwigluOai) {
expect_near(out, expected, 1e-4f);
}
+TEST(GGUFOps, SwigluClampOneInputSwapped) {
+ const float limit = 2.0f;
+ auto model = SingleOpBuilder()
+ .op("GGML_GLU_OP_SWIGLU_CLAMP")
+ .input("x", ov::element::f32, {1, 8})
+ .output("out", ov::element::f32, {1, 4})
+ .attr<bool>("swapped", true)
+ .attr<float>("glu_limit", limit)
+ .build();
+
+ std::vector<float> x{3.0f, -4.0f, 0.5f, 1.0f, 1.0f, 2.0f, -3.0f, 4.0f};
+ auto out = run_on_cpu(model, {{"x", make_f32_tensor({1, 8}, x)}});
+ std::vector<float> expected(4);
+ for (size_t i = 0; i < expected.size(); ++i) {
+ const float gate = std::min(x[4 + i], limit);
+ const float up = std::min(std::max(x[i], -limit), limit);
+ expected[i] = gate / (1.0f + std::exp(-gate)) * up;
+ }
+ expect_near(out, expected);
+}
+
+TEST(GGUFOps, SwigluClampTwoInputs) {
+ auto model = SingleOpBuilder()
+ .op("GGML_GLU_OP_SWIGLU_CLAMP")
+ .input("gate", ov::element::f32, {1, 3})
+ .input("up", ov::element::f32, {1, 3})
+ .output("out", ov::element::f32, {1, 3})
+ .attr<bool>("swapped", false)
+ .attr<float>("glu_limit", 3.0f)
+ .build();
+ std::vector<float> gate{1.0f, 4.0f, -2.0f};
+ std::vector<float> up{5.0f, -5.0f, 0.5f};
+ auto out = run_on_cpu(model, {{"gate", make_f32_tensor({1, 3}, gate)}, {"up", make_f32_tensor({1, 3}, up)}});
+ std::vector<float> expected(3);
+ for (size_t i = 0; i < expected.size(); ++i) {
+ const float g = std::min(gate[i], 3.0f);
+ const float u = std::min(std::max(up[i], -3.0f), 3.0f);
+ expected[i] = g / (1.0f + std::exp(-g)) * u;
+ }
+ expect_near(out, expected);
+}
+
// MulMatId (generic dequantized experts): per-token expert matmul.
TEST(GGUFOps, MulMatId) {
// weights [1, n_expert=2, m=2, k=3]; activations [1, n_tokens=2, 1, k=3];
@@ -1927,6 +2011,166 @@ TEST(GGUFOps, FlashAttnExt) {
expect_near(out, expected, 2e-2f); // fp16 SDPA
}
+TEST(GGUFOps, FlashAttnExtFlatKvWithoutMask) {
+ auto model = SingleOpBuilder()
+ .op("GGML_OP_FLASH_ATTN_EXT")
+ .input("q", ov::element::f32, {1, 1, 2, 2})
+ .input("k_flat", ov::element::f32, {1, 1, 1, 8})
+ .input("v_flat", ov::element::f32, {1, 1, 1, 8})
+ .extra_input("attention_size_static", ov::element::i64, {1})
+ .output("out", ov::element::f32, {1, 2, 1, 2})
+ .op_case(2)
+ .attr<float>("scale", 1.0f)
+ .attr<std::vector<int64_t>>("flat_kv_shape_k", {1, 1, 2, 2})
+ .attr<std::vector<int64_t>>("flat_kv_shape_v", {1, 1, 2, 2})
+ .attr<int64_t>("flat_kv_offset_k", 2)
+ .attr<int64_t>("flat_kv_offset_v", 2)
+ .build();
+
+ const std::vector<float> q{1, 0, 0, 1};
+ const std::vector<float> k_flat{9, 9, 1, 0, 0, 1, 9, 9};
+ const std::vector<float> v_flat{9, 9, 1, 2, 3, 4, 9, 9};
+ auto out = run_on_cpu(model,
+ {{"q", make_f32_tensor({1, 1, 2, 2}, q)},
+ {"k_flat", make_f32_tensor({1, 1, 1, 8}, k_flat)},
+ {"v_flat", make_f32_tensor({1, 1, 1, 8}, v_flat)},
+ {"attention_size_static", make_i64_tensor({1}, {2})}});
+
+ const float p = std::exp(1.0f) / (std::exp(1.0f) + 1.0f);
+ expect_near(out, {3.0f - 2.0f * p, 4.0f - 2.0f * p, 1.0f + 2.0f * p, 2.0f + 2.0f * p}, 2e-2f);
+}
+
+TEST(GGUFOps, FlashAttnExtFlatKvGqaWithoutMask) {
+ auto model = SingleOpBuilder()
+ .op("GGML_OP_FLASH_ATTN_EXT")
+ .input("q", ov::element::f32, {1, 4, 2, 2})
+ .input("k_flat", ov::element::f32, {1, 1, 1, 10})
+ .input("v_flat", ov::element::f32, {1, 1, 1, 10})
+ .extra_input("attention_size_static", ov::element::i64, {1})
+ .output("out", ov::element::f32, {1, 2, 4, 2})
+ .op_case(2)
+ .attr<float>("scale", 1.0f)
+ .attr<std::vector<int64_t>>("flat_kv_shape_k", {1, 2, 2, 2})
+ .attr<std::vector<int64_t>>("flat_kv_shape_v", {1, 2, 2, 2})
+ .attr<int64_t>("flat_kv_offset_k", 1)
+ .attr<int64_t>("flat_kv_offset_v", 1)
+ .build();
+
+ const std::vector<float> q{1, 0, 0, 1, 0.5f, 1, 1, -0.5f, -1, 1, 1, 0, 0, -1, 0.5f, 0.5f};
+ // ggml's [Hkv,T,D] K/V data is stored in the flat cache as [T,Hkv,D].
+ const std::vector<float> k_flat{9, 1, 0, 0.5f, 0.5f, 0, 1, -0.5f, 1, 9};
+ const std::vector<float> v_flat{9, 1, 2, 5, 6, 3, 4, 7, 8, 9};
+ auto out = run_on_cpu(model,
+ {{"q", make_f32_tensor({1, 4, 2, 2}, q)},
+ {"k_flat", make_f32_tensor({1, 1, 1, 10}, k_flat)},
+ {"v_flat", make_f32_tensor({1, 1, 1, 10}, v_flat)},
+ {"attention_size_static", make_i64_tensor({1}, {2})}});
+
+ // GGML_OP_FLASH_ATTN_EXT on ggml CPU, flash_attn_gqa_oracle.c (Hq=4, Hkv=2).
+ expect_near(out,
+ {1.537883f,
+ 2.537883f,
+ 2.244919f,
+ 3.244919f,
+ 6.635149f,
+ 7.635149f,
+ 5.755081f,
+ 6.755082f,
+ 2.462117f,
+ 3.462117f,
+ 1.364851f,
+ 2.364851f,
+ 5.537883f,
+ 6.537883f,
+ 5.875648f,
+ 6.875647f},
+ 2e-2f);
+}
+
+TEST(GGUFOps, FlashAttnExtRejectsMasklessSinks) {
+ for (const auto& sink_shape : {ov::Shape{2}, ov::Shape{1, 1, 1, 2}}) {
+ EXPECT_THROW(SingleOpBuilder()
+ .op("GGML_OP_FLASH_ATTN_EXT")
+ .input("q", ov::element::f32, {1, 2, 1, 2})
+ .input("k", ov::element::f32, {1, 1, 2, 2})
+ .input("v", ov::element::f32, {1, 1, 2, 2})
+ .input("sinks", ov::element::f32, sink_shape)
+ .output("out", ov::element::f32, {1, 1, 2, 2})
+ .attr<float>("scale", 1.0f)
+ .attr<bool>("sink_without_mask", true)
+ .build(),
+ ov::Exception);
+ }
+
+ EXPECT_THROW(SingleOpBuilder()
+ .op("GGML_OP_FLASH_ATTN_EXT")
+ .input("q", ov::element::f32, {1, 2, 1, 2})
+ .input("k", ov::element::f32, {1, 1, 2, 2})
+ .input("v", ov::element::f32, {1, 1, 2, 2})
+ .input("blk.0.attn_sinks.weight", ov::element::f32, {1, 1, 1, 2})
+ .output("out", ov::element::f32, {1, 1, 2, 2})
+ .attr<float>("scale", 1.0f)
+ .build(),
+ ov::Exception);
+}
+
+TEST(GGUFOps, FlashAttnExtAcceptsF32MaskMatchingHeadCount) {
+ auto model = SingleOpBuilder()
+ .op("GGML_OP_FLASH_ATTN_EXT")
+ .input("q", ov::element::f32, {1, 2, 1, 2})
+ .input("k", ov::element::f32, {1, 1, 2, 2})
+ .input("v", ov::element::f32, {1, 1, 2, 2})
+ .input("mask", ov::element::f32, {1, 1, 1, 2})
+ .output("out", ov::element::f32, {1, 1, 2, 2})
+ .attr<float>("scale", 1.0f)
+ .build();
+ auto out = run_on_cpu(model,
+ {{"q", make_f32_tensor({1, 2, 1, 2}, {1, 0, 0, 1})},
+ {"k", make_f32_tensor({1, 1, 2, 2}, {1, 0, 0, 1})},
+ {"v", make_f32_tensor({1, 1, 2, 2}, {1, 2, 3, 4})},
+ {"mask", make_f32_tensor({1, 1, 1, 2}, {0, -100})}});
+ expect_near(out, {1, 2, 1, 2}, 2e-2f);
+}
+
+TEST(GGUFOps, FlashAttnExtRejectsMasklessSoftCap) {
+ EXPECT_THROW(SingleOpBuilder()
+ .op("GGML_OP_FLASH_ATTN_EXT")
+ .input("q", ov::element::f32, {1, 1, 1, 2})
+ .input("k", ov::element::f32, {1, 1, 1, 2})
+ .input("v", ov::element::f32, {1, 1, 1, 2})
+ .output("out", ov::element::f32, {1, 1, 1, 2})
+ .attr<float>("scale", 1.0f)
+ .attr<float>("kq_soft_cap", 10.0f)
+ .build(),
+ ov::Exception);
+}
+
+TEST(GGUFOps, FlashAttnExtFlatKvWithMask) {
+ auto model = SingleOpBuilder()
+ .op("GGML_OP_FLASH_ATTN_EXT")
+ .input("q", ov::element::f32, {1, 1, 1, 2})
+ .input("k_flat", ov::element::f32, {1, 1, 1, 6})
+ .input("v_flat", ov::element::f32, {1, 1, 1, 6})
+ .input("mask", ov::element::f32, {1, 1, 1, 2})
+ .extra_input("attention_size", ov::element::i64, {1})
+ .output("out", ov::element::f32, {1, 1, 1, 2})
+ .op_case(1)
+ .attr<float>("scale", 1.0f)
+ .attr<std::vector<int64_t>>("flat_kv_shape_k", {1, 1, 2, 2})
+ .attr<std::vector<int64_t>>("flat_kv_shape_v", {1, 1, 2, 2})
+ .attr<int64_t>("flat_kv_offset_k", 1)
+ .attr<int64_t>("flat_kv_offset_v", 1)
+ .build();
+
+ auto out = run_on_cpu(model,
+ {{"q", make_f32_tensor({1, 1, 1, 2}, {1, 0})},
+ {"k_flat", make_f32_tensor({1, 1, 1, 6}, {9, 1, 0, 0, 1, 9})},
+ {"v_flat", make_f32_tensor({1, 1, 1, 6}, {9, 1, 2, 3, 4, 9})},
+ {"mask", make_f32_tensor({1, 1, 1, 2}, {0, -100})},
+ {"attention_size", make_i64_tensor({1}, {2})}});
+ expect_near(out, {1, 2}, 2e-2f);
+}
+
// FlashAttnExt with gpt-oss attention sinks (5th input), on the default op_case 0 (llama.cpp cgraph)
// layout where q/k/v already arrive as [B, n_head, T, D]. Regression test for a bug where the sink
// logit was reshaped to [1, q_shape[2], 1, 1] instead of [1, q_shape[head_axis], 1, 1]: q_shape[2] is
@@ -2421,30 +2665,38 @@ const std::vector<float> kGdnTneqDv{1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.
const std::vector<float> kGdnTneqDg{0.0f, -0.1f, -0.2f, 0.0f, -0.1f, -0.2f};
const std::vector<float> kGdnTneqDbeta{0.5f, 0.6f, 0.7f, 0.8f, 0.5f, 0.6f};
-ov::Tensor run_gdn_tneqd(bool force_ref) {
+ov::Tensor run_gdn_tneqd(bool force_ref, int64_t valid_len = -1, bool dynamic_tokens = false) {
const int64_t B = 1, T = 3, H = 2, D = 4;
- auto qkv_shp = ov::PartialShape{B, T, H, D};
- auto gate_shp = ov::PartialShape{B, T, H, 1};
+ const auto tokens = dynamic_tokens ? ov::Dimension::dynamic() : ov::Dimension(T);
+ auto qkv_shp = ov::PartialShape{B, tokens, H, D};
+ auto gate_shp = ov::PartialShape{B, tokens, H, 1};
auto state_shp = ov::PartialShape{B, H, D, D};
- auto model = SingleOpBuilder()
- .op("GGML_OP_GATED_DELTA_NET")
- .attr<bool>("force_ref", force_ref)
- .input("q", ov::element::f32, qkv_shp)
- .input("k", ov::element::f32, qkv_shp)
- .input("v", ov::element::f32, qkv_shp)
- .input("g", ov::element::f32, gate_shp)
- .input("beta", ov::element::f32, gate_shp)
- .input("state", ov::element::f32, state_shp)
- .output("out", ov::element::f32, {1, 1, (T + D) * B, D * H})
- .build();
+ auto builder = SingleOpBuilder()
+ .op("GGML_OP_GATED_DELTA_NET")
+ .attr<bool>("force_ref", force_ref)
+ .input("q", ov::element::f32, qkv_shp)
+ .input("k", ov::element::f32, qkv_shp)
+ .input("v", ov::element::f32, qkv_shp)
+ .input("g", ov::element::f32, gate_shp)
+ .input("beta", ov::element::f32, gate_shp)
+ .input("state", ov::element::f32, state_shp)
+ .output("out", ov::element::f32, {1, 1, (T + D) * B, D * H});
+ if (valid_len >= 0) {
+ builder.extra_input("chunk_valid_len", ov::element::i64, {1});
+ }
+ auto model = builder.build();
std::vector<float> state0((size_t)(H * D * D), 0.0f);
- return run_on_cpu(model,
- {{"q", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, (size_t)D}, kGdnTneqDq)},
- {"k", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, (size_t)D}, kGdnTneqDk)},
- {"v", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, (size_t)D}, kGdnTneqDv)},
- {"g", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, 1}, kGdnTneqDg)},
- {"beta", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, 1}, kGdnTneqDbeta)},
- {"state", make_f32_tensor({(size_t)B, (size_t)H, (size_t)D, (size_t)D}, state0)}});
+ std::map<std::string, ov::Tensor> inputs{
+ {"q", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, (size_t)D}, kGdnTneqDq)},
+ {"k", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, (size_t)D}, kGdnTneqDk)},
+ {"v", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, (size_t)D}, kGdnTneqDv)},
+ {"g", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, 1}, kGdnTneqDg)},
+ {"beta", make_f32_tensor({(size_t)B, (size_t)T, (size_t)H, 1}, kGdnTneqDbeta)},
+ {"state", make_f32_tensor({(size_t)B, (size_t)H, (size_t)D, (size_t)D}, state0)}};
+ if (valid_len >= 0) {
+ inputs.emplace("chunk_valid_len", make_i64_tensor({1}, {valid_len}));
+ }
+ return run_on_cpu(model, inputs);
}
} // namespace
@@ -2458,6 +2710,20 @@ TEST(GGUFOps, GatedDeltaNetRefTneqD) {
expect_near(out, kGdnTneqDExpected, 1e-3f);
}
+TEST(GGUFOps, GatedDeltaNetRefDynamicTokens) {
+ auto out = run_gdn_tneqd(/*force_ref=*/true, /*valid_len=*/-1, /*dynamic_tokens=*/true);
+ expect_near(out, kGdnTneqDExpected, 1e-3f);
+}
+
+TEST(GGUFOps, GatedDeltaNetRefMasksStaticPadding) {
+ for (const int64_t valid_len : {int64_t{0}, int64_t{1}, int64_t{3}}) {
+ auto fused = run_gdn_tneqd(/*force_ref=*/false, valid_len);
+ auto reference = run_gdn_tneqd(/*force_ref=*/true, valid_len);
+ ASSERT_EQ(fused.get_size(), reference.get_size());
+ expect_near(reference, std::vector<float>(fused.data<float>(), fused.data<float>() + fused.get_size()), 1e-3f);
+ }
+}
+
// Im2col 1D: unfold a width-KW sliding window over the innermost image axis. For IC=1, stride=1,
// no pad/dilation, image [1,2,3] with KW=2 yields the two windows [1,2] and [2,3].
TEST(GGUFOps, Im2col1D) {
@@ -2503,6 +2769,36 @@ TEST(GGUFOps, Cpy) {
expect_near(out, expected, 0.0f);
}
+TEST(GGUFOps, CpyConvolutionStateUsesDestinationType) {
+ auto model = SingleOpBuilder()
+ .op("GGML_OP_CPY")
+ .input("window", ov::element::f32, {1, 1, 2, 3})
+ .output("out", ov::element::f32, {1, 1, 1, 6})
+ .op_case(2)
+ .attr<ov::element::Type>("dst_type", ov::element::f32)
+ .attr<ov::element::Type>("output_type", ov::element::dynamic)
+ .build();
+
+ const std::vector<float> values{1, 2, 3, 4, 5, 6};
+ auto out = run_on_cpu(model, {{"window", make_f32_tensor({1, 1, 2, 3}, values)}});
+ EXPECT_EQ(out.get_shape(), (ov::Shape{1, 1, 1, 6}));
+ expect_near(out, values, 0.0f);
+}
+
+TEST(GGUFOps, CpyEmptyCompactionPreservesCacheProducerName) {
+ auto model = SingleOpBuilder()
+ .op("GGML_OP_CPY")
+ .input("empty_rows", ov::element::f32, {1, 1, 0, 4})
+ .input("cache", ov::element::f32, {1, 1, 2, 4})
+ .output("out", ov::element::f32, {1, 1, 2, 4})
+ .op_case(5)
+ .build();
+
+ const auto& cache = model->get_results()[0]->input_value(0).get_node_shared_ptr();
+ EXPECT_STREQ(cache->get_type_name(), "Parameter");
+ EXPECT_EQ(cache->get_friendly_name(), "cache");
+}
+
// Cont (op_case 1/2): after a PERMUTE/TRANSPOSE the OV tensor is already logically contiguous, so
// CONT is an identity passthrough of its input.
TEST(GGUFOps, Cont) {
@@ -2513,11 +2809,25 @@ TEST(GGUFOps, Cont) {
.op_case(1) // input from PERMUTE
.build();
+ EXPECT_EQ(model->get_parameters()[0]->get_friendly_name(), "x");
+
std::vector<float> x{1, 2, 3, 4, 5, 6, 7, 8};
auto out = run_on_cpu(model, {{"x", make_f32_tensor({2, 4}, x)}});
expect_near(out, x, 0.0f);
}
+TEST(GGUFOps, ContViewPassThroughPreservesProducerName) {
+ auto model = SingleOpBuilder()
+ .op("GGML_OP_CONT")
+ .input("x", ov::element::f32, {2, 4})
+ .output("out", ov::element::f32, {2, 4})
+ .op_case(3)
+ .build();
+
+ EXPECT_EQ(model->get_parameters()[0]->get_friendly_name(), "x");
+ EXPECT_EQ(model->get_results()[0]->input_value(0).get_node_shared_ptr(), model->get_parameters()[0]);
+}
+
// GeGLU: split the last axis in half -> gelu(a) * b, where gelu is ggml's tanh approximation.
TEST(GGUFOps, GeGLU) {
auto model = SingleOpBuilder()
@@ -2547,6 +2857,150 @@ TEST(GGUFOps, GeGLU) {
expect_near(out, expected, 1e-3f);
}
+TEST(GGUFOps, GeGLUQuickOneInputSwapped) {
+ auto model = SingleOpBuilder()
+ .op("GGML_GLU_OP_GEGLU_QUICK")
+ .input("x", ov::element::f32, {1, 8})
+ .output("out", ov::element::f32, {1, 4})
+ .attr<bool>("swapped", true)
+ .build();
+ std::vector<float> x{1, 2, 3, 4, -1, -2, 0.5f, 1.5f};
+ auto out = run_on_cpu(model, {{"x", make_f32_tensor({1, 8}, x)}});
+ std::vector<float> expected(4);
+ for (size_t i = 0; i < expected.size(); ++i) {
+ const float gate = x[4 + i];
+ expected[i] = gate / (1.0f + std::exp(-1.702f * gate)) * x[i];
+ }
+ expect_near(out, expected);
+}
+
+TEST(GGUFOps, GeGLUQuickTwoInputs) {
+ auto model = SingleOpBuilder()
+ .op("GGML_GLU_OP_GEGLU_QUICK")
+ .input("gate", ov::element::f32, {1, 3})
+ .input("up", ov::element::f32, {1, 3})
+ .output("out", ov::element::f32, {1, 3})
+ .attr<bool>("swapped", false)
+ .build();
+ std::vector<float> gate{-2.0f, 0.5f, 3.0f};
+ std::vector<float> up{4.0f, -1.0f, 2.0f};
+ auto out = run_on_cpu(model, {{"gate", make_f32_tensor({1, 3}, gate)}, {"up", make_f32_tensor({1, 3}, up)}});
+ std::vector<float> expected(3);
+ for (size_t i = 0; i < expected.size(); ++i) {
+ expected[i] = gate[i] / (1.0f + std::exp(-1.702f * gate[i])) * up[i];
+ }
+ expect_near(out, expected);
+}
+
+TEST(GGUFOps, Pool2DMaxAndAverage) {
+ const std::vector<float> input{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
+ const std::vector<int32_t> params{2, 2, 2, 1, 1, 0};
+
+ auto max_model = SingleOpBuilder()
+ .op("GGML_OP_POOL_2D")
+ .input("x", ov::element::f32, {1, 1, 3, 4})
+ .output("out", ov::element::f32, {1, 1, 2, 3})
+ .op_case(1)
+ .attr<std::vector<int32_t>>("pool_params", params)
+ .build();
+ auto avg_model = SingleOpBuilder()
+ .op("GGML_OP_POOL_2D")
+ .input("x", ov::element::f32, {1, 1, 3, 4})
+ .output("out", ov::element::f32, {1, 1, 2, 3})
+ .op_case(2)
+ .attr<std::vector<int32_t>>("pool_params", params)
+ .build();
+
+ auto tensor = make_f32_tensor({1, 1, 3, 4}, input);
+ expect_near(run_on_cpu(max_model, {{"x", tensor}}), {5, 7, 8, 9, 11, 12});
+ expect_near(run_on_cpu(avg_model, {{"x", tensor}}), {1.5f, 4.5f, 3.0f, 3.5f, 8.5f, 5.0f});
+}
+
+TEST(GGUFOps, Pool2DF16InputProducesF32) {
+ auto model = SingleOpBuilder()
+ .op("GGML_OP_POOL_2D")
+ .input("x", ov::element::f16, {1, 1, 2, 3})
+ .output("out", ov::element::f32, {1, 1, 1, 2})
+ .op_case(1)
+ .attr<std::vector<int32_t>>("pool_params", {2, 2, 1, 1, 0, 0})
+ .build();
+
+ auto out = run_on_cpu(model, {{"x", make_f16_tensor({1, 1, 2, 3}, {1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f})}});
+ expect_near(out, {5.0f, 6.0f});
+}
+
+TEST(GGUFOps, Pool2DRejectsInvalidParams) {
+ const std::vector<std::vector<int32_t>> invalid_params{
+ {-1, 2, 1, 1, 0, 0},
+ {2, 0, 1, 1, 0, 0},
+ {2, 2, -1, 1, 0, 0},
+ {2, 2, 1, 0, 0, 0},
+ {2, 2, 1, 1, -1, 0},
+ {2, 2, 1, 1, 0, -1},
+ };
+ for (const auto& params : invalid_params) {
+ EXPECT_THROW(SingleOpBuilder()
+ .op("GGML_OP_POOL_2D")
+ .input("x", ov::element::f32, {1, 1, 2, 2})
+ .output("out", ov::element::f32, {1, 1, 1, 1})
+ .op_case(2)
+ .attr<std::vector<int32_t>>("pool_params", params)
+ .build(),
+ ov::Exception);
+ }
+}
+
+TEST(GGUFOps, RollFourAxes) {
+ auto model = SingleOpBuilder()
+ .op("GGML_OP_ROLL")
+ .input("x", ov::element::f32, {2, 2, 2, 3})
+ .output("out", ov::element::f32, {2, 2, 2, 3})
+ .attr<std::vector<int64_t>>("roll_shifts", {1, -1, 1, -1})
+ .build();
+ std::vector<float> input(24);
+ for (size_t i = 0; i < input.size(); ++i) {
+ input[i] = static_cast<float>(i);
+ }
+ std::vector<float> expected(24);
+ for (int a = 0; a < 2; ++a) {
+ for (int b = 0; b < 2; ++b) {
+ for (int c = 0; c < 2; ++c) {
+ for (int d = 0; d < 3; ++d) {
+ const int src_a = (a - 1 + 2) % 2;
+ const int src_b = (b + 1) % 2;
+ const int src_c = (c - 1 + 2) % 2;
+ const int src_d = (d + 1) % 3;
+ expected[((a * 2 + b) * 2 + c) * 3 + d] = input[((src_a * 2 + src_b) * 2 + src_c) * 3 + src_d];
+ }
+ }
+ }
+ }
+ expect_near(run_on_cpu(model, {{"x", make_f32_tensor({2, 2, 2, 3}, input)}}), expected, 0.0f);
+}
+
+TEST(GGUFOps, SolveTriBatched) {
+ auto builder = SingleOpBuilder()
+ .op("GGML_OP_SOLVE_TRI")
+ .input("a", ov::element::f32, {2, 1, 3, 3})
+ .input("b", ov::element::f32, {2, 1, 3, 2})
+ .output("out", ov::element::f32, {2, 1, 3, 2})
+ .attr<std::vector<int32_t>>("solve_tri_params", {1, 1, 0});
+ auto model = builder.build();
+ std::vector<float> a{2, 0, 0, 3, 1, 0, 1, -1, 2, 1, 0, 0, 2, 2, 0, -1, 1, 1};
+ std::vector<float> b{2, 4, 5, 7, 3, 1, 1, 3, 4, 8, 2, 5};
+ auto out = run_on_cpu(model, {{"a", make_f32_tensor({2, 1, 3, 3}, a)}, {"b", make_f32_tensor({2, 1, 3, 2}, b)}});
+ expect_near(out, {1, 2, 2, 1, 2, 0, 1, 3, 1, 1, 2, 7});
+
+ EXPECT_THROW(SingleOpBuilder()
+ .op("GGML_OP_SOLVE_TRI")
+ .input("a", ov::element::f32, {1, 1, 2, 2})
+ .input("b", ov::element::f32, {1, 1, 2, 1})
+ .output("out", ov::element::f32, {1, 1, 2, 1})
+ .attr<std::vector<int32_t>>("solve_tri_params", {0, 1, 0})
+ .build(),
+ ov::Exception);
+}
+
// Add1: ggml adds a (broadcast) scalar to the input. The translator is the generic 2-input Add,
// which broadcasts the [1,1] operand across the [2,4] input.
TEST(GGUFOps, Add1) {
@@ -2634,6 +3088,35 @@ TEST(GGUFOps, Diag) {
expect_near(out, expected);
}
+TEST(GGUFOps, DiagKeepsInputPort) {
+ using namespace ov::frontend::gguf;
+ auto data = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 1, 1, 4});
+ auto k = ov::op::v0::Constant::create(ov::element::i64, ov::Shape{}, {2});
+ auto topk = std::make_shared<ov::op::v11::TopK>(data,
+ k,
+ -1,
+ ov::op::v11::TopK::Mode::MAX,
+ ov::op::v11::TopK::SortType::SORT_VALUES,
+ ov::element::i32);
+ auto decoder = SingleOpBuilder()
+ .op("GGML_OP_DIAG")
+ .input("x", ov::element::i32, {1, 1, 1, 2})
+ .output("out", ov::element::i32, {1, 1, 2, 2})
+ .decoder();
+ auto tensors = std::make_shared<TensorMap>();
+ (*tensors)["x"] = topk->output(1);
+ NodeContext context(decoder, tensors);
+ auto diag = op::translate_diag(context)[0];
+ auto multiply = ov::as_type_ptr<ov::op::v1::Multiply>(diag.get_node_shared_ptr());
+ ASSERT_NE(multiply, nullptr);
+ auto eye = ov::as_type_ptr<ov::op::v9::Eye>(multiply->input_value(1).get_node_shared_ptr());
+ ASSERT_NE(eye, nullptr);
+ auto shape_of = eye->input_value(0).get_node_shared_ptr()->input_value(0).get_node_shared_ptr();
+ ASSERT_NE(shape_of, nullptr);
+ EXPECT_EQ(shape_of->input_value(0).get_node_shared_ptr(), topk);
+ EXPECT_EQ(shape_of->input_value(0).get_index(), 1u);
+}
+
// Unary Sigmoid: 1 / (1 + exp(-x)) via the 1to1 template.
TEST(GGUFOps, UnarySigmoid) {
auto model = SingleOpBuilder()
@@ -2746,8 +3229,6 @@ TEST(GGUFOps, Fill) {
}
// Div: plain element-wise divide when both inputs already share a shape.
-// (The silu(x)/x -> sigmoid(x) fold requires input 0 to be a Multiply(x,Sigmoid(x)) node, which a
-// single-op decoder cannot express -- that path is exercised by the qwen2moe E2E test instead.)
TEST(GGUFOps, Div) {
auto model = SingleOpBuilder()
.op("GGML_OP_DIV")
@@ -2818,4 +3299,231 @@ TEST(GGUFOps, Set) {
expect_near(out, {1, 1, 10, 20, 1, 1, 1, 1});
}
+TEST(GGUFOps, AddMixedPrecisionPreservesLeftType) {
+ for (auto type : {ov::element::f32, ov::element::f16}) {
+ const auto rhs_type = type == ov::element::f32 ? ov::element::f16 : ov::element::f32;
+ auto model = SingleOpBuilder()
+ .op("GGML_OP_ADD")
+ .input("a", type, {1, 3})
+ .input("b", rhs_type, {1, 3})
+ .output("out", type, {1, 3})
+ .build();
+ auto a = type == ov::element::f32 ? make_f32_tensor({1, 3}, {1, 2, 3}) : make_f16_tensor({1, 3}, {1, 2, 3});
+ auto b = rhs_type == ov::element::f32 ? make_f32_tensor({1, 3}, {0.5f, -1, 2})
+ : make_f16_tensor({1, 3}, {0.5f, -1, 2});
+ auto out = run_on_cpu(model, {{"a", a}, {"b", b}});
+ ASSERT_EQ(out.get_element_type(), type);
+ const std::vector<float> expected{1.5f, 1, 5};
+ for (size_t i = 0; i < expected.size(); ++i) {
+ const float value = type == ov::element::f32 ? out.data<float>()[i] : float(out.data<ov::float16>()[i]);
+ EXPECT_EQ(value, expected[i]);
+ }
+ }
+}
+
+TEST(GGUFOps, SwigluClampF16RoundsOnce) {
+ auto model = SingleOpBuilder()
+ .op("GGML_GLU_OP_SWIGLU_CLAMP")
+ .input("gate", ov::element::f16, {1, 6})
+ .input("up", ov::element::f16, {1, 6})
+ .output("out", ov::element::f16, {1, 6})
+ .attr<bool>("swapped", false)
+ .attr<float>("glu_limit", 3.0f)
+ .build();
+ auto gate = make_f16_tensor({1, 6}, {-2.3f, -0.7f, 0.3f, 1.7f, 3.7f, -5.1f});
+ auto up = make_f16_tensor({1, 6}, {2.7f, -1.3f, 0.7f, -4.1f, 1.3f, 3.4f});
+ ov::TensorVector outputs{ov::Tensor(ov::element::f16, {1, 6})};
+ ASSERT_TRUE(model->evaluate(outputs, {gate, up}));
+ for (size_t i = 0; i < 6; ++i) {
+ const float g = std::min(float(gate.data<ov::float16>()[i]), 3.0f);
+ const float u = std::clamp(float(up.data<ov::float16>()[i]), -3.0f, 3.0f);
+ const ov::float16 expected(g / (1.0f + std::exp(-g)) * u);
+ EXPECT_EQ(outputs[0].data<ov::float16>()[i], expected);
+ }
+}
+
+TEST(GGUFOps, PermuteCase1RankThree) {
+ for (const auto& perm : {std::vector<int64_t>{0, 2, 1, 3}, std::vector<int64_t>{1, 0, 2}}) {
+ auto model = SingleOpBuilder()
+ .op("GGML_OP_PERMUTE")
+ .input("x", ov::element::f32, {-1, 3, 2})
+ .output("out", ov::element::f32, {3, -1, 2})
+ .op_case(1)
+ .attr<std::vector<int64_t>>("perm", perm)
+ .build();
+ auto out = run_on_cpu(model, {{"x", make_f32_tensor({2, 3, 2}, {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11})}});
+ ASSERT_EQ(out.get_shape(), (ov::Shape{3, 2, 2}));
+ expect_near(out, {0, 1, 6, 7, 2, 3, 8, 9, 4, 5, 10, 11});
+ }
+}
+
+TEST(GGUFOps, DiagDynamicWidth) {
+ auto model = SingleOpBuilder()
+ .op("GGML_OP_DIAG")
+ .input("x", ov::element::f32, {1, 2, 1, -1})
+ .output("out", ov::element::f32, {1, 2, -1, -1})
+ .build();
+ auto out = run_on_cpu(model, {{"x", make_f32_tensor({1, 2, 1, 2}, {2, 3, 5, 7})}});
+ ASSERT_EQ(out.get_shape(), (ov::Shape{1, 2, 2, 2}));
+ expect_near(out, {2, 0, 0, 3, 5, 0, 0, 7});
+}
+
+TEST(GGUFOps, DivSiluAtZero) {
+ using namespace ov::frontend::gguf;
+ auto x = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 3});
+ x->output(0).set_names({"x"});
+ auto silu_decoder = SingleOpBuilder()
+ .op("GGML_UNARY_OP_SILU")
+ .input("x", ov::element::f32, {1, 3})
+ .output("silu", ov::element::f32, {1, 3})
+ .decoder();
+ auto tensors = std::make_shared<TensorMap>();
+ (*tensors)["x"] = x;
+ NodeContext silu_context(silu_decoder, tensors);
+ (*tensors)["silu"] = op::translate_unary_silu(silu_context)[0];
+ auto decoder = SingleOpBuilder()
+ .op("GGML_OP_DIV")
+ .input("silu", ov::element::f32, {1, 3})
+ .input("x", ov::element::f32, {1, 3})
+ .output("out", ov::element::f32, {1, 3})
+ .decoder();
+ NodeContext context(decoder, tensors);
+ auto model = std::make_shared<ov::Model>(op::translate_div(context), ov::ParameterVector{x});
+ auto out = run_on_cpu(model, {{"x", make_f32_tensor({1, 3}, {0, -1, 1})}});
+ expect_near(out, {0.5f, 1.0f / (1.0f + std::exp(1.0f)), 1.0f / (1.0f + std::exp(-1.0f))});
+}
+
+TEST(GGUFOps, RopeOffsetPreservesPrefixAndTail) {
+ // ggml CPU oracle: rope_ext [8,2,2,1], dims=4, offset=2, positions={2,5}; normal and NEOX.
+ const std::vector<std::vector<float>> expected{
+ {-2, -1.75f, 1.76084197f, -0.843762517f, -0.984801054f, -0.769848704f, -0.5f, -0.25f,
+ 0, 0.25f, -0.890046477f, 0.142538577f, 0.974801719f, 1.26974869f, 1.5f, 1.75f,
+ 2, 2.25f, 3.34619737f, -1.61723971f, 2.83381844f, 3.39587569f, 3.5f, 3.75f,
+ 4, 4.25f, 5.83137035f, -2.9677639f, 4.73136091f, 5.49333477f, 5.5f, 5.75f},
+ {-2, -1.75f, 1.53351772f, -1.23475099f, -0.947799265f, -0.774848342f, -0.5f, -0.25f,
+ 0, 0.25f, -1.11737084f, 0.724851668f, 0.0385018587f, 1.26474905f, 1.5f, 1.75f,
+ 2, 2.25f, 3.58592844f, 2.584131f, -1.54632413f, 3.38338089f, 3.5f, 3.75f,
+ 4, 4.25f, 6.07110119f, 4.48167324f, -2.8968482f, 5.48083973f, 5.5f, 5.75f}};
+ for (int mode = 0; mode < 2; ++mode) {
+ RopeConfig cfg;
+ cfg.n_dims = 4;
+ cfg.n_ctx_orig = 4096;
+ cfg.freq_base = 10000;
+ cfg.freq_scale = 1;
+ cfg.attn_factor = 1;
+ auto model = SingleOpBuilder()
+ .op("GGML_OP_ROPE")
+ .input("data", ov::element::f32, {1, 2, 2, 8})
+ .input("pos", ov::element::i32, {1, 1, 1, 2})
+ .output("out", ov::element::f32, {1, 2, 2, 8})
+ .op_case(mode << 16)
+ .attr<RopeConfig>("rope_config", cfg)
+ .attr<int64_t>("rope_offset", 2)
+ .build();
+ std::vector<float> data(32);
+ for (size_t i = 0; i < data.size(); ++i)
+ data[i] = (float(i) - 8) * 0.25f;
+ ov::Tensor pos(ov::element::i32, {1, 1, 1, 2});
+ pos.data<int32_t>()[0] = 2;
+ pos.data<int32_t>()[1] = 5;
+ auto out = run_on_cpu(model, {{"data", make_f32_tensor({1, 2, 2, 8}, data)}, {"pos", pos}});
+ expect_near(out, expected[mode]);
+ }
+}
+
+TEST(GGUFOps, RopeInvalidOffsetThrows) {
+ for (int64_t offset : {-2, 1, 6}) {
+ RopeConfig cfg;
+ cfg.n_dims = 4;
+ cfg.freq_base = 10000;
+ cfg.freq_scale = 1;
+ cfg.attn_factor = 1;
+ EXPECT_ANY_THROW(SingleOpBuilder()
+ .op("GGML_OP_ROPE")
+ .input("data", ov::element::f32, {1, 2, 2, 8})
+ .input("pos", ov::element::i32, {1, 1, 1, 2})
+ .output("out", ov::element::f32, {1, 2, 2, 8})
+ .attr<RopeConfig>("rope_config", cfg)
+ .attr<int64_t>("rope_offset", offset)
+ .build());
+ }
+}
+
+TEST(GGUFOps, ContDynamicLayoutRequiresReshape) {
+ for (int op_case : {1, 2, 3}) {
+ auto builder = SingleOpBuilder()
+ .op("GGML_OP_CONT")
+ .input("x", ov::element::f32, {1, -1, 3, 2})
+ .output("out", ov::element::f32, {1, 3, -1, 2})
+ .op_case(op_case);
+ EXPECT_THROW(builder.build(), ov::Exception);
+ auto model = builder.attr<std::vector<int64_t>>("cont_reshape", {1, 3, -1, 2}).build();
+ std::vector<float> values{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11};
+ auto out = run_on_cpu(model, {{"x", make_f32_tensor({1, 2, 3, 2}, values)}});
+ EXPECT_EQ(out.get_shape(), (ov::Shape{1, 3, 2, 2}));
+ expect_near(out, values);
+
+ auto without_metadata = builder.output("out", ov::element::f32, ov::PartialShape::dynamic()).build();
+ auto reshaped = run_on_cpu(without_metadata, {{"x", make_f32_tensor({1, 2, 3, 2}, values)}});
+ EXPECT_EQ(reshaped.get_shape(), (ov::Shape{1, 3, 2, 2}));
+ expect_near(reshaped, values);
+ }
+}
+
+TEST(GGUFOps, ContDynamicPassThroughPreservesProducer) {
+ for (int op_case : {1, 2, 3}) {
+ auto model = SingleOpBuilder()
+ .op("GGML_OP_CONT")
+ .input("x", ov::element::f32, {1, -1, 3, 2})
+ .output("out", ov::element::f32, {1, -1, 3, 2})
+ .op_case(op_case)
+ .build();
+ EXPECT_EQ(model->get_results()[0]->input_value(0).get_node_shared_ptr(), model->get_parameters()[0]);
+ EXPECT_EQ(model->get_parameters()[0]->get_friendly_name(), "x");
+ auto without_metadata = SingleOpBuilder()
+ .op("GGML_OP_CONT")
+ .input("x", ov::element::f32, {1, -1, 3, 2})
+ .output("out", ov::element::f32, ov::PartialShape::dynamic())
+ .op_case(op_case)
+ .build();
+ EXPECT_EQ(without_metadata->get_results()[0]->input_value(0).get_node_shared_ptr(),
+ without_metadata->get_parameters()[0]);
+ }
+}
+
+TEST(GGUFOps, Pool2DF16AverageWithoutOutputType) {
+ std::shared_ptr<ov::frontend::gguf::GgufDecoder> decoder = std::make_shared<SingleOpDecoder>(
+ "GGML_OP_POOL_2D",
+ std::vector<TensorDesc>{{"x", ov::element::f16, {1, 1, 2, 2}}},
+ std::vector<TensorDesc>{},
+ TensorDesc{"out", ov::element::f32, {1, 1, 1, 1}},
+ std::map<std::string, ov::Any>{{"op_case", 2}, {"pool_params", std::vector<int32_t>{2, 2, 1, 1, 0, 0}}});
+ ov::frontend::gguf::FrontEnd frontend;
+ auto model = frontend.convert(frontend.load(decoder));
+ auto input = make_f16_tensor({1, 1, 2, 2}, {2048, 1, 0, 0});
+ // ggml CPU oracle: F16 2x2 AVG pool of {2048,1,0,0}; F16 accumulation/output loses 0.25.
+ auto out = run_on_cpu(model, {{"x", input}});
+ ASSERT_EQ(out.get_element_type(), ov::element::f32);
+ EXPECT_FLOAT_EQ(out.data<float>()[0], 512.25f);
+}
+
+TEST(GGUFOps, SolveTriDynamicBatchDimensions) {
+ auto model = SingleOpBuilder()
+ .op("GGML_OP_SOLVE_TRI")
+ .input("a", ov::element::f32, {-1, -1, 3, 3})
+ .input("b", ov::element::f32, {-1, -1, 3, 2})
+ .output("out", ov::element::f32, {-1, -1, 3, 2})
+ .attr<std::vector<int32_t>>("solve_tri_params", {1, 1, 0})
+ .build();
+ const std::vector<float> a{2, 0, 0, 3, 1, 0, 1, -1, 2, 1, 0, 0, 2, 2, 0, -1, 1, 1};
+ const std::vector<float> b{2, 4, 5, 7, 3, 1, 1, 3, 4, 8, 2, 5};
+ for (size_t batch : {1, 2}) {
+ auto out = run_on_cpu(
+ model,
+ {{"a", make_f32_tensor({batch, 2 / batch, 3, 3}, a)}, {"b", make_f32_tensor({batch, 2 / batch, 3, 2}, b)}});
+ EXPECT_EQ(out.get_shape(), (ov::Shape{batch, 2 / batch, 3, 2}));
+ expect_near(out, {1, 2, 2, 1, 2, 0, 1, 3, 1, 1, 2, 7});
+ }
+}
+
} // namespace