Skip to content

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

[CORE] FIx PagedGatedDeltaNet type validation for independent state float type (#35541)

Mateusz Mikolajczyk3eea2b7e3356
diff --git a/src/core/src/op/paged_gated_delta_net.cpp b/src/core/src/op/paged_gated_delta_net.cpp
index 1f8527ef902..d70640fe5cf 100644
--- a/src/core/src/op/paged_gated_delta_net.cpp
+++ b/src/core/src/op/paged_gated_delta_net.cpp
@@ -58,21 +58,29 @@ void PagedGatedDeltaNet::validate_and_infer_types() {
NODE_VALIDATION_CHECK(this, get_input_size() == 11);
+ // query (0), key (1), value (2), gate (4), and beta (5) participate in the main arithmetic
+ // and therefore must share a common float element type; it also determines the output precision.
+ // recurrent_state_table (3) is an in-place state cache and is allowed to use an independent
+ // float element type so plugins can maintain lower-precision state without breaking in-place semantics.
ov::element::Type common_float_type = get_input_element_type(0);
const bool float_types_merge =
ov::element::Type::merge(common_float_type, common_float_type, get_input_element_type(1)) &&
ov::element::Type::merge(common_float_type, common_float_type, get_input_element_type(2)) &&
- ov::element::Type::merge(common_float_type, common_float_type, get_input_element_type(3)) &&
ov::element::Type::merge(common_float_type, common_float_type, get_input_element_type(4)) &&
ov::element::Type::merge(common_float_type, common_float_type, get_input_element_type(5));
NODE_VALIDATION_CHECK(this,
float_types_merge,
- "PagedGatedDeltaNet expects query, key, value, recurrent_state_table, gate, and beta to "
- "have the same element type.");
+ "PagedGatedDeltaNet expects query, key, value, gate, and beta to have the same element "
+ "type.");
NODE_VALIDATION_CHECK(this,
common_float_type.is_dynamic() || common_float_type == ov::element::f32 ||
common_float_type == ov::element::f16 || common_float_type == ov::element::bf16,
"Float inputs must have f32, f16, or bf16 element type.");
+ const auto& state_et = get_input_element_type(3);
+ NODE_VALIDATION_CHECK(this,
+ state_et.is_dynamic() || state_et == ov::element::f32 || state_et == ov::element::f16 ||
+ state_et == ov::element::bf16,
+ "Float inputs must have f32, f16, or bf16 element type.");
for (size_t i = 6; i < 11; ++i) {
const auto& et = get_input_element_type(i);
NODE_VALIDATION_CHECK(this,
diff --git a/src/core/tests/type_prop/paged_gated_delta_net.cpp b/src/core/tests/type_prop/paged_gated_delta_net.cpp
index 967e1f59a0d..32542275461 100644
--- a/src/core/tests/type_prop/paged_gated_delta_net.cpp
+++ b/src/core/tests/type_prop/paged_gated_delta_net.cpp
@@ -516,7 +516,37 @@ TEST_F(TypePropPagedGatedDeltaNetTest, overlapping_dim_ranges_compatible) {
EXPECT_EQ(op->get_output_partial_shape(0), (PartialShape{-1, {4, 6}, {16, 32}}));
}
-TEST_F(TypePropPagedGatedDeltaNetTest, mixed_float_types_incompatible) {
+TEST_F(TypePropPagedGatedDeltaNetTest, state_float_type_independent_from_main_inputs) {
+ const auto query = std::make_shared<op::v0::Parameter>(element::f32, Shape{10, 4, 8});
+ const auto key = std::make_shared<op::v0::Parameter>(element::f32, Shape{10, 4, 8});
+ const auto value = std::make_shared<op::v0::Parameter>(element::f32, Shape{10, 4, 16});
+ const auto state = std::make_shared<op::v0::Parameter>(element::f16, Shape{5, 4, 16, 8});
+ const auto gate = std::make_shared<op::v0::Parameter>(element::f32, Shape{10, 4});
+ const auto beta = std::make_shared<op::v0::Parameter>(element::f32, Shape{10, 4});
+ const auto subsequence_begins = std::make_shared<op::v0::Parameter>(element::i32, Shape{3});
+ const auto la_block_indices = std::make_shared<op::v0::Parameter>(element::i32, Shape{5});
+ const auto la_block_indices_begins = std::make_shared<op::v0::Parameter>(element::i32, Shape{3});
+ const auto processed_tokens = std::make_shared<op::v0::Parameter>(element::i32, Shape{2});
+ const auto cache_interval = std::make_shared<op::v0::Parameter>(element::i32, Shape{2});
+
+ const auto op = make_op(OutputVector{query,
+ key,
+ value,
+ state,
+ gate,
+ beta,
+ subsequence_begins,
+ la_block_indices,
+ la_block_indices_begins,
+ processed_tokens,
+ cache_interval});
+
+ EXPECT_EQ(op->get_output_size(), 1);
+ EXPECT_EQ(op->get_output_element_type(0), element::f32);
+ EXPECT_EQ(op->get_output_partial_shape(0), PartialShape(Shape{10, 4, 16}));
+}
+
+TEST_F(TypePropPagedGatedDeltaNetTest, float_type_mismatch_among_query_key_value_gate_beta) {
const auto query = std::make_shared<op::v0::Parameter>(element::f32, Shape{10, 4, 8});
const auto key = std::make_shared<op::v0::Parameter>(element::f16, Shape{10, 4, 8});
const auto value = std::make_shared<op::v0::Parameter>(element::f32, Shape{10, 4, 16});
@@ -541,7 +571,8 @@ TEST_F(TypePropPagedGatedDeltaNetTest, mixed_float_types_incompatible) {
processed_tokens,
cache_interval}),
NodeValidationFailure,
- testing::HasSubstr("have the same element type"));
+ testing::HasSubstr("PagedGatedDeltaNet expects query, key, value, gate, and beta to have the "
+ "same element type."));
}
TEST_F(TypePropPagedGatedDeltaNetTest, i64_integer_inputs) {