Skip to content

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

[GPU] Fix GDN func test to use TEMPLATE plugin as reference (#36081)

Zijun Yucdd6cf0c2b11
diff --git a/src/core/reference/include/openvino/reference/gated_delta_net.hpp b/src/core/reference/include/openvino/reference/gated_delta_net.hpp
new file mode 100644
index 00000000000..5ae61f74ab6
--- /dev/null
+++ b/src/core/reference/include/openvino/reference/gated_delta_net.hpp
@@ -0,0 +1,120 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#pragma once
+
+#include <cmath>
+#include <vector>
+
+#include "openvino/core/shape.hpp"
+#include "openvino/reference/normalize_l2.hpp"
+
+namespace ov::reference {
+
+template <typename T>
+void gated_delta_net(const T* q_data,
+ const T* k_data,
+ const T* v_data,
+ const T* state_data,
+ const T* gate_data,
+ const T* beta_data,
+ T* out_data,
+ T* out_state,
+ const Shape& q_shape,
+ const Shape& v_shape,
+ bool fuse_qk_l2norm,
+ T q_l2_norm_eps,
+ T k_l2_norm_eps) {
+ const size_t B = q_shape[0];
+ const size_t S = q_shape[1];
+ const size_t qk_H = q_shape[2];
+ const size_t D = q_shape[3];
+ const size_t v_H = v_shape[2];
+ const size_t Dv = v_shape[3];
+ const size_t group_size = v_H / qk_H;
+
+ const T attn_scale = static_cast<T>(1) / std::sqrt(static_cast<T>(D));
+
+ const size_t qk_stride_batch = S * qk_H * D;
+ const size_t v_stride_batch = S * v_H * Dv;
+ const size_t gate_beta_stride_batch = S * v_H;
+
+ auto dot_product = [](const T* a, const T* b, size_t n) {
+ T result = static_cast<T>(0);
+ for (size_t i = 0; i < n; i++) {
+ result += a[i] * b[i];
+ }
+ return result;
+ };
+
+ const Shape norm_shape{D};
+ const AxisSet norm_axes{0};
+
+ for (size_t b = 0; b < B; b++) {
+ for (size_t h_v = 0; h_v < v_H; h_v++) {
+ const size_t h_qk = h_v / group_size;
+ for (size_t d_v = 0; d_v < Dv; d_v++) {
+ const size_t state_offset = b * v_H * D * Dv + h_v * D * Dv + d_v;
+ T* state_ptr = out_state + state_offset;
+
+ std::vector<T> local_state(D);
+ const T* src_state = state_data + state_offset;
+ for (size_t d = 0; d < D; d++) {
+ local_state[d] = src_state[d * Dv];
+ }
+
+ for (size_t t = 0; t < S; t++) {
+ const T* q_ptr = q_data + b * qk_stride_batch + t * qk_H * D + h_qk * D;
+ const T* k_ptr = k_data + b * qk_stride_batch + t * qk_H * D + h_qk * D;
+
+ std::vector<T> q_vec(q_ptr, q_ptr + D);
+ std::vector<T> k_vec(k_ptr, k_ptr + D);
+
+ if (fuse_qk_l2norm) {
+ normalize_l2(q_vec.data(),
+ q_vec.data(),
+ norm_shape,
+ norm_axes,
+ static_cast<float>(q_l2_norm_eps),
+ op::EpsMode::ADD);
+ normalize_l2(k_vec.data(),
+ k_vec.data(),
+ norm_shape,
+ norm_axes,
+ static_cast<float>(k_l2_norm_eps),
+ op::EpsMode::ADD);
+ }
+
+ for (size_t i = 0; i < D; i++)
+ q_vec[i] *= attn_scale;
+
+ T g = std::exp(gate_data[b * gate_beta_stride_batch + t * v_H + h_v]);
+ T bt = beta_data[b * gate_beta_stride_batch + t * v_H + h_v];
+
+ for (size_t d = 0; d < D; d++) {
+ local_state[d] *= g;
+ }
+
+ T h_k = dot_product(local_state.data(), k_vec.data(), D);
+
+ T v_val = v_data[b * v_stride_batch + t * v_H * Dv + h_v * Dv + d_v] - h_k;
+
+ T update_scale = v_val * bt;
+ for (size_t d = 0; d < D; d++) {
+ local_state[d] += k_vec[d] * update_scale;
+ }
+
+ out_data[b * v_stride_batch + t * v_H * Dv + h_v * Dv + d_v] =
+ dot_product(local_state.data(), q_vec.data(), D);
+ }
+
+ for (size_t d = 0; d < D; d++) {
+ state_ptr[d * Dv] = local_state[d];
+ }
+ }
+ }
+ }
+}
+
+} // namespace ov::reference
diff --git a/src/core/shape_inference/include/gated_delta_net_shape_inference.hpp b/src/core/shape_inference/include/gated_delta_net_shape_inference.hpp
index 238b5c7c2ec..b27c34115ea 100644
--- a/src/core/shape_inference/include/gated_delta_net_shape_inference.hpp
+++ b/src/core/shape_inference/include/gated_delta_net_shape_inference.hpp
@@ -4,6 +4,7 @@
#pragma once
+#include "dimension_util.hpp"
#include "openvino/op/gated_delta_net.hpp"
#include "utils.hpp"
@@ -28,6 +29,7 @@ std::vector<TRShape> shape_infer(const GatedDeltaNet* op, const std::vector<T>&
const auto& k_head_size = key_ps[3];
const auto& q_head_size = query_ps[3];
const auto& v_head_size = value_ps[3];
+ auto out_shape = TRShape(value_ps);
NODE_SHAPE_INFER_CHECK(op,
input_shapes,
@@ -45,6 +47,15 @@ std::vector<TRShape> shape_infer(const GatedDeltaNet* op, const std::vector<T>&
" and ",
q_head_size);
+ NODE_SHAPE_INFER_CHECK(
+ op,
+ input_shapes,
+ q_head_num.is_dynamic() || ov::util::dim::is_divisible(out_shape[2], q_head_num.get_length()),
+ "The number of value heads must be a multiple of query/key heads (GQA), but got v_H=",
+ v_head_num,
+ " and qk_H=",
+ q_head_num);
+
const auto& gate_head_num = gate_ps[2];
const auto& beta_head_num = beta_ps[2];
@@ -84,6 +95,6 @@ std::vector<TRShape> shape_infer(const GatedDeltaNet* op, const std::vector<T>&
v_head_size);
// output has the same shape and type as input value, output state has the same shape and type as input
// recurrent_state
- return {value_ps, state_ps};
+ return {out_shape, state_ps};
}
} // namespace ov::op::internal
diff --git a/src/plugins/intel_gpu/tests/functional/single_layer_tests/gated_delta_net.cpp b/src/plugins/intel_gpu/tests/functional/single_layer_tests/gated_delta_net.cpp
index b33c4d137eb..74a87211ae1 100644
--- a/src/plugins/intel_gpu/tests/functional/single_layer_tests/gated_delta_net.cpp
+++ b/src/plugins/intel_gpu/tests/functional/single_layer_tests/gated_delta_net.cpp
@@ -2,23 +2,23 @@
// SPDX-License-Identifier: Apache-2.0
//
+#include "openvino/op/gated_delta_net.hpp"
+
+#include "common_test_utils/common_utils.hpp"
#include "common_test_utils/ov_tensor_utils.hpp"
+#include "common_test_utils/ov_test_utils.hpp"
#include "common_test_utils/test_common.hpp"
-#include "common_test_utils/common_utils.hpp"
#include "openvino/op/parameter.hpp"
#include "openvino/op/result.hpp"
-#include "openvino/op/gated_delta_net.hpp"
#include "openvino/runtime/core.hpp"
namespace {
-using GatedDeltaNetParams = std::tuple<
- std::vector<ov::Shape>, // Input shapes: query, key, value, state, gate, beta
- ov::element::Type, // Input precision
- bool>; // fuse_qk_l2norm
+using GatedDeltaNetParams = std::tuple<std::vector<ov::Shape>, // Input shapes: query, key, value, state, gate, beta
+ ov::element::Type, // Input precision
+ bool>; // fuse_qk_l2norm
-class GatedDeltaNetStaticTest : public testing::WithParamInterface<GatedDeltaNetParams>,
- public ov::test::TestsCommon {
+class GatedDeltaNetStaticTest : public testing::WithParamInterface<GatedDeltaNetParams>, public ov::test::TestsCommon {
public:
static std::string getTestCaseName(const testing::TestParamInfo<GatedDeltaNetParams>& obj) {
const auto& [input_shapes, precision, fuse_qk_l2norm] = obj.param;
@@ -46,16 +46,12 @@ protected:
auto gate = std::make_shared<ov::op::v0::Parameter>(precision, input_shapes[4]);
auto beta = std::make_shared<ov::op::v0::Parameter>(precision, input_shapes[5]);
- auto gdn = std::make_shared<ov::op::internal::GatedDeltaNet>(
- query, key, value, state, gate, beta, fuse_qk_l2norm);
+ auto gdn = std::make_shared<ov::op::internal::GatedDeltaNet>(query, key, value, state, gate, beta, fuse_qk_l2norm);
auto result0 = std::make_shared<ov::op::v0::Result>(gdn->output(0));
auto result1 = std::make_shared<ov::op::v0::Result>(gdn->output(1));
- model = std::make_shared<ov::Model>(
- ov::ResultVector{result0, result1},
- ov::ParameterVector{query, key, value, state, gate, beta},
- "GatedDeltaNetTest");
+ model = std::make_shared<ov::Model>(ov::ResultVector{result0, result1}, ov::ParameterVector{query, key, value, state, gate, beta}, "GatedDeltaNetTest");
}
std::map<std::shared_ptr<ov::op::v0::Parameter>, ov::Tensor> generate_inputs() {
@@ -66,8 +62,7 @@ protected:
if (i == 4) {
in_data = ov::test::utils::InputGenerateData(-1, 1, 1000, 1);
}
- inputs[params[i]] = ov::test::utils::create_and_fill_tensor(
- params[i]->get_element_type(), params[i]->get_shape(), in_data);
+ inputs[params[i]] = ov::test::utils::create_and_fill_tensor(params[i]->get_element_type(), params[i]->get_shape(), in_data);
}
return inputs;
}
@@ -75,20 +70,20 @@ protected:
std::shared_ptr<ov::Model> model;
};
-TEST_P(GatedDeltaNetStaticTest, CompareWithCPU) {
+TEST_P(GatedDeltaNetStaticTest, CompareWithTemplate) {
auto inputs = generate_inputs();
- ov::Core core;
-
- // Run on CPU (reference)
- auto compiled_cpu = core.compile_model(model, "CPU");
- auto req_cpu = compiled_cpu.create_infer_request();
- for (const auto& [param, tensor] : inputs) {
- req_cpu.set_tensor(param->output(0), tensor);
+ // Build input tensor vector for infer_on_template
+ ov::TensorVector input_tensors;
+ for (const auto& param : model->get_parameters()) {
+ input_tensors.push_back(inputs.at(param));
}
- req_cpu.infer();
+
+ // Run on TEMPLATE (reference)
+ auto ref_outputs = ov::test::utils::infer_on_template(model, input_tensors);
// Run on GPU
+ ov::Core core;
auto compiled_gpu = core.compile_model(model, "GPU");
auto req_gpu = compiled_gpu.create_infer_request();
for (const auto& [param, tensor] : inputs) {
@@ -98,30 +93,28 @@ TEST_P(GatedDeltaNetStaticTest, CompareWithCPU) {
// Compare outputs
for (size_t i = 0; i < model->get_output_size(); i++) {
- auto out_cpu = req_cpu.get_output_tensor(i);
auto out_gpu = req_gpu.get_output_tensor(i);
- ov::test::utils::compare(out_cpu, out_gpu, 1e-2, 1e-2);
+ ov::test::utils::compare(ref_outputs[i], out_gpu, 1e-2, 1e-2);
}
}
-// Shapes: query[B,S,H,D], key[B,S,H,D], value[B,S,H,Dv], state[B,H,D,Dv], gate[B,S,H], beta[B,S,H]
+// Shapes: query[B,S,qk_H,D], key[B,S,qk_H,D], value[B,S,v_H,Dv], state[B,v_H,D,Dv], gate[B,S,v_H], beta[B,S,v_H]
const std::vector<std::vector<ov::Shape>> static_shapes = {
- // B=1, S=1, H=4, D=16, Dv=16 (minimal)
+ // B=1, S=1, qk_H=4, v_H=4, D=16, Dv=16 (minimal)
{{1, 1, 4, 16}, {1, 1, 4, 16}, {1, 1, 4, 16}, {1, 4, 16, 16}, {1, 1, 4}, {1, 1, 4}},
- // B=1, S=1, H=32, D=128, Dv=128 (typical LLM decode)
+ // B=1, S=1, qk_H=32, v_H=32, D=128, Dv=128 (typical LLM decode)
{{1, 1, 32, 128}, {1, 1, 32, 128}, {1, 1, 32, 128}, {1, 32, 128, 128}, {1, 1, 32}, {1, 1, 32}},
- // B=1, S=16, H=2, D=16, Dv=32 (seq_len > 1, different D and Dv)
+ // B=1, S=16, qk_H=2, v_H=2, D=16, Dv=32 (seq_len > 1, different D and Dv)
{{1, 16, 2, 16}, {1, 16, 2, 16}, {1, 16, 2, 32}, {1, 2, 16, 32}, {1, 16, 2}, {1, 16, 2}},
- // B=2, S=1, H=8, D=64, Dv=64 (batch > 1)
+ // B=2, S=1, qk_H=8, v_H=8, D=64, Dv=64 (batch > 1)
{{2, 1, 8, 64}, {2, 1, 8, 64}, {2, 1, 8, 64}, {2, 8, 64, 64}, {2, 1, 8}, {2, 1, 8}},
+ // B=1, S=4, qk_H=2, v_H=8, D=16, Dv=16 (GQA: v_H is multiple of qk_H)
+ {{1, 4, 2, 16}, {1, 4, 2, 16}, {1, 4, 8, 16}, {1, 8, 16, 16}, {1, 4, 8}, {1, 4, 8}},
};
-INSTANTIATE_TEST_SUITE_P(
- smoke_GatedDeltaNetStatic,
- GatedDeltaNetStaticTest,
- ::testing::Combine(::testing::ValuesIn(static_shapes),
- ::testing::Values(ov::element::f32),
- ::testing::Values(false, true)),
- GatedDeltaNetStaticTest::getTestCaseName);
+INSTANTIATE_TEST_SUITE_P(smoke_GatedDeltaNetStatic,
+ GatedDeltaNetStaticTest,
+ ::testing::Combine(::testing::ValuesIn(static_shapes), ::testing::Values(ov::element::f32), ::testing::Values(false, true)),
+ GatedDeltaNetStaticTest::getTestCaseName);
} // namespace
diff --git a/src/plugins/template/backend/ops/gated_delta_net.cpp b/src/plugins/template/backend/ops/gated_delta_net.cpp
new file mode 100644
index 00000000000..0728e3af127
--- /dev/null
+++ b/src/plugins/template/backend/ops/gated_delta_net.cpp
@@ -0,0 +1,51 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "openvino/reference/gated_delta_net.hpp"
+
+#include "evaluate_node.hpp"
+#include "gated_delta_net_shape_inference.hpp"
+#include "openvino/core/type/element_type_traits.hpp"
+#include "openvino/op/gated_delta_net.hpp"
+
+template <ov::element::Type_t ET>
+bool evaluate(const std::shared_ptr<ov::op::internal::GatedDeltaNet>& op,
+ ov::TensorVector& outputs,
+ const ov::TensorVector& inputs) {
+ using T = typename ov::element_type_traits<ET>::value_type;
+
+ const auto input_shapes = ov::util::get_tensors_partial_shapes(inputs);
+ const auto output_shapes = ov::op::internal::shape_infer(op.get(), input_shapes);
+ outputs[0].set_shape(output_shapes[0].to_shape());
+ outputs[1].set_shape(output_shapes[1].to_shape());
+
+ ov::reference::gated_delta_net<T>(inputs[0].data<const T>(),
+ inputs[1].data<const T>(),
+ inputs[2].data<const T>(),
+ inputs[3].data<const T>(),
+ inputs[4].data<const T>(),
+ inputs[5].data<const T>(),
+ outputs[0].data<T>(),
+ outputs[1].data<T>(),
+ inputs[0].get_shape(),
+ inputs[2].get_shape(),
+ op->get_fuse_qk_l2norm(),
+ static_cast<T>(op->get_q_l2_norm_eps()),
+ static_cast<T>(op->get_k_l2_norm_eps()));
+ return true;
+}
+
+template <>
+bool evaluate_node<ov::op::internal::GatedDeltaNet>(std::shared_ptr<ov::Node> node,
+ ov::TensorVector& outputs,
+ const ov::TensorVector& inputs) {
+ const auto& element_type = node->get_input_element_type(0);
+
+ switch (element_type) {
+ case ov::element::f32:
+ return evaluate<ov::element::f32>(ov::as_type_ptr<ov::op::internal::GatedDeltaNet>(node), outputs, inputs);
+ default:
+ OPENVINO_THROW("Unhandled data type ", element_type, " in evaluate_node()");
+ }
+}
diff --git a/src/plugins/template/backend/ops/ops_evaluates.hpp b/src/plugins/template/backend/ops/ops_evaluates.hpp
index a186fc4a6d9..d0a7de9be75 100644
--- a/src/plugins/template/backend/ops/ops_evaluates.hpp
+++ b/src/plugins/template/backend/ops/ops_evaluates.hpp
@@ -4,6 +4,7 @@
#pragma once
#include "evaluate_node.hpp"
+#include "openvino/op/gated_delta_net.hpp"
#include "openvino/op/ops.hpp"
#include "openvino/op/paged_attention.hpp"
#include "openvino/op/rms_norm.hpp"
@@ -549,6 +550,10 @@ extern template bool evaluate_node<ov::op::internal::AUGRUSequence>(std::shared_
ov::TensorVector& outputs,
const ov::TensorVector& inputs);
+extern template bool evaluate_node<ov::op::internal::GatedDeltaNet>(std::shared_ptr<ov::Node> node,
+ ov::TensorVector& outputs,
+ const ov::TensorVector& inputs);
+
extern template bool evaluate_node<ov::op::internal::RMS>(std::shared_ptr<ov::Node> node,
ov::TensorVector& outputs,
const ov::TensorVector& inputs);
diff --git a/src/plugins/template/backend/opset_int_tbl.hpp b/src/plugins/template/backend/opset_int_tbl.hpp
index c10ac0808e6..ebc765a67bd 100644
--- a/src/plugins/template/backend/opset_int_tbl.hpp
+++ b/src/plugins/template/backend/opset_int_tbl.hpp
@@ -188,6 +188,7 @@ _OPENVINO_OP_REG(OneHot, ov::op::v16)
_OPENVINO_OP_REG(AUGRUCell, ov::op::internal)
_OPENVINO_OP_REG(AUGRUSequence, ov::op::internal)
+_OPENVINO_OP_REG(GatedDeltaNet, ov::op::internal)
_OPENVINO_OP_REG(RMS, ov::op::internal)
_OPENVINO_OP_REG(RMSNorm, ov::op::internal)
_OPENVINO_OP_REG(PagedAttentionExtension, ov::op)
diff --git a/src/plugins/template/tests/functional/op_reference/gated_delta_net.cpp b/src/plugins/template/tests/functional/op_reference/gated_delta_net.cpp
new file mode 100644
index 00000000000..1205173960f
--- /dev/null
+++ b/src/plugins/template/tests/functional/op_reference/gated_delta_net.cpp
@@ -0,0 +1,345 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "openvino/op/gated_delta_net.hpp"
+
+#include <gtest/gtest.h>
+
+#include "base_reference_test.hpp"
+#include "openvino/op/parameter.hpp"
+
+using namespace reference_tests;
+using namespace ov;
+
+namespace {
+
+struct GatedDeltaNetParams {
+ PartialShape qShape;
+ PartialShape kShape;
+ PartialShape vShape;
+ PartialShape stateShape;
+ PartialShape gateShape;
+ PartialShape betaShape;
+ bool fuseQkL2Norm;
+ float qL2NormEps;
+ float kL2NormEps;
+ std::string testcaseName;
+ reference_tests::Tensor qData;
+ reference_tests::Tensor kData;
+ reference_tests::Tensor vData;
+ reference_tests::Tensor stateData;
+ reference_tests::Tensor gateData;
+ reference_tests::Tensor betaData;
+ reference_tests::Tensor expectedOutput;
+ reference_tests::Tensor expectedState;
+};
+
+template <typename T>
+GatedDeltaNetParams PrepareTestCaseParams(const PartialShape& qShape,
+ const PartialShape& kShape,
+ const PartialShape& vShape,
+ const PartialShape& stateShape,
+ const PartialShape& gateShape,
+ const PartialShape& betaShape,
+ bool fuseQkL2Norm,
+ float qL2NormEps,
+ float kL2NormEps,
+ const std::vector<T>& qData,
+ const std::vector<T>& kData,
+ const std::vector<T>& vData,
+ const std::vector<T>& stateData,
+ const std::vector<T>& gateData,
+ const std::vector<T>& betaData,
+ const std::vector<T>& expectedOutput,
+ const std::vector<T>& expectedState,
+ const std::string& description) {
+ GatedDeltaNetParams ret;
+ const auto elementType = element::from<T>();
+ ret.qShape = qShape;
+ ret.kShape = kShape;
+ ret.vShape = vShape;
+ ret.stateShape = stateShape;
+ ret.gateShape = gateShape;
+ ret.betaShape = betaShape;
+ ret.fuseQkL2Norm = fuseQkL2Norm;
+ ret.qL2NormEps = qL2NormEps;
+ ret.kL2NormEps = kL2NormEps;
+ ret.testcaseName = description;
+ ret.qData = reference_tests::Tensor(elementType, qShape.to_shape(), qData);
+ ret.kData = reference_tests::Tensor(elementType, kShape.to_shape(), kData);
+ ret.vData = reference_tests::Tensor(elementType, vShape.to_shape(), vData);
+ ret.stateData = reference_tests::Tensor(elementType, stateShape.to_shape(), stateData);
+ ret.gateData = reference_tests::Tensor(elementType, gateShape.to_shape(), gateData);
+ ret.betaData = reference_tests::Tensor(elementType, betaShape.to_shape(), betaData);
+ ret.expectedOutput = reference_tests::Tensor(elementType, vShape.to_shape(), expectedOutput);
+ ret.expectedState = reference_tests::Tensor(elementType, stateShape.to_shape(), expectedState);
+ return ret;
+}
+
+class ReferenceGatedDeltaNetTest : public testing::TestWithParam<GatedDeltaNetParams>, public CommonReferenceTest {
+public:
+ void SetUp() override {
+ const auto& params = GetParam();
+ function = CreateFunction(params);
+ inputData = {params.qData.data,
+ params.kData.data,
+ params.vData.data,
+ params.stateData.data,
+ params.gateData.data,
+ params.betaData.data};
+ refOutData = {params.expectedOutput.data, params.expectedState.data};
+ threshold = 1e-5f;
+ abs_threshold = 1e-5f;
+ }
+
+ static std::string getTestCaseName(const testing::TestParamInfo<GatedDeltaNetParams>& obj) {
+ const auto& param = obj.param;
+ std::ostringstream result;
+ result << "type=" << param.qData.data.get_element_type();
+ result << "_qShape=" << param.qShape;
+ result << "_vShape=" << param.vShape;
+ result << "_fuse=" << param.fuseQkL2Norm;
+ result << "_=" << param.testcaseName;
+ return result.str();
+ }
+
+private:
+ static std::shared_ptr<Model> CreateFunction(const GatedDeltaNetParams& params) {
+ const auto elementType = params.qData.data.get_element_type();
+ const auto query = std::make_shared<op::v0::Parameter>(elementType, params.qShape);
+ const auto key = std::make_shared<op::v0::Parameter>(elementType, params.kShape);
+ const auto value = std::make_shared<op::v0::Parameter>(elementType, params.vShape);
+ const auto state = std::make_shared<op::v0::Parameter>(elementType, params.stateShape);
+ const auto gate = std::make_shared<op::v0::Parameter>(elementType, params.gateShape);
+ const auto beta = std::make_shared<op::v0::Parameter>(elementType, params.betaShape);
+ const auto gdn = std::make_shared<op::internal::GatedDeltaNet>(query,
+ key,
+ value,
+ state,
+ gate,
+ beta,
+ params.fuseQkL2Norm,
+ params.qL2NormEps,
+ params.kL2NormEps);
+ return std::make_shared<Model>(OutputVector{gdn->output(0), gdn->output(1)},
+ ParameterVector{query, key, value, state, gate, beta});
+ }
+};
+
+TEST_P(ReferenceGatedDeltaNetTest, CompareWithHardcodedRefs) {
+ Exec();
+}
+
+template <element::Type_t ET>
+std::vector<GatedDeltaNetParams> generateParams() {
+ using T = typename element_type_traits<ET>::value_type;
+ std::vector<GatedDeltaNetParams> params{
+ PrepareTestCaseParams<T>(PartialShape{1, 1, 1, 2},
+ PartialShape{1, 1, 1, 2},
+ PartialShape{1, 1, 1, 1},
+ PartialShape{1, 1, 2, 1},
+ PartialShape{1, 1, 1},
+ PartialShape{1, 1, 1},
+ false,
+ 1e-06f,
+ 1e-06f,
+ std::vector<T>{1.0000000f, 2.0000000f},
+ std::vector<T>{3.0000000f, 4.0000000f},
+ std::vector<T>{3.0000000f},
+ std::vector<T>{0.0000000f, 0.0000000f},
+ std::vector<T>{0.0000000f},
+ std::vector<T>{1.0000000f},
+ std::vector<T>{23.3345242f},
+ std::vector<T>{9.0000000f, 12.0000000f},
+ "single_step"),
+ PrepareTestCaseParams<T>(PartialShape{1, 1, 1, 2},
+ PartialShape{1, 1, 1, 2},
+ PartialShape{1, 1, 1, 1},
+ PartialShape{1, 1, 2, 1},
+ PartialShape{1, 1, 1},
+ PartialShape{1, 1, 1},
+ true,
+ 0.0f,
+ 0.0f,
+ std::vector<T>{3.0000000f, 4.0000000f},
+ std::vector<T>{3.0000000f, 4.0000000f},
+ std::vector<T>{3.0000000f},
+ std::vector<T>{0.0000000f, 0.0000000f},
+ std::vector<T>{0.0000000f},
+ std::vector<T>{1.0000000f},
+ std::vector<T>{2.1213202f},
+ std::vector<T>{1.8000000f, 2.4000001f},
+ "fused_qk_l2norm"),
+ PrepareTestCaseParams<T>(
+ PartialShape{2, 3, 2, 4},
+ PartialShape{2, 3, 2, 4},
+ PartialShape{2, 3, 2, 4},
+ PartialShape{2, 2, 4, 4},
+ PartialShape{2, 3, 2},
+ PartialShape{2, 3, 2},
+ false,
+ 1e-06f,
+ 1e-06f,
+ std::vector<T>{0.0980000f, 0.4300000f, 0.2060000f, 0.0900000f, -0.1530000f, 0.2920000f, -0.1250000f,
+ 0.7840000f, 0.9270000f, -0.2330000f, 0.5830000f, 0.0580000f, 0.1360000f, 0.8510000f,
+ -0.8580000f, -0.8260000f, -0.9600000f, 0.6650000f, 0.5560000f, 0.7400000f, 0.9570000f,
+ 0.5980000f, -0.0770000f, 0.5610000f, -0.7630000f, 0.2800000f, -0.7130000f, 0.8890000f,
+ 0.0440000f, -0.1710000f, -0.4710000f, 0.5480000f, -0.0880000f, 0.1370000f, -0.9620000f,
+ 0.2350000f, 0.2240000f, 0.2340000f, 0.8870000f, 0.3640000f, -0.2810000f, -0.1260000f,
+ 0.3950000f, -0.8800000f, 0.3340000f, 0.3410000f, -0.5790000f, -0.7420000f},
+ std::vector<T>{-0.3690000f, -0.2730000f, 0.1400000f, -0.1230000f, 0.9770000f, -0.7960000f, -0.5820000f,
+ -0.6770000f, 0.3060000f, -0.4930000f, -0.0670000f, -0.5110000f, -0.6820000f, -0.7790000f,
+ 0.3130000f, -0.7240000f, -0.6070000f, -0.2630000f, 0.6420000f, -0.8060000f, 0.6760000f,
+ -0.8080000f, 0.9530000f, -0.0630000f, 0.9540000f, 0.2100000f, 0.4790000f, -0.9220000f,
+ -0.4340000f, -0.7600000f, -0.4080000f, -0.7630000f, -0.3640000f, -0.1710000f, -0.8720000f,
+ 0.3850000f, 0.1330000f, -0.4690000f, 0.0460000f, -0.8120000f, 0.1520000f, 0.8590000f,
+ -0.3630000f, 0.3350000f, -0.7360000f, 0.4330000f, -0.4210000f, -0.6340000f},
+ std::vector<T>{0.1730000f, -0.9600000f, 0.6580000f, -0.9910000f, 0.3560000f, -0.4600000f, 0.4700000f,
+ 0.9240000f, -0.5020000f, 0.1520000f, 0.1840000f, 0.1450000f, -0.5540000f, 0.9050000f,
+ -0.1060000f, 0.6930000f, 0.3990000f, -0.4050000f, 0.6280000f, -0.2070000f, 0.7620000f,
+ 0.1630000f, 0.7630000f, 0.3850000f, 0.4510000f, 0.0030000f, 0.9120000f, 0.2880000f,
+ -0.1520000f, 0.2130000f, -0.9620000f, -0.3970000f, 0.3200000f, -0.4200000f, 0.2360000f,
+ -0.1420000f, -0.7290000f, -0.4030000f, 0.1400000f, 0.1820000f, 0.1490000f, 0.3060000f,
+ 0.3040000f, -0.1370000f, 0.7930000f, -0.2650000f, -0.1280000f, 0.7840000f},
+ std::vector<T>{
+ 0.6120000f, 0.4080000f, -0.8000000f, 0.8390000f, 0.4280000f, 0.9980000f, -0.7010000f, 0.7360000f,
+ -0.6750000f, 0.2310000f, -0.7520000f, 0.6960000f, 0.6150000f, 0.1380000f, -0.1860000f, -0.8620000f,
+ 0.3950000f, -0.0930000f, 0.4440000f, 0.7330000f, 0.9510000f, 0.7120000f, -0.9770000f, -0.2800000f,
+ 0.4600000f, -0.6570000f, 0.0420000f, -0.8910000f, -0.6000000f, -0.9630000f, 0.5870000f, -0.5520000f,
+ -0.3090000f, 0.8560000f, 0.4090000f, -0.9360000f, -0.6710000f, 0.2430000f, 0.1540000f, -0.5240000f,
+ 0.8680000f, 0.2280000f, 0.0710000f, 0.1800000f, 0.4600000f, -0.3760000f, -0.2040000f, -0.5800000f,
+ -0.6280000f, 0.8890000f, 0.4790000f, -0.0190000f, -0.5450000f, -0.4910000f, -0.8840000f, -0.1310000f,
+ -0.3760000f, 0.3930000f, -0.2440000f, -0.6410000f, -0.9510000f, -0.8660000f, 0.3590000f, -0.0930000f},
+ std::vector<T>{-0.4630000f,
+ -0.1030000f,
+ -0.0100000f,
+ -0.7830000f,
+ -0.3370000f,
+ -0.7370000f,
+ -0.9790000f,
+ -0.2420000f,
+ -0.6800000f,
+ -0.6170000f,
+ -0.4120000f,
+ -0.1690000f},
+ std::vector<T>{0.6290000f,
+ 0.8730000f,
+ 0.2740000f,
+ 0.7980000f,
+ 0.1860000f,
+ 0.9530000f,
+ 0.6870000f,
+ 0.2160000f,
+ 0.9470000f,
+ 0.7310000f,
+ 0.2540000f,
+ 0.2130000f},
+ std::vector<T>{0.0292801f, 0.1965543f, -0.1907852f, 0.1802422f, -0.3475720f, 0.0899363f, 0.1347459f,
+ 0.0344922f, -0.0127816f, 0.1556332f, -0.3452297f, 0.3505386f, 0.3307252f, 0.1523854f,
+ -0.2742097f, 0.0062912f, 0.0174631f, 0.0383229f, -0.0372409f, -0.1582982f, 0.2121457f,
+ -0.3082414f, 0.0589287f, -0.2175981f, -0.4188678f, 0.1074970f, -0.5152162f, -0.2856665f,
+ -0.0921463f, -0.2085163f, 0.2047262f, 0.1161998f, 0.1281915f, -0.1862048f, 0.1532833f,
+ -0.0736611f, -0.0076235f, 0.1365270f, 0.0008625f, -0.1217498f, -0.0673063f, 0.0286443f,
+ -0.0572516f, 0.0899307f, -0.0291833f, -0.0237945f, -0.0286928f, 0.1317744f},
+ std::vector<T>{
+ 0.0640817f, 0.3329480f, -0.4654701f, 0.5303040f, 0.1172151f, 0.4877794f, -0.3810537f, 0.4352176f,
+ -0.1524748f, 0.0443132f, -0.2629542f, 0.2324124f, 0.1395575f, 0.0638709f, -0.1644997f, -0.3056021f,
+ 0.7906327f, -0.2136607f, 0.4572420f, 0.0166299f, -0.3592100f, -0.2845609f, -0.5910100f, -0.4625308f,
+ 0.6720783f, 0.3752943f, 0.5714668f, 0.3227212f, -0.1172666f, -0.3795801f, 0.1385095f, -0.2667879f,
+ -0.0415166f, 0.1235775f, 0.0786008f, -0.0288009f, -0.0850454f, 0.1343191f, 0.0412224f, -0.0513090f,
+ -0.1859950f, 0.2082087f, -0.2475475f, 0.0598664f, 0.0949164f, -0.0303361f, -0.0119988f, -0.1609728f,
+ -0.3469469f, 0.2534083f, 0.2013349f, -0.0675972f, 0.2506652f, 0.0815753f, -0.2609223f, 0.0111625f,
+ -0.1646039f, 0.1218667f, -0.0549655f, -0.2564011f, 0.1661306f, 0.1205980f, 0.0909460f, -0.1804092f},
+ "multihead_multibatch_seq"),
+ PrepareTestCaseParams<T>(
+ PartialShape{1, 3, 2, 4},
+ PartialShape{1, 3, 2, 4},
+ PartialShape{1, 3, 4, 3},
+ PartialShape{1, 4, 4, 3},
+ PartialShape{1, 3, 4},
+ PartialShape{1, 3, 4},
+ true,
+ 1e-06f,
+ 1e-06f,
+ std::vector<T>{-0.1660000f, 0.4410000f, -1.0000000f, -0.3950000f, -0.7060000f, -0.8150000f,
+ -0.6270000f, -0.3090000f, -0.2060000f, 0.0780000f, -0.1620000f, 0.3700000f,
+ -0.5910000f, 0.7560000f, -0.9450000f, 0.3410000f, -0.1650000f, 0.1170000f,
+ -0.7190000f, -0.6040000f, 0.6010000f, 0.9370000f, -0.3730000f, 0.3850000f},
+ std::vector<T>{0.7530000f, 0.7890000f, -0.8300000f, -0.9220000f, -0.6600000f, 0.7560000f,
+ -0.8030000f, -0.1580000f, 0.9160000f, 0.0660000f, 0.3840000f, -0.3690000f,
+ 0.3730000f, 0.6690000f, -0.9630000f, 0.5000000f, 0.9780000f, 0.4960000f,
+ -0.4390000f, 0.5790000f, -0.7940000f, -0.1040000f, 0.8170000f, -0.4130000f},
+ std::vector<T>{-0.4240000f, -0.7400000f, -0.9610000f, 0.3580000f, -0.5770000f, -0.4690000f,
+ -0.0170000f, -0.8930000f, 0.1480000f, -0.7070000f, 0.1790000f, 0.4000000f,
+ -0.7950000f, -0.1720000f, 0.3890000f, -0.1720000f, -0.9000000f, 0.0720000f,
+ 0.3280000f, 0.0300000f, 0.8890000f, 0.1730000f, 0.8070000f, -0.7250000f,
+ -0.7210000f, 0.6150000f, -0.2050000f, -0.6690000f, 0.8550000f, -0.3040000f,
+ 0.5020000f, 0.4520000f, 0.7670000f, 0.2470000f, 0.5020000f, -0.3020000f},
+ std::vector<T>{-0.4600000f, 0.7920000f, -0.1440000f, 0.9300000f, 0.3270000f, 0.2430000f, -0.7710000f,
+ 0.8990000f, -0.1000000f, 0.1570000f, -0.1840000f, -0.5260000f, 0.8070000f, 0.1470000f,
+ -0.9940000f, 0.2340000f, -0.3470000f, 0.0540000f, 0.7720000f, -0.2850000f, 0.8170000f,
+ 0.2470000f, -0.9680000f, 0.8590000f, 0.3820000f, 0.9950000f, -0.6550000f, -0.7260000f,
+ 0.8650000f, 0.3940000f, -0.8680000f, 0.5110000f, 0.5080000f, 0.8460000f, 0.4230000f,
+ -0.7510000f, -0.9600000f, -0.9480000f, -0.9430000f, -0.5080000f, 0.7200000f, 0.0780000f,
+ 0.1060000f, 0.6840000f, -0.7520000f, -0.4420000f, 0.1720000f, 0.9390000f},
+ std::vector<T>{-0.4390000f,
+ -0.9810000f,
+ -0.1990000f,
+ -0.7670000f,
+ -0.1930000f,
+ -0.6120000f,
+ -0.1360000f,
+ -0.2530000f,
+ -0.4440000f,
+ -0.8640000f,
+ -0.9400000f,
+ -0.8790000f},
+ std::vector<T>{0.0450000f,
+ 0.1070000f,
+ 0.2260000f,
+ 0.7130000f,
+ 0.5600000f,
+ 0.0130000f,
+ 0.0720000f,
+ 0.9670000f,
+ 0.5680000f,
+ 0.2030000f,
+ 0.2520000f,
+ 0.7440000f},
+ std::vector<T>{0.3156259f, -0.2373515f, 0.1005170f, -0.1291053f, 0.0471067f, -0.1535292f,
+ 0.1965116f, -0.6087571f, 0.0139169f, 0.1418082f, -0.0751124f, 0.1409220f,
+ 0.3011487f, -0.0347568f, -0.1512573f, -0.0425837f, -0.0676554f, 0.0856228f,
+ 0.0934182f, -0.1311470f, 0.0110565f, 0.0364411f, 0.3941338f, -0.1337204f,
+ 0.1462962f, -0.1119237f, 0.0600990f, -0.0247636f, 0.0160566f, -0.0388770f,
+ -0.0470632f, 0.0939437f, -0.0877036f, -0.0738933f, -0.0188734f, -0.0037616f},
+ std::vector<T>{-0.6210173f, 0.2913882f, -0.0153076f, 0.1345025f, 0.2170283f, 0.0404436f, -0.1634557f,
+ 0.1040684f, 0.0639312f, -0.0750427f, 0.1945509f, -0.2552438f, -0.0368244f, 0.1344352f,
+ -0.1218083f, -0.0306820f, 0.0292087f, -0.0143055f, 0.1094918f, -0.0772062f, 0.0872796f,
+ -0.0474569f, 0.0097682f, 0.0502628f, -0.0305745f, 0.2023586f, -0.2529472f, -0.2165265f,
+ 0.1987633f, 0.1122109f, -0.1108112f, 0.2758878f, 0.2087887f, 0.1652790f, 0.0706161f,
+ -0.2388630f, -0.1336043f, -0.3598680f, 0.0403608f, -0.0630931f, 0.2500483f, -0.1466690f,
+ 0.0922092f, 0.1713165f, -0.1283414f, -0.0228204f, -0.0019501f, 0.1454688f},
+ "gqa_fused_l2norm"),
+ };
+ return params;
+}
+
+std::vector<GatedDeltaNetParams> generateCombinedParams() {
+ // GatedDeltaNet evaluate currently dispatches f32 only.
+ const std::vector<std::vector<GatedDeltaNetParams>> generatedParams{
+ generateParams<element::Type_t::f32>(),
+ };
+ std::vector<GatedDeltaNetParams> combinedParams;
+ for (const auto& params : generatedParams) {
+ combinedParams.insert(combinedParams.end(), params.begin(), params.end());
+ }
+ return combinedParams;
+}
+
+INSTANTIATE_TEST_SUITE_P(smoke_GatedDeltaNet_With_Hardcoded_Refs,
+ ReferenceGatedDeltaNetTest,
+ testing::ValuesIn(generateCombinedParams()),
+ ReferenceGatedDeltaNetTest::getTestCaseName);
+
+} // namespace