OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[GGUF] Reduce recurrent-attention decode overhead (#39336)
Maxim Vafin5c6917ed75a7
diff --git a/src/frontends/gguf/src/builder/blocks/gated_delta_net.cpp b/src/frontends/gguf/src/builder/blocks/gated_delta_net.cppindex 3690e265b08..62ab88d2ed0 100644--- a/src/frontends/gguf/src/builder/blocks/gated_delta_net.cpp+++ b/src/frontends/gguf/src/builder/blocks/gated_delta_net.cpp@@ -132,7 +132,8 @@ std::string gated_delta_net(GraphEmitter& e, const DecoderConfig& cfg, int il, cstd::string alpha_base = p + "ssm_alpha", beta_base = p + "ssm_beta";std::string conv_w = p + "ssm_conv1d.weight", a_w = p + "ssm_a", dt_w = p + "ssm_dt.bias";bool gqa_grouped = false;- if (!e.has_hadamard() && H_v != H_k && H_v % H_k == 0) {+ const bool grouped_hadamard = e.has_grouped_hadamard_gdn();+ if ((!e.has_hadamard() || grouped_hadamard) && H_v != H_k && H_v % H_k == 0) {const int64_t rep = H_v / H_k;std::vector<int64_t> src(H_v);for (int64_t n = 0; n < H_v; ++n) {@@ -144,6 +145,8 @@ std::string gated_delta_net(GraphEmitter& e, const DecoderConfig& cfg, int il, c};};const auto cols = [&](const ov::Tensor& t) {+ if (grouped_hadamard)+ return t;return permute_col_blocks(t, value_dim, head_v, src);};struct Grouped {@@ -169,7 +172,10 @@ std::string gated_delta_net(GraphEmitter& e, const DecoderConfig& cfg, int il, cif (ok) {const std::string g = "_grouped";for (auto& w : grouped) {+ if (grouped_hadamard && &w.base == &out_base)+ continue;store_parts(e, w.base + g, w.parts, e.weight_qtype(w.base));+ e.inherit_hadamard(w.base + g + ".weight", w.base + ".weight");w.base += g;}conv_w = p + "ssm_conv1d" + g + ".weight", a_w = p + "ssm_a" + g, dt_w = p + "ssm_dt" + g + ".bias";@@ -184,14 +190,15 @@ std::string gated_delta_net(GraphEmitter& e, const DecoderConfig& cfg, int il, ce.add_weight(qkv_base + ".weight");auto qkv = e.add_op("GGML_OP_MUL_MAT", p + "qkv_mixed", {qkv_base + ".weight", attn_norm});- // z, ssm_beta and ssm_alpha share the input. beta/alpha produce one scalar per v-head, and- // such a narrow matmul costs about as much as a wide one, so all three run as one matmul when- // they share a quantization layout. Widening z to merge would cost more weight bandwidth.+ // Merge compatible projections without widening z. Standalone FP32 scalar projections+ // remain separate so their bias and activations can fuse into FCs.std::string z, beta, alpha;- auto ba = concat_rows(e.weight_parts(beta_base),- e.weight_parts(alpha_base),- e.weight_qtype(beta_base),- e.weight_qtype(alpha_base));+ const bool dense_gates = e.weight_qtype(beta_base) == GGUF_TYPE_F32 && e.weight_qtype(alpha_base) == GGUF_TYPE_F32;+ auto ba = !dense_gates || !e.has_hadamard() ? concat_rows(e.weight_parts(beta_base),+ e.weight_parts(alpha_base),+ e.weight_qtype(beta_base),+ e.weight_qtype(alpha_base))+ : std::nullopt;auto zba = ba && !e.has_hadamard()? concat_rows(e.weight_parts(gate_base), *ba, e.weight_qtype(gate_base), e.weight_qtype(beta_base)): std::nullopt;@@ -210,7 +217,7 @@ std::string gated_delta_net(GraphEmitter& e, const DecoderConfig& cfg, int il, c{zba_out},3,{{"view_slice", std::vector<int64_t>{3, value_dim + H_v, H_v}}});- } else if (ba) {+ } else if (ba && !dense_gates) {e.add_weight(gate_base + ".weight");z = e.add_op("GGML_OP_MUL_MAT", p + "z", {gate_base + ".weight", attn_norm});store_parts(e, p + "ssm_beta_alpha", *ba, e.weight_qtype(beta_base));@@ -219,12 +226,13 @@ std::string gated_delta_net(GraphEmitter& e, const DecoderConfig& cfg, int il, cbeta = e.add_op("GGML_OP_VIEW", p + "beta", {ba_out}, 3, {{"view_slice", std::vector<int64_t>{3, 0, H_v}}});alpha = e.add_op("GGML_OP_VIEW", p + "alpha", {ba_out}, 3, {{"view_slice", std::vector<int64_t>{3, H_v, H_v}}});} else {+ const std::map<std::string, ov::Any> gate_attrs{{"activation_rank", dense_gates ? 3 : 4}};e.add_weight(gate_base + ".weight");z = e.add_op("GGML_OP_MUL_MAT", p + "z", {gate_base + ".weight", attn_norm});e.add_weight(beta_base + ".weight");- beta = e.add_op("GGML_OP_MUL_MAT", p + "beta", {beta_base + ".weight", attn_norm});+ beta = e.add_op("GGML_OP_MUL_MAT", p + "beta", {beta_base + ".weight", attn_norm}, 0, gate_attrs);e.add_weight(alpha_base + ".weight");- alpha = e.add_op("GGML_OP_MUL_MAT", p + "alpha", {alpha_base + ".weight", attn_norm});+ alpha = e.add_op("GGML_OP_MUL_MAT", p + "alpha", {alpha_base + ".weight", attn_norm}, 0, gate_attrs);}// beta = sigmoid(ssm_beta @ x), one scalar per v-head@@ -325,7 +333,11 @@ std::string gated_delta_net(GraphEmitter& e, const DecoderConfig& cfg, int il, c{"shape_axes", std::vector<int64_t>{0, 1, 2, -1}}});e.add_weight(out_base + ".weight");- return e.add_op("GGML_OP_MUL_MAT", p + "linear_attn_out", {out_base + ".weight", out});+ return e.add_op("GGML_OP_MUL_MAT",+ p + "linear_attn_out",+ {out_base + ".weight", out},+ 0,+ {{"gqa_grouped", gqa_grouped}});}} // namespace ov::frontend::gguf::blocksdiff --git a/src/frontends/gguf/src/builder/graph_emitter.cpp b/src/frontends/gguf/src/builder/graph_emitter.cppindex b8017417aa2..90cf0f3ce22 100644--- a/src/frontends/gguf/src/builder/graph_emitter.cpp+++ b/src/frontends/gguf/src/builder/graph_emitter.cpp@@ -100,7 +100,9 @@ std::string GraphEmitter::add_op(const std::string& op_type,OPENVINO_ASSERT(m_hadamard_signs.count(width), "[GGUF] missing Hadamard signs for width ", width);attrs["hadamard_signs"] = m_hadamard_signs.at(width);}- if (op_type == "GGML_OP_MUL_MAT" && m_hadamard_v_heads && inputs[0].find(".ssm_out.") != std::string::npos) {+ const bool gqa_grouped = attrs.count("gqa_grouped") && attrs.at("gqa_grouped").as<bool>();+ if (op_type == "GGML_OP_MUL_MAT" && m_hadamard_v_heads && !gqa_grouped &&+ inputs[0].find(".ssm_out.") != std::string::npos) {OPENVINO_ASSERT(width % m_hadamard_v_heads == 0, "[GGUF] invalid Hadamard GDN width");attrs["hadamard_gdn_heads"] = std::vector<int64_t>{m_hadamard_v_heads / m_hadamard_k_heads,m_hadamard_k_heads,diff --git a/src/frontends/gguf/src/builder/graph_emitter.hpp b/src/frontends/gguf/src/builder/graph_emitter.hppindex e351a0bb641..ecf4fdbaf1f 100644--- a/src/frontends/gguf/src/builder/graph_emitter.hpp+++ b/src/frontends/gguf/src/builder/graph_emitter.hpp@@ -118,6 +118,9 @@ public:bool has_hadamard() const {return m_hadamard_block != 0;}+ bool has_grouped_hadamard_gdn() const {+ return m_hadamard_v_heads > 0;+ }void inherit_hadamard(const std::string& name, const std::string& source);private:diff --git a/src/frontends/gguf/src/op/gated_delta_net.cpp b/src/frontends/gguf/src/op/gated_delta_net.cppindex 1d93b5519e8..e41e8bd01c5 100644--- a/src/frontends/gguf/src/op/gated_delta_net.cpp+++ b/src/frontends/gguf/src/op/gated_delta_net.cpp@@ -8,10 +8,12 @@#include <cstdint>#include <memory>#include <numeric>+#include <optional>#include <vector>#include "node_context.hpp"#include "op_table.hpp"+#include "openvino/core/rt_info.hpp"#include "openvino/op/add.hpp"#include "openvino/op/broadcast.hpp"#include "openvino/op/concat.hpp"@@ -25,17 +27,77 @@#include "openvino/op/multiply.hpp"#include "openvino/op/reshape.hpp"#include "openvino/op/shape_of.hpp"+#include "openvino/op/slice.hpp"+#include "openvino/op/split.hpp"#include "openvino/op/squeeze.hpp"#include "openvino/op/subtract.hpp"#include "openvino/op/tile.hpp"#include "openvino/op/transpose.hpp"#include "openvino/op/unsqueeze.hpp"+#include "transformations/utils/utils.hpp"#include "utils.hpp"namespace ov::frontend::gguf::op {static OutputVector translate_gated_delta_net_ref(const NodeContext& context);+namespace {++struct FeatureSlice {+ std::shared_ptr<ov::op::v1::Reshape> reshape;+ std::shared_ptr<ov::op::v8::Slice> slice;+ int64_t begin, end;+};++std::optional<FeatureSlice> match_feature_slice(const Output<Node>& value, const std::vector<int64_t>& target) {+ using ov::op::util::has_constant_value;+ const auto reshape = ov::as_type_ptr<ov::op::v1::Reshape>(value.get_node_shared_ptr());+ if (!reshape || !reshape->get_special_zero() ||+ !has_constant_value<int64_t>(reshape->get_input_node_shared_ptr(1), target))+ return std::nullopt;+ const auto slice = ov::as_type_ptr<ov::op::v8::Slice>(reshape->get_input_node_shared_ptr(0));+ if (!slice || slice->get_input_size() != 5 ||+ !has_constant_value<int64_t>(slice->get_input_node_shared_ptr(3), 1) ||+ !has_constant_value<int64_t>(slice->get_input_node_shared_ptr(4), 3))+ return std::nullopt;+ const auto begin = ov::as_type_ptr<ov::op::v0::Constant>(slice->get_input_node_shared_ptr(1));+ const auto end = ov::as_type_ptr<ov::op::v0::Constant>(slice->get_input_node_shared_ptr(2));+ if (!begin || !end || ov::shape_size(begin->get_shape()) != 1 || ov::shape_size(end->get_shape()) != 1)+ return std::nullopt;+ return FeatureSlice{reshape, slice, begin->cast_vector<int64_t>()[0], end->cast_vector<int64_t>()[0]};+}++} // namespace++static Output<Node> join_adjacent_qk(const Output<Node>& q, const Output<Node>& k) {+ const auto shape = q.get_partial_shape();+ if (shape.rank() != 4 || !shape[2].is_static() || !shape[3].is_static() ||+ q.get_element_type() != k.get_element_type())+ return {};+ const auto heads = shape[2].get_length(), width = shape[3].get_length();+ const std::vector<int64_t> target{0, -1, heads, width};+ const auto qs = match_feature_slice(q, target);+ const auto ks = match_feature_slice(k, target);+ if (!qs || !ks || qs->slice->input_value(0) != ks->slice->input_value(0))+ return {};+ const auto source_shape = qs->slice->get_input_partial_shape(0);+ if (qs->begin < 0 || qs->end - qs->begin != heads * width || ks->begin != qs->end ||+ ks->end - ks->begin != heads * width || source_shape.rank() != 4 || source_shape[1] != 1 ||+ !source_shape[3].is_static() || ks->end > source_shape[3].get_length())+ return {};+ const auto slice = std::make_shared<ov::op::v8::Slice>(qs->slice->input_value(0),+ qs->slice->input_value(1),+ ks->slice->input_value(2),+ qs->slice->input_value(3),+ qs->slice->input_value(4));+ const auto joined = std::make_shared<ov::op::v1::Reshape>(+ slice,+ ov::op::v0::Constant::create<int64_t>(ov::element::i64, {4}, {0, -1, 2 * heads, width}),+ true);+ ov::copy_runtime_info({qs->slice, ks->slice, qs->reshape, ks->reshape}, {slice, joined});+ return joined;+}+// GGML_OP_GATED_DELTA_NET (qwen3next linear-attention block). Emits the internal (non-opset) op// ov::op::internal::GatedDeltaNet for the device's fused kernel; a model using it is not// IR-serializable (see docs/runtime.md). The fused op only supports scalar gating, so the@@ -82,8 +144,15 @@ OutputVector translate_gated_delta_net(const NodeContext& context) {// square root instead, which differs for small vectors, so normalize here.if (context.get_attribute<bool>("fuse_qk_l2norm", false)) {const float eps = context.get_attribute<float>("qk_l2_norm_eps", 1e-6f);- q = make_l2_norm(q, eps);- k = make_l2_norm(k, eps);+ if (const auto joined = join_adjacent_qk(q, k); joined.get_node()) {+ const auto axis = ov::op::v0::Constant::create(ov::element::i64, {}, {2});+ const auto normalized = std::make_shared<ov::op::v1::Split>(make_l2_norm(joined, eps), axis, 2);+ q = normalized->output(0);+ k = normalized->output(1);+ } else {+ q = make_l2_norm(q, eps);+ k = make_l2_norm(k, eps);+ }}// ggml maps GQA heads in tiled order, while the OV op maps repeated heads in grouped order:diff --git a/src/frontends/gguf/src/pass/adapt_to_genai.cpp b/src/frontends/gguf/src/pass/adapt_to_genai.cppindex efb602ae5d2..9f41500827e 100644--- a/src/frontends/gguf/src/pass/adapt_to_genai.cpp+++ b/src/frontends/gguf/src/pass/adapt_to_genai.cpp@@ -52,6 +52,7 @@#include "openvino/pass/matcher_pass.hpp"#include "openvino/pass/pattern/op/wrap_type.hpp"#include "openvino/runtime/properties.hpp"+#include "pass/simplify_activation_shapes.hpp"#include "utils.hpp"namespace ov::frontend::gguf::pass {@@ -775,6 +776,9 @@ bool AdaptToGenAI::run_on_model(const std::shared_ptr<ov::Model>& model) {if (!uses_ids)model->remove_parameter(input_ids);}+ ov::pass::Manager activation_shapes_manager;+ activation_shapes_manager.register_pass<SimplifyActivationShapes>();+ activation_shapes_manager.run_passes(model);return true;}diff --git a/src/frontends/gguf/src/pass/isolate_precision_sensitive_outputs.cpp b/src/frontends/gguf/src/pass/isolate_precision_sensitive_outputs.cppnew file mode 100644index 00000000000..0ac0e0221c6--- /dev/null+++ b/src/frontends/gguf/src/pass/isolate_precision_sensitive_outputs.cpp@@ -0,0 +1,40 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "pass/isolate_precision_sensitive_outputs.hpp"++#include "openvino/core/rt_info.hpp"+#include "openvino/op/convert.hpp"+#include "openvino/op/split.hpp"+#include "openvino/pass/pattern/op/wrap_type.hpp"+#include "openvino/util/pp.hpp"+#include "transformations/rt_info/disable_precision_conversion.hpp"++namespace ov::frontend::gguf::pass {++IsolatePrecisionSensitiveOutputs::IsolatePrecisionSensitiveOutputs() {+ const auto protected_fp32 = ov::pass::pattern::any_input([](const ov::Output<ov::Node>& value) {+ return value.get_element_type() == ov::element::f32 &&+ ov::is_conversion_disabled(value.get_node_shared_ptr(), ov::element::f16);+ });+ const auto split = ov::pass::pattern::wrap_type<ov::op::v1::Split>(+ {protected_fp32, ov::pass::pattern::any_input()},+ [](const ov::Output<ov::Node>& value) {+ return !ov::is_conversion_disabled(value.get_node_shared_ptr(), ov::element::f16);+ });+ const ov::matcher_pass_callback callback = [OV_CAPTURE_CPY_AND_THIS](ov::pass::pattern::Matcher& matcher) {+ const auto node = matcher.get_match_root();+ if (transformation_callback(node))+ return false;+ const auto input = matcher.get_pattern_value_map().at(protected_fp32);+ const auto boundary = std::make_shared<ov::op::v0::Convert>(input, input.get_element_type());+ ov::copy_runtime_info(node, boundary);+ node->input(0).replace_source_output(boundary);+ return true;+ };+ register_matcher(std::make_shared<ov::pass::pattern::Matcher>(split, "gguf::IsolatePrecisionSensitiveOutputs"),+ callback);+}++} // namespace ov::frontend::gguf::passdiff --git a/src/frontends/gguf/src/pass/isolate_precision_sensitive_outputs.hpp b/src/frontends/gguf/src/pass/isolate_precision_sensitive_outputs.hppnew file mode 100644index 00000000000..d3bc047b487--- /dev/null+++ b/src/frontends/gguf/src/pass/isolate_precision_sensitive_outputs.hpp@@ -0,0 +1,20 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/pass/matcher_pass.hpp"++namespace ov::frontend::gguf::pass {++// Add a same-type Convert between a protected FP32 producer and an unprotected Split.+// Inference-precision lowering can then convert once before splitting, while retaining+// the producer's computation precision and the original graph's types and values.+class IsolatePrecisionSensitiveOutputs : public ov::pass::MatcherPass {+public:+ OPENVINO_MATCHER_PASS_RTTI("ov::frontend::gguf::pass::IsolatePrecisionSensitiveOutputs");+ IsolatePrecisionSensitiveOutputs();+};++} // namespace ov::frontend::gguf::passdiff --git a/src/frontends/gguf/src/pass/simplify_activation_shapes.cpp b/src/frontends/gguf/src/pass/simplify_activation_shapes.cppnew file mode 100644index 00000000000..2acfa9fa4ca--- /dev/null+++ b/src/frontends/gguf/src/pass/simplify_activation_shapes.cpp@@ -0,0 +1,167 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "pass/simplify_activation_shapes.hpp"++#include <algorithm>+#include <unordered_set>++#include "openvino/core/graph_util.hpp"+#include "openvino/core/rt_info.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/convert.hpp"+#include "openvino/op/gather.hpp"+#include "openvino/op/normalize_l2.hpp"+#include "openvino/op/reduce_mean.hpp"+#include "openvino/op/reduce_sum.hpp"+#include "openvino/op/reshape.hpp"+#include "openvino/op/squeeze.hpp"+#include "openvino/op/swish.hpp"+#include "openvino/op/unsqueeze.hpp"+#include "openvino/op/util/binary_elementwise_arithmetic.hpp"+#include "openvino/op/util/symbolic_info.hpp"+#include "openvino/op/util/unary_elementwise_arithmetic.hpp"+#include "openvino/pass/manager.hpp"+#include "transformations/symbolic_transformations/symbolic_optimizations.hpp"+#include "transformations/symbolic_transformations/utils.hpp"+#include "transformations/utils/utils.hpp"++namespace ov::frontend::gguf::pass {+namespace {++bool activation_shape(const ov::PartialShape& shape) {+ return shape.rank() == 4 && shape[1] == 1;+}++ov::PartialShape reduced_shape(const ov::PartialShape& shape) {+ return {shape[0], shape[2], shape[3]};+}++bool same_shape(const ov::PartialShape& lhs, const ov::PartialShape& rhs) {+ if (lhs.rank().is_dynamic() || lhs.rank() != rhs.rank())+ return false;+ for (size_t i = 0; i < lhs.size(); ++i) {+ if (!ov::symbol::util::dims_are_equal(lhs[i], rhs[i]))+ return false;+ }+ return true;+}++ov::Output<ov::Node> unwrapped(const ov::Output<ov::Node>& value) {+ const auto node = ov::as_type_ptr<ov::op::v0::Unsqueeze>(value.get_node_shared_ptr());+ if (node && node->input_value(0).get_partial_shape().rank() == 3 &&+ ov::op::util::has_constant_value<int64_t>(node->get_input_node_shared_ptr(1), 1))+ return node->input_value(0);+ return value;+}++} // namespace++bool SimplifyActivationShapes::run_on_model(const std::shared_ptr<ov::Model>& model) {+ ov::pass::Manager symbols;+ symbols.set_per_pass_validation(false);+ symbols.register_pass<ov::pass::SymbolicPropagation>();+ symbols.run_passes(model);+ const auto nodes = model->get_ordered_ops();+ std::unordered_set<const ov::Node*> constants;+ for (const auto& node : nodes) {+ const auto inputs = node->inputs();+ if (ov::is_type<ov::op::v0::Constant>(node) ||+ (!inputs.empty() && std::all_of(inputs.begin(), inputs.end(), [&](const auto& input) {+ return constants.count(input.get_source_output().get_node());+ }))) {+ constants.insert(node.get());+ }+ }+ const auto axis = ov::op::v0::Constant::create(ov::element::i64, {1}, {1});+ bool changed = false;+ for (const auto& node : nodes) {+ if (constants.count(node.get()) || node->get_output_size() != 1 ||+ !node->get_output_element_type(0).is_real() || transformation_callback(node)) {+ continue;+ }+ const auto shape = node->get_output_partial_shape(0);+ const auto reshape = ov::as_type_ptr<ov::op::v1::Reshape>(node);+ if (reshape && shape.rank() == 3) {+ const auto value = unwrapped(reshape->input_value(0));+ if (same_shape(value.get_partial_shape(), shape)) {+ changed |= ov::replace_output_update_name(node->output(0), value);+ }+ continue;+ }+ if (!activation_shape(shape))+ continue;+ ov::Output<ov::Node> result;+ ov::NodeVector created;+ const auto lower = [&](const ov::Output<ov::Node>& input) -> ov::Output<ov::Node> {+ if (!activation_shape(input.get_partial_shape()))+ return input;+ const auto value = unwrapped(input);+ if (value != input)+ return value;+ const auto squeezed = ov::op::util::make_try_fold<ov::op::v0::Squeeze>(input, axis);+ created.push_back(squeezed);+ return squeezed;+ };+ if (reshape) {+ const auto value = unwrapped(reshape->input_value(0));+ if (same_shape(value.get_partial_shape(), reduced_shape(shape))) {+ result = value;+ } else {+ const bool reduced_input = activation_shape(reshape->get_input_partial_shape(0));+ if (reshape->get_special_zero() && !reduced_input)+ continue;+ const auto indices = ov::op::v0::Constant::create(ov::element::i64, {3}, {0, 2, 3});+ const auto zero = ov::op::v0::Constant::create(ov::element::i64, {}, {0});+ const auto target =+ ov::op::util::make_try_fold<ov::op::v8::Gather>(reshape->input_value(1), indices, zero);+ created.insert(created.end(), {indices, zero, target});+ result = std::make_shared<ov::op::v1::Reshape>(reduced_input ? lower(reshape->input_value(0)) : value,+ target,+ reshape->get_special_zero());+ }+ } else if (ov::is_type_any_of<ov::op::v1::ReduceMean, ov::op::v1::ReduceSum, ov::op::v0::NormalizeL2>(node)) {+ if (!activation_shape(node->get_input_partial_shape(0)))+ continue;+ const auto axes = ov::as_type_ptr<ov::op::v0::Constant>(node->get_input_node_shared_ptr(1));+ if (!ov::op::util::has_constant_value<int64_t>(axes, -1) &&+ !ov::op::util::has_constant_value<int64_t>(axes, 3))+ continue;+ const auto last = ov::op::v0::Constant::create(axes->get_element_type(), axes->get_shape(), {-1});+ created.push_back(last);+ result = node->clone_with_new_inputs({lower(node->input_value(0)), last});+ } else {+ const auto binary = ov::as_type_ptr<ov::op::util::BinaryElementwiseArithmetic>(node);+ if (binary) {+ const auto type = binary->get_autob().m_type;+ if (type != ov::op::AutoBroadcastType::NUMPY && type != ov::op::AutoBroadcastType::NONE)+ continue;+ const auto inputs = node->input_values();+ if (type == ov::op::AutoBroadcastType::NONE &&+ !std::all_of(inputs.begin(), inputs.end(), [](const auto& input) {+ return activation_shape(input.get_partial_shape());+ }))+ continue;+ } else if (!ov::is_type_any_of<ov::op::util::UnaryElementwiseArithmetic,+ ov::op::v0::Convert,+ ov::op::v4::Swish>(node)) {+ continue;+ }+ ov::OutputVector inputs;+ for (const auto& input : node->input_values())+ inputs.push_back(lower(input));+ result = node->clone_with_new_inputs(inputs);+ }+ const auto restored = std::make_shared<ov::op::v0::Unsqueeze>(result, axis);+ restored->set_friendly_name(node->get_friendly_name());+ created.insert(created.end(), {result.get_node_shared_ptr(), restored});+ ov::copy_runtime_info({node, result.get_node_shared_ptr()}, created);+ ov::replace_node(node, restored);+ changed = true;+ }+ ov::remove_skip_invalidation_rti(model);+ return changed;+}++} // namespace ov::frontend::gguf::passdiff --git a/src/frontends/gguf/src/pass/simplify_activation_shapes.hpp b/src/frontends/gguf/src/pass/simplify_activation_shapes.hppnew file mode 100644index 00000000000..1ab988e7fbd--- /dev/null+++ b/src/frontends/gguf/src/pass/simplify_activation_shapes.hpp@@ -0,0 +1,19 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#pragma once++#include "openvino/pass/pass.hpp"++namespace ov::frontend::gguf::pass {++// Remove GGML's singleton activation axis through elementwise and normalization paths,+// preserving the original layout at consumers that require it.+class SimplifyActivationShapes : public ov::pass::ModelPass {+public:+ OPENVINO_MODEL_PASS_RTTI("ov::frontend::gguf::pass::SimplifyActivationShapes");+ bool run_on_model(const std::shared_ptr<ov::Model>& model) override;+};++} // namespace ov::frontend::gguf::passdiff --git a/src/frontends/gguf/src/translate_session.cpp b/src/frontends/gguf/src/translate_session.cppindex 449a62af964..855f61d2f2b 100644--- a/src/frontends/gguf/src/translate_session.cpp+++ b/src/frontends/gguf/src/translate_session.cpp@@ -45,6 +45,7 @@#include "openvino/op/transpose.hpp"#include "openvino/pass/constant_folding.hpp"#include "openvino/pass/manager.hpp"+#include "pass/isolate_precision_sensitive_outputs.hpp"#include "pass/lower_set_rows_stateless.hpp"#include "pass/prune_orphaned_parameters.hpp"#include "quant/weights.hpp"@@ -414,6 +415,8 @@ std::shared_ptr<Model> TranslateSession::apply_transformations(std::shared_ptr<Mmanager.register_pass<pass::PruneParametersOrphanedSince>(live_before_gdn);}+ manager.register_pass<pass::IsolatePrecisionSensitiveOutputs>();+fold_hadamard_input_signs(model);manager.run_passes(model);normalize_u2_zero_points(model);diff --git a/src/frontends/gguf/src/utils.cpp b/src/frontends/gguf/src/utils.cppindex d8137bc3471..6f327349a27 100644--- a/src/frontends/gguf/src/utils.cpp+++ b/src/frontends/gguf/src/utils.cpp@@ -7,6 +7,7 @@#include <algorithm>#include <cmath>#include <cstddef>+#include <limits>#include <memory>#include <numeric>#include <string>@@ -27,6 +28,8 @@#include "openvino/op/maximum.hpp"#include "openvino/op/multiply.hpp"#include "openvino/op/parameter.hpp"+#include "openvino/op/power.hpp"+#include "openvino/op/reduce_l2.hpp"#include "openvino/op/reduce_sum.hpp"#include "openvino/op/reshape.hpp"#include "openvino/op/shape_of.hpp"@@ -171,7 +174,9 @@ ov::Output<ov::Node> apply_hadamard(const NodeContext& context, ov::Output<ov::Nauto* cached = context.get_hadamard_cache_entry(input, block, inverse, use_matrix, heads, signs);if (cached && cached->get_node())return *cached;- const auto original = std::make_shared<v3::ShapeOf>(input, ov::element::i64);+ ov::Output<ov::Node> original;+ if (!use_matrix || !heads.empty())+ original = std::make_shared<v3::ShapeOf>(input, ov::element::i64);if (!heads.empty()) {FRONT_END_OP_CONVERSION_CHECK(heads.size() == 3 && heads[0] * heads[1] * heads[2] == width,"Invalid Hadamard GDN feature order");@@ -189,17 +194,24 @@ ov::Output<ov::Node> apply_hadamard(const NodeContext& context, ov::Output<ov::Ninput = std::make_shared<v1::Multiply>(input, sign_node);input.get_node_shared_ptr()->get_rt_info()["gguf_hadamard_input_sign"] = true;}- input = std::make_shared<v1::Reshape>(input, pattern({-1, block}), false);if (use_matrix) {+ std::vector<int64_t> matrix_shape(shape.size() + 1, 0);+ matrix_shape[shape.size() - 1] = width / block;+ matrix_shape.back() = block;+ input = std::make_shared<v1::Reshape>(input, pattern(matrix_shape), true);input = std::make_shared<v0::MatMul>(input,context.get_hadamard_matrix(input.get_element_type(), block),false,false);input.get_node_shared_ptr()->get_rt_info()[hadamard_marker] = block;+ std::vector<int64_t> restored_shape(shape.size(), 0);+ restored_shape.back() = width;+ input = std::make_shared<v1::Reshape>(input, pattern(restored_shape), true);} else {+ input = std::make_shared<v1::Reshape>(input, pattern({-1, block}), false);input = hadamard_butterfly(input, block, &context, block == 1024);+ input = std::make_shared<v1::Reshape>(input, original, false);}- input = std::make_shared<v1::Reshape>(input, original, false);if (signs && inverse)input = std::make_shared<v1::Multiply>(input, sign_node);if (cached)@@ -220,7 +232,20 @@ void decompose_hadamard(Output<Node> input) {const auto marker = rotation->get_rt_info().find(hadamard_marker);if (marker == rotation->get_rt_info().end() || rotation->output(0).get_target_inputs().empty())return;- const auto replacement = hadamard_butterfly(rotation->input_value(0), marker->second.as<int64_t>(), nullptr, true);+ input = rotation->input_value(0);+ const auto block = marker->second.as<int64_t>();+ const bool flatten = input.get_partial_shape().rank() != 2;+ std::shared_ptr<ov::Node> shape;+ if (flatten) {+ shape = std::make_shared<ov::op::v3::ShapeOf>(input, ov::element::i64);+ input = std::make_shared<ov::op::v1::Reshape>(+ input,+ ov::op::v0::Constant::create<int64_t>(ov::element::i64, {2}, {-1, block}),+ false);+ }+ ov::Output<ov::Node> replacement = hadamard_butterfly(input, block, nullptr, true);+ if (flatten)+ replacement = std::make_shared<ov::op::v1::Reshape>(replacement, shape, false);rotation->get_rt_info().erase(marker);ov::copy_runtime_info(rotation, replacement.get_node_shared_ptr());ov::copy_output_runtime_info({rotation->output(0)}, {replacement});@@ -321,12 +346,33 @@ int non_cont_dim(std::vector<size_t> ne, std::vector<size_t> nb) {}ov::Output<ov::Node> make_l2_norm(const ov::Output<ov::Node>& x, float eps) {- auto sum = std::make_shared<ov::op::v1::ReduceSum>(std::make_shared<ov::op::v1::Multiply>(x, x),- ov::op::v0::Constant::create(ov::element::i64, {1}, {-1}),- true);- auto norm = std::make_shared<ov::op::v1::Maximum>(std::make_shared<ov::op::v0::Sqrt>(sum),- ov::op::v0::Constant::create(ov::element::f32, {1}, {eps}));- return std::make_shared<ov::op::v1::Divide>(x, norm);+ const auto axis = ov::op::v0::Constant::create(ov::element::i64, {1}, {-1});+ ov::Output<ov::Node> value = x;+ if (value.get_element_type() != ov::element::f32)+ value = std::make_shared<ov::op::v0::Convert>(value, ov::element::f32);+ const auto length = std::make_shared<ov::op::v4::ReduceL2>(value, axis, true);+ ov::Output<ov::Node> norm;+ if (std::isfinite(eps))+ norm = std::make_shared<ov::op::v0::Clamp>(length, eps, std::numeric_limits<float>::infinity());+ else+ norm =+ std::make_shared<ov::op::v1::Maximum>(length, ov::op::v0::Constant::create(ov::element::f32, {1}, {eps}));+ ov::NodeVector protected_nodes{length, norm.get_node_shared_ptr()};+ ov::Output<ov::Node> result;+ if (eps > 0.f && eps < std::numeric_limits<float>::min()) {+ result = std::make_shared<ov::op::v1::Divide>(value, norm);+ } else {+ const auto scale =+ std::make_shared<ov::op::v1::Power>(norm, ov::op::v0::Constant::create(ov::element::f32, {}, {-1.f}));+ protected_nodes.push_back(scale);+ result = std::make_shared<ov::op::v1::Multiply>(value, scale);+ }+ protected_nodes.push_back(result.get_node_shared_ptr());+ for (const auto& node : protected_nodes)+ ov::disable_conversion(node, ov::element::f16);+ if (result.get_element_type() != x.get_element_type())+ result = std::make_shared<ov::op::v0::Convert>(result, x.get_element_type());+ return result;}void name_output(const ov::Output<ov::Node>& out, const std::string& name) {diff --git a/src/frontends/gguf/tests/CMakeLists.txt b/src/frontends/gguf/tests/CMakeLists.txtindex cfe50612469..cc13ef77ad2 100644--- a/src/frontends/gguf/tests/CMakeLists.txt+++ b/src/frontends/gguf/tests/CMakeLists.txt@@ -27,8 +27,10 @@ set(FRONTEND_SRCS"${FE_SRC_DIR}/pass/adapt_to_genai.cpp""${FE_SRC_DIR}/pass/adapt_mmproj_to_genai.cpp""${FE_SRC_DIR}/pass/lower_set_rows_stateless.cpp"+ "${FE_SRC_DIR}/pass/isolate_precision_sensitive_outputs.cpp""${FE_SRC_DIR}/pass/make_stateful.cpp""${FE_SRC_DIR}/pass/prune_orphaned_parameters.cpp"+ "${FE_SRC_DIR}/pass/simplify_activation_shapes.cpp""${FE_SRC_DIR}/tokenizer_metadata.cpp""${FE_SRC_DIR}/quant/gguf.cpp""${FE_SRC_DIR}/quant/gguf_quants.cpp"@@ -118,9 +120,12 @@ set(TEST_SRCS"${CMAKE_CURRENT_SOURCE_DIR}/test_extensions.cpp""${CMAKE_CURRENT_SOURCE_DIR}/test_op_coverage.cpp""${CMAKE_CURRENT_SOURCE_DIR}/test_ops.cpp"+ "${CMAKE_CURRENT_SOURCE_DIR}/test_gdn_normalization.cpp"+ "${CMAKE_CURRENT_SOURCE_DIR}/test_isolate_precision_sensitive_outputs.cpp""${CMAKE_CURRENT_SOURCE_DIR}/test_parser.cpp""${CMAKE_CURRENT_SOURCE_DIR}/test_weights.cpp""${CMAKE_CURRENT_SOURCE_DIR}/test_shared_linear_inputs.cpp"+ "${CMAKE_CURRENT_SOURCE_DIR}/test_simplify_activation_shapes.cpp""${CMAKE_CURRENT_SOURCE_DIR}/test_hadamard_sign_folding.cpp")diff --git a/src/frontends/gguf/tests/test_adapt_to_genai.cpp b/src/frontends/gguf/tests/test_adapt_to_genai.cppindex c8421065074..02f7511ba4f 100644--- a/src/frontends/gguf/tests/test_adapt_to_genai.cpp+++ b/src/frontends/gguf/tests/test_adapt_to_genai.cpp@@ -589,22 +589,10 @@ TEST(GGUFAdaptToGenAI, FixesEmbdAxisStructurally) {ASSERT_TRUE(AdaptToGenAI().run_on_model(m.model));- // The original Unsqueeze(axis=0) node was replaced; find its successor by name (the- // replacement copies it) and confirm the new axis is 1, fed by the same Gather.- std::shared_ptr<ov::Node> fixed_embd;- for (const auto& op : m.model->get_ordered_ops()) {- if (op->get_friendly_name() == "Unsqueeze_test_embd") {- fixed_embd = op;- break;- }- }- ASSERT_NE(fixed_embd, nullptr);- ASSERT_EQ(fixed_embd->get_type_name(), std::string("Unsqueeze"));- EXPECT_EQ(fixed_embd->input_value(0), embd_gather_input); // still the same Gather, unchanged-- auto axis_const = ov::as_type_ptr<v0::Constant>(fixed_embd->input_value(1).get_node_shared_ptr());- ASSERT_NE(axis_const, nullptr);- EXPECT_EQ(axis_const->cast_vector<int64_t>(), std::vector<int64_t>({1}));+ const auto logits = ov::as_type_ptr<v1::ReduceSum>(m.model->get_results()[0]->input_value(0).get_node_shared_ptr());+ ASSERT_NE(logits, nullptr);+ EXPECT_EQ(logits->input_value(0), embd_gather_input);+ EXPECT_EQ(embd_gather_input.get_partial_shape(), ov::PartialShape({-1, -1, 2}));}// Regression test for the BLOCKER FixEmbdAxis's name-only matcher used to miss: Gemma4 has adiff --git a/src/frontends/gguf/tests/test_arch_accuracy.cpp b/src/frontends/gguf/tests/test_arch_accuracy.cppindex a01b1f3dbd6..69fde00a951 100644--- a/src/frontends/gguf/tests/test_arch_accuracy.cpp+++ b/src/frontends/gguf/tests/test_arch_accuracy.cpp@@ -34,6 +34,7 @@#include "openvino/frontend/gguf/make_stateful.hpp"#include "openvino/op/broadcast.hpp"#include "openvino/op/constant.hpp"+#include "openvino/op/gated_delta_net.hpp"#include "openvino/op/matmul.hpp"#include "openvino/op/multiply.hpp"#include "openvino/op/paged_attention.hpp"@@ -562,6 +563,15 @@ TEST(GGUFHadamardTypes, ConstantsAreSharedWithinEachConversion) {auto input_model = frontend.load(temporary.path);const auto first = frontend.convert(input_model);const auto second = frontend.convert(input_model);+ for (const auto& model : {first, second}) {+ for (const auto& node : model->get_ops()) {+ if (const auto gdn = ov::as_type_ptr<ov::op::internal::GatedDeltaNet>(node)) {+ EXPECT_EQ(gdn->get_input_partial_shape(0)[2], 2);+ EXPECT_EQ(gdn->get_input_partial_shape(1)[2], 2);+ EXPECT_EQ(gdn->get_input_partial_shape(2)[2], 4);+ }+ }+ }const auto rotation_constants = [](const std::shared_ptr<ov::Model>& model) {std::set<ov::Node*> constants;size_t stages = 0;diff --git a/src/frontends/gguf/tests/test_arch_conversion.cpp b/src/frontends/gguf/tests/test_arch_conversion.cppindex 605179a11b2..9eca7a31c43 100644--- a/src/frontends/gguf/tests/test_arch_conversion.cpp+++ b/src/frontends/gguf/tests/test_arch_conversion.cpp@@ -194,7 +194,7 @@ const std::map<std::string, Fingerprint>& fingerprints() {{"mistral3-moe.gguf.hdr", {532, 10}}, {"olmoe-moe.gguf.hdr", {560, 10}},{"phi3-dense.gguf.hdr", {358, 10}}, {"qwen2-dense.gguf.hdr", {373, 10}},{"qwen3-dense.gguf.hdr", {421, 10}}, {"qwen3moe-moe.gguf.hdr", {572, 10}},- {"qwen35-dense.gguf.hdr", {406, 10}}, {"qwen35moe-moe.gguf.hdr", {578, 10}},+ {"qwen35-dense.gguf.hdr", {399, 10}}, {"qwen35moe-moe.gguf.hdr", {571, 10}},{"smollm3-dense.gguf.hdr", {389, 10}}, {"jais2-dense.gguf.hdr", {334, 10}},};return fp;diff --git a/src/frontends/gguf/tests/test_gdn_normalization.cpp b/src/frontends/gguf/tests/test_gdn_normalization.cppnew file mode 100644index 00000000000..e920289d0ce--- /dev/null+++ b/src/frontends/gguf/tests/test_gdn_normalization.cpp@@ -0,0 +1,118 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "op_test_utils.hpp"+#include "openvino/op/gated_delta_net.hpp"+#include "openvino/op/reshape.hpp"+#include "openvino/op/slice.hpp"+#include "openvino/op/split.hpp"+#include "utils.hpp"++namespace {++using namespace ov::op;++enum class QkSlices { Adjacent, Offset, Gap, Strided, SeparateSources, ExplicitShape };+class GGUFQkNormalization : public testing::TestWithParam<QkSlices> {};++TEST_P(GGUFQkNormalization, PreservesIndependentRowsAndClamp) {+ constexpr int64_t batch = 2, heads = 2, width = 4, features = 4 * heads * width;+ const auto layout = GetParam();+ const auto x = std::make_shared<v0::Parameter>(ov::element::f32, ov::PartialShape{batch, 1, -1, features});+ x->set_friendly_name("x");+ ov::ParameterVector parameters{x};+ ov::Output<ov::Node> k_source = x;+ if (layout == QkSlices::SeparateSources) {+ const auto y = std::make_shared<v0::Parameter>(ov::element::f32, x->get_partial_shape());+ y->set_friendly_name("y");+ parameters.push_back(y);+ k_source = y;+ }+ const int64_t step = layout == QkSlices::Strided ? 2 : 1;+ const int64_t first = layout == QkSlices::Offset ? width : 0;+ const int64_t middle = first + step * heads * width;+ const int64_t k_first = middle + (layout == QkSlices::Gap ? width : 0);+ const auto slice = [&](const ov::Output<ov::Node>& input, int64_t begin) {+ return std::make_shared<v8::Slice>(input,+ v0::Constant::create(ov::element::i64, {1}, {begin}),+ v0::Constant::create(ov::element::i64, {1}, {begin + step * heads * width}),+ v0::Constant::create(ov::element::i64, {1}, {step}),+ v0::Constant::create(ov::element::i64, {1}, {3}));+ };+ const bool special_zero = layout != QkSlices::ExplicitShape;+ const auto shape =+ v0::Constant::create<int64_t>(ov::element::i64, {4}, {special_zero ? 0 : batch, -1, heads, width});+ const auto q = std::make_shared<v1::Reshape>(slice(x, first), shape, special_zero);+ const auto k = std::make_shared<v1::Reshape>(slice(k_source, k_first), shape, special_zero);+ const ov::PartialShape qkv_shape{batch, -1, heads, width}, gate_shape{batch, -1, heads, 1};+ const auto decoder = std::make_shared<ov_gguf_test::SingleOpDecoder>(+ "GGML_OP_GATED_DELTA_NET",+ std::vector<ov_gguf_test::TensorDesc>{{"q", ov::element::f32, qkv_shape},+ {"k", ov::element::f32, qkv_shape},+ {"v", ov::element::f32, qkv_shape},+ {"g", ov::element::f32, gate_shape},+ {"beta", ov::element::f32, gate_shape},+ {"state", ov::element::f32, {batch, heads, width, width}}},+ std::vector<ov_gguf_test::TensorDesc>{},+ ov_gguf_test::TensorDesc{"out", ov::element::f32, qkv_shape},+ std::map<std::string, ov::Any>{{"split_outputs", true}, {"fuse_qk_l2norm", true}, {"qk_l2_norm_eps", 1e-6f}});+ auto values = std::make_shared<ov::frontend::gguf::TensorMap>();+ for (const auto& entry : decoder->get_model_inputs())+ values->emplace(entry.first, entry.second);+ values->at("q") = q;+ values->at("k") = k;+ const ov::frontend::gguf::NodeContext context(decoder, values);+ const auto outputs = ov::frontend::gguf::op::translate_gated_delta_net(context);+ const auto gdn = ov::as_type_ptr<internal::GatedDeltaNet>(outputs[0].get_node_shared_ptr());+ ASSERT_NE(gdn, nullptr);+ const bool joined = layout == QkSlices::Adjacent || layout == QkSlices::Offset;+ EXPECT_EQ(ov::is_type<v1::Split>(gdn->get_input_node_shared_ptr(0)), joined);+ if (joined) {+ EXPECT_EQ(gdn->get_input_node_shared_ptr(0), gdn->get_input_node_shared_ptr(1));+ EXPECT_EQ(gdn->input_value(0).get_index(), 0u);+ EXPECT_EQ(gdn->input_value(1).get_index(), 1u);+ }+ const auto model =+ std::make_shared<ov::Model>(ov::OutputVector{gdn->input_value(0), gdn->input_value(1), q}, parameters);+ const auto reference = std::make_shared<ov::Model>(+ ov::OutputVector{ov::frontend::gguf::make_l2_norm(q, 1e-6f), ov::frontend::gguf::make_l2_norm(k, 1e-6f), q},+ parameters);+ ov::Core core;+ auto compiled = core.compile_model(model, "CPU", ov::hint::inference_precision(ov::element::f32));+ auto compiled_ref = core.compile_model(reference, "CPU", ov::hint::inference_precision(ov::element::f32));+ for (const size_t tokens : {1u, 3u}) {+ const ov::Shape input_shape{batch, 1, tokens, features};+ std::vector<float> data(ov::shape_size(input_shape));+ for (size_t i = 0; i < data.size(); ++i)+ data[i] = i % 12 < 4 ? 0.f : (i % 12 < 8 ? 1e-8f : 0.25f * static_cast<float>(i % 7) - 0.5f);+ auto request = compiled.create_infer_request();+ auto ref_request = compiled_ref.create_infer_request();+ for (size_t i = 0; i < parameters.size(); ++i) {+ const auto tensor = ov_gguf_test::make_f32_tensor(input_shape, data);+ request.set_input_tensor(i, tensor);+ ref_request.set_input_tensor(i, tensor);+ }+ request.infer();+ ref_request.infer();+ for (size_t i = 0; i < 3; ++i) {+ const auto expected = ref_request.get_output_tensor(i);+ EXPECT_EQ(request.get_output_tensor(i).get_shape(), expected.get_shape());+ ov_gguf_test::expect_near(+ request.get_output_tensor(i),+ {expected.data<const float>(), expected.data<const float>() + expected.get_size()},+ 1e-6f);+ }+ }+}++INSTANTIATE_TEST_SUITE_P(GGUFOps,+ GGUFQkNormalization,+ testing::Values(QkSlices::Adjacent,+ QkSlices::Offset,+ QkSlices::Gap,+ QkSlices::Strided,+ QkSlices::SeparateSources,+ QkSlices::ExplicitShape));++} // namespacediff --git a/src/frontends/gguf/tests/test_isolate_precision_sensitive_outputs.cpp b/src/frontends/gguf/tests/test_isolate_precision_sensitive_outputs.cppnew file mode 100644index 00000000000..e1bb4d5a521--- /dev/null+++ b/src/frontends/gguf/tests/test_isolate_precision_sensitive_outputs.cpp@@ -0,0 +1,70 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "common_test_utils/ov_test_utils.hpp"+#include "openvino/op/abs.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/convert.hpp"+#include "openvino/op/parameter.hpp"+#include "openvino/op/split.hpp"+#include "pass/isolate_precision_sensitive_outputs.hpp"+#include "transformations/rt_info/disable_precision_conversion.hpp"++namespace {++using namespace ov::op;++std::shared_ptr<ov::Model> split_model(bool boundary,+ bool protect_source = true,+ bool protect_split = false,+ ov::element::Type type = ov::element::f32) {+ const auto x = std::make_shared<v0::Parameter>(type, ov::PartialShape{2, -1, 8});+ const auto source = std::make_shared<v0::Abs>(x);+ if (protect_source)+ ov::disable_conversion(source, ov::element::f16);+ ov::Output<ov::Node> value = source;+ if (boundary)+ value = std::make_shared<v0::Convert>(value, type);+ const auto split = std::make_shared<v1::Split>(value, v0::Constant::create(ov::element::i64, {}, {-1}), 2);+ split->set_friendly_name("split");+ if (protect_split)+ ov::disable_conversion(split, ov::element::f16);+ return std::make_shared<ov::Model>(ov::OutputVector{split->output(0), split->output(1), source},+ ov::ParameterVector{x});+}++class GGUFPrecisionBoundary : public TransformationTestsF {+protected:+ void SetUp() override {+ TransformationTestsF::SetUp();+ manager.register_pass<ov::frontend::gguf::pass::IsolatePrecisionSensitiveOutputs>();+ manager.register_pass<ov::frontend::gguf::pass::IsolatePrecisionSensitiveOutputs>();+ comparator.enable(FunctionsComparator::ATTRIBUTES);+ comparator.enable(FunctionsComparator::CONST_VALUES);+ comparator.enable(FunctionsComparator::ACCURACY);+ }+};++TEST_F(GGUFPrecisionBoundary, IsolatesProducerWithoutChangingItsOtherConsumer) {+ model = split_model(false);+ model_ref = split_model(true);+}++TEST_F(GGUFPrecisionBoundary, KeepsUnprotectedProducer) {+ model = split_model(false, false);+}++TEST_F(GGUFPrecisionBoundary, KeepsProtectedSplit) {+ model = split_model(false, true, true);+}++TEST_F(GGUFPrecisionBoundary, KeepsExistingBoundary) {+ model = split_model(true);+}++TEST_F(GGUFPrecisionBoundary, KeepsOriginalFp16Graph) {+ model = split_model(false, true, false, ov::element::f16);+}++} // namespacediff --git a/src/frontends/gguf/tests/test_ops.cpp b/src/frontends/gguf/tests/test_ops.cppindex 112a08d7d13..b60992592b4 100644--- a/src/frontends/gguf/tests/test_ops.cpp+++ b/src/frontends/gguf/tests/test_ops.cpp@@ -636,6 +636,26 @@ TEST(GGUFOps, L2Norm) {expect_near(out, expected, 1e-4f);}+TEST(GGUFOps, L2NormExtremeEpsilon) {+ for (const auto& parameters : std::vector<std::pair<float, float>>{{2e19f, 1e19f},+ {1e-30f, 1e-30f},+ {3e-23f, 1e-23f},+ {0.f, 1e-4f},+ {-1.f, 1e-4f}}) {+ const auto eps = parameters.first;+ const auto amplitude = parameters.second;+ SCOPED_TRACE(eps);+ const auto model = SingleOpBuilder()+ .op("GGML_OP_L2_NORM")+ .input("x", ov::element::f32, {1, 2})+ .output("out", ov::element::f32, {1, 2})+ .attr("eps", eps)+ .build();+ const auto out = run_on_cpu(model, {{"x", make_f32_tensor({1, 2}, {amplitude, 0.f})}});+ expect_near(out, {amplitude / std::max(amplitude, eps), 0.f}, 1e-6f);+ }+}+// SumRows: reduce-sum over the last axis, keeping rank.TEST(GGUFOps, SumRows) {const size_t cols = 4;diff --git a/src/frontends/gguf/tests/test_shared_linear_inputs.cpp b/src/frontends/gguf/tests/test_shared_linear_inputs.cppindex a25b0b54473..88623db9039 100644--- a/src/frontends/gguf/tests/test_shared_linear_inputs.cpp+++ b/src/frontends/gguf/tests/test_shared_linear_inputs.cpp@@ -206,12 +206,20 @@ TEST(GGUFHadamardSharing, InverseRotationUsesSupportedMatrix) {ASSERT_EQ(y.get_node()->get_type_name(), std::string("Reshape"));EXPECT_EQ(y.get_node()->get_input_node_shared_ptr(0)->get_type_name(), std::string("MatMul"));const auto model = std::make_shared<ov::Model>(ov::OutputVector{y}, ov::ParameterVector{x});- ov::Tensor input(ov::element::f32, {2, 1, block});- std::fill_n(input.data<float>(), input.get_size(), 1.f);- ov::TensorVector output{ov::Tensor(ov::element::f32, {2, 1, block})};- ASSERT_TRUE(model->evaluate(output, {input}));- for (size_t i = 0; i < input.get_size(); ++i)- EXPECT_FLOAT_EQ(output[0].data<float>()[i], i % block == 0 ? 16.f : 0.f);+ for (const bool decomposed : {false, true}) {+ if (decomposed) {+ decompose_hadamard(y);+ model->validate_nodes_and_infer_types();+ }+ for (const size_t tokens : {1, 3}) {+ ov::Tensor input(ov::element::f32, {2, tokens, block});+ std::fill_n(input.data<float>(), input.get_size(), 1.f);+ ov::TensorVector output{ov::Tensor(ov::element::f32, {2, tokens, block})};+ ASSERT_TRUE(model->evaluate(output, {input}));+ for (size_t i = 0; i < input.get_size(); ++i)+ EXPECT_FLOAT_EQ(output[0].data<float>()[i], i % block == 0 ? 16.f : 0.f);+ }+ }}TEST(GGUFHadamardSharing, DistinguishesSignsDirectionLayoutAndConversionScope) {diff --git a/src/frontends/gguf/tests/test_simplify_activation_shapes.cpp b/src/frontends/gguf/tests/test_simplify_activation_shapes.cppnew file mode 100644index 00000000000..26bd5c4716a--- /dev/null+++ b/src/frontends/gguf/tests/test_simplify_activation_shapes.cpp@@ -0,0 +1,120 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include "common_test_utils/ov_test_utils.hpp"+#include "openvino/op/add.hpp"+#include "openvino/op/constant.hpp"+#include "openvino/op/gather.hpp"+#include "openvino/op/matmul.hpp"+#include "openvino/op/parameter.hpp"+#include "openvino/op/reshape.hpp"+#include "openvino/op/shape_of.hpp"+#include "openvino/op/swish.hpp"+#include "openvino/op/unsqueeze.hpp"+#include "openvino/op/variadic_split.hpp"+#include "pass/simplify_activation_shapes.hpp"++namespace {++using namespace ov::op;++class GGUFActivationShapes : public TransformationTestsF {+protected:+ void SetUp() override {+ TransformationTestsF::SetUp();+ manager.register_pass<ov::frontend::gguf::pass::SimplifyActivationShapes>();+ comparator.enable(FunctionsComparator::ACCURACY);+ comparator.enable(FunctionsComparator::CONST_VALUES);+ comparator.enable(FunctionsComparator::ATTRIBUTES);+ }+};++std::shared_ptr<ov::Model> residual_model(bool compact) {+ const auto x = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{2, 3, 8});+ const auto axis = v0::Constant::create(ov::element::i64, {1}, {1});+ const auto w = v0::Constant::create(ov::element::f32, {8, 8}, {0.25f});+ const auto fc = std::make_shared<v0::MatMul>(x, w, false, true);+ ov::Output<ov::Node> value = fc;+ ov::Output<ov::Node> residual = x;+ if (!compact) {+ value = std::make_shared<v0::Unsqueeze>(value, axis);+ residual = std::make_shared<v0::Unsqueeze>(residual, axis);+ }+ value = std::make_shared<v4::Swish>(std::make_shared<v1::Add>(value, residual));+ if (compact)+ value = std::make_shared<v0::Unsqueeze>(value, axis);+ return std::make_shared<ov::Model>(ov::OutputVector{value}, ov::ParameterVector{x});+}++TEST_F(GGUFActivationShapes, KeepsResidualPathAtRankThree) {+ model = residual_model(false);+ model_ref = residual_model(true);+}++TEST_F(GGUFActivationShapes, PreservesOtherOutputsOfReshapeProducer) {+ const auto make_model = [](bool compact) {+ const auto x = std::make_shared<v0::Parameter>(ov::element::f32, ov::Shape{1, 5, 8});+ const auto split = std::make_shared<v1::VariadicSplit>(x,+ v0::Constant::create(ov::element::i64, {}, {1}),+ v0::Constant::create(ov::element::i64, {2}, {2, 3}));+ ov::Output<ov::Node> second = split->output(1);+ if (compact) {+ second = std::make_shared<v0::Unsqueeze>(second, v0::Constant::create(ov::element::i64, {1}, {1}));+ } else {+ second =+ std::make_shared<v1::Reshape>(second, v0::Constant::create(ov::element::i64, {4}, {1, 1, 3, 8}), false);+ }+ return std::make_shared<ov::Model>(ov::OutputVector{split->output(0), second}, ov::ParameterVector{x});+ };+ model = make_model(false);+ model_ref = make_model(true);+}++TEST_F(GGUFActivationShapes, RemovesOnlySymbolProvenIdentityReshapes) {+ const auto make_model = [](bool compact) {+ const auto x = std::make_shared<v0::Parameter>(ov::element::f32, ov::PartialShape{2, -1, 8});+ ov::Output<ov::Node> value = x;+ if (!compact) {+ const auto expanded = std::make_shared<v0::Unsqueeze>(x, v0::Constant::create(ov::element::i64, {1}, {1}));+ const auto shape = std::make_shared<v3::ShapeOf>(expanded);+ const auto target = std::make_shared<v8::Gather>(shape,+ v0::Constant::create(ov::element::i64, {3}, {0, 2, 3}),+ v0::Constant::create(ov::element::i64, {}, {0}));+ value = std::make_shared<v1::Reshape>(expanded, target, false);+ }+ return std::make_shared<ov::Model>(ov::OutputVector{std::make_shared<v4::Swish>(value)},+ ov::ParameterVector{x});+ };+ model = make_model(false);+ model_ref = make_model(true);+}++TEST_F(GGUFActivationShapes, LeavesIndependentDynamicDimensionsInReshape) {+ const auto x = std::make_shared<v0::Parameter>(ov::element::f32, ov::PartialShape{2, -1, 8});+ const auto shape = std::make_shared<v0::Parameter>(ov::element::i64, ov::Shape{3});+ const auto reshape = std::make_shared<v1::Reshape>(x, shape, false);+ model = std::make_shared<ov::Model>(ov::OutputVector{reshape}, ov::ParameterVector{x, shape});+ comparator.disable(FunctionsComparator::ACCURACY);+}++TEST_F(GGUFActivationShapes, LeavesNonSingletonBroadcastAxisUnchanged) {+ const auto x = std::make_shared<v0::Parameter>(ov::element::f32, ov::PartialShape{2, 3, -1, 8});+ const auto bias = v0::Constant::create(ov::element::f32, {8}, {0.125f});+ const auto add = std::make_shared<v1::Add>(x, bias);+ model = std::make_shared<ov::Model>(ov::OutputVector{add}, ov::ParameterVector{x});+}++TEST_F(GGUFActivationShapes, LeavesSelectedTokenAxisDynamic) {+ const auto x = std::make_shared<v0::Parameter>(ov::element::f32, ov::PartialShape{1, -1, 1, 8});+ model = std::make_shared<ov::Model>(ov::OutputVector{std::make_shared<v4::Swish>(x)}, ov::ParameterVector{x});+}++TEST_F(GGUFActivationShapes, LeavesUnprovenSingletonAxisWithoutBroadcasting) {+ const auto x = std::make_shared<v0::Parameter>(ov::element::f32, ov::PartialShape{2, -1, 3, 8});+ const auto y = std::make_shared<v0::Parameter>(ov::element::f32, ov::PartialShape{2, 1, 3, 8});+ const auto add = std::make_shared<v1::Add>(x, y, ov::op::AutoBroadcastType::NONE);+ model = std::make_shared<ov::Model>(ov::OutputVector{add}, ov::ParameterVector{x, y});+}++} // namespace