Skip to content

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

[GPU] support scale/zp as input (#38204)

Yaru Du577aa224f593
diff --git a/src/plugins/intel_gpu/src/graph/graph_optimizer/select_preferred_formats.cpp b/src/plugins/intel_gpu/src/graph/graph_optimizer/select_preferred_formats.cpp
index cff0d6c14a2..455fece2980 100644
--- a/src/plugins/intel_gpu/src/graph/graph_optimizer/select_preferred_formats.cpp
+++ b/src/plugins/intel_gpu/src/graph/graph_optimizer/select_preferred_formats.cpp
@@ -240,8 +240,10 @@ void select_preferred_formats::run(program& p) {
n->set_preferred_input_fmt(
decompression_param_idx,
n->get_input_layout(decompression_param_idx).format);
- decompression_param_idx++;
}
+ // The index must advance even when the format was already chosen (e.g. by oneDNN
+ // query_formats), otherwise the zero-point slot below would re-check the scale index.
+ decompression_param_idx++;
} if (fc_prim->decompression_zero_point.is_valid()) {
if (n->get_preferred_input_fmt(decompression_param_idx) == format::any) {
n->set_preferred_input_fmt(
diff --git a/src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.hpp b/src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.hpp
index 9960d13efba..cbc9fd61b34 100644
--- a/src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.hpp
+++ b/src/plugins/intel_gpu/src/graph/impls/onednn/fully_connected_onednn.hpp
@@ -140,14 +140,29 @@ struct FullyConnectedImplementationManager : public ImplementationManager {
in_out_fmts_t query_formats(const program_node& node) const override {
assert(node.is_type<fully_connected>());
+ const auto& fc_node = node.as<fully_connected>();
+ const auto& fc_prim = fc_node.get_primitive();
std::vector<format::type> in_fmts(node.get_dependencies().size(), format::any);
std::vector<format::type> out_fmts(node.get_outputs_count(), format::any);
size_t out_rank = node.get_output_layout().get_rank();
- for (size_t idx = 0 ; idx < node.get_dependencies().size() ; idx++) {
+ for (size_t idx = 0; idx < node.get_dependencies().size(); idx++) {
if (node.get_dependency(idx).is_constant()) {
continue;
}
+ const size_t scale_idx = fc_prim->bias.is_valid() ? 3 : 2;
+ const size_t zp_idx = scale_idx + 1;
+ const bool is_decompression_parameter =
+ ((fc_prim->decompression_scale.is_valid() && idx == scale_idx) || (fc_prim->decompression_zero_point.is_valid() && idx == zp_idx));
+ if (is_decompression_parameter) {
+ const auto& in_layout = node.get_input_layout(idx);
+ const bool is_blocked = format::is_blocked(in_layout.format);
+ // oneDNN binds scale/zp as a flat format_tag::a buffer, so only plain layouts can be passed through.
+ // Keep plain permutations (e.g. fbyx from prepare_quantization); reorder blocked layouts to plain.
+ in_fmts[idx] = is_blocked ? format::get_default_format(in_layout.get_rank()).value : in_layout.format.value;
+ GPU_DEBUG_LOG << node.id() << " : " << (is_blocked ? "Reorder blocked" : "Keep plain") << " scale/zp format at index " << idx << std::endl;
+ continue;
+ }
auto target_format = format::get_default_format(out_rank);
diff --git a/src/plugins/intel_gpu/src/plugin/transformations/compressed_weights_pattern.hpp b/src/plugins/intel_gpu/src/plugin/transformations/compressed_weights_pattern.hpp
index 3cda16a1c43..1098cb808de 100644
--- a/src/plugins/intel_gpu/src/plugin/transformations/compressed_weights_pattern.hpp
+++ b/src/plugins/intel_gpu/src/plugin/transformations/compressed_weights_pattern.hpp
@@ -29,13 +29,37 @@ using ov::pass::operator|;
auto weights_convert_reshape_m = wrap_type<ov::op::v1::Reshape>({weights_param_convert_m, any_input()});\
auto decompressed_weights_m = convert_m | weights_convert_reshape_m;\
\
- auto sub_const_m = wrap_type<ov::op::v0::Constant>();\
+ /* Per-tensor (1-element) parameter scale/zp is not supported. */\
+ auto non_scalar_static_param = [](const ov::Output<ov::Node>& output) {\
+ const auto& ps = output.get_partial_shape();\
+ return ps.is_static() && ov::shape_size(ps.to_shape()) > 1;\
+ };\
+ auto sub_value_const_m = wrap_type<ov::op::v0::Constant>();\
+ auto sub_value_param_m = wrap_type<ov::op::v0::Parameter>(non_scalar_static_param);\
+ auto sub_value_param_reshape_m =\
+ wrap_type<ov::op::v1::Reshape>({sub_value_param_m, any_input()}, ov::pass::pattern::has_static_shape());\
+ auto sub_value_param_convert_m = wrap_type<ov::op::v0::Convert>({sub_value_param_m});\
+ auto sub_value_param_convert_reshape_m =\
+ wrap_type<ov::op::v1::Reshape>({sub_value_param_convert_m, any_input()}, ov::pass::pattern::has_static_shape());\
+ auto sub_const_m = sub_value_const_m | sub_value_param_m | sub_value_param_reshape_m |\
+ sub_value_param_convert_reshape_m;\
auto sub_convert_const_m = wrap_type<ov::op::v0::Convert>({sub_const_m});\
auto sub_with_convert_m = wrap_type<ov::op::v1::Subtract>({decompressed_weights_m, sub_convert_const_m});\
auto sub_no_convert_m = wrap_type<ov::op::v1::Subtract>({decompressed_weights_m, sub_const_m});\
auto subtract_m = sub_with_convert_m | sub_no_convert_m;\
\
- auto mul_const_m = wrap_type<ov::op::v0::Constant>();\
+ auto mul_value_const_m = wrap_type<ov::op::v0::Constant>();\
+ auto mul_value_param_m = wrap_type<ov::op::v0::Parameter>(non_scalar_static_param);\
+ auto mul_value_param_reshape_m =\
+ wrap_type<ov::op::v1::Reshape>({mul_value_param_m, any_input()}, ov::pass::pattern::has_static_shape());\
+ auto mul_value_param_convert_m = wrap_type<ov::op::v0::Convert>({mul_value_param_m});\
+ auto mul_value_param_convert_reshape_m =\
+ wrap_type<ov::op::v1::Reshape>({mul_value_param_convert_m, any_input()}, ov::pass::pattern::has_static_shape());\
+ auto mul_value_param_reshape_convert_m =\
+ wrap_type<ov::op::v0::Convert>({mul_value_param_reshape_m});\
+ auto mul_const_m = mul_value_const_m | mul_value_param_m | mul_value_param_reshape_m |\
+ mul_value_param_convert_m | mul_value_param_convert_reshape_m |\
+ mul_value_param_reshape_convert_m;\
auto mul_with_sub_m = wrap_type<ov::op::v1::Multiply>({subtract_m, mul_const_m});\
auto mul_const_convert_m = ov::pass::pattern::optional<ov::op::v0::Convert>(mul_const_m);\
auto mul_no_sub_m = wrap_type<ov::op::v1::Multiply>({decompressed_weights_m, mul_const_convert_m});\
diff --git a/src/plugins/intel_gpu/src/plugin/transformations/convert_fc_to_compressed.cpp b/src/plugins/intel_gpu/src/plugin/transformations/convert_fc_to_compressed.cpp
index 6ebb1728f9d..d67def348b8 100644
--- a/src/plugins/intel_gpu/src/plugin/transformations/convert_fc_to_compressed.cpp
+++ b/src/plugins/intel_gpu/src/plugin/transformations/convert_fc_to_compressed.cpp
@@ -48,7 +48,15 @@ ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedToFullyCon
}
const bool has_transpose_before_reshape = pattern_map.count(transpose_before_reshape_m) != 0u;
const bool has_transpose = pattern_map.count(transpose_m) != 0u;
- auto scale_shape = pattern_map.at(mul_const_m).get_shape();
+ // An optional Convert absorbed by mul_const_convert_m carries the precision the graph used for the
+ // scale (e.g. f32 -> f16 inserted by ConvertPrecision). Keep it for runtime scales: stripping it would
+ // leak the source precision into the FC scale input. Constants need no Convert because Convert(Constant)
+ // is constant-folded long before this pass.
+ const bool scale_convert_absorbed =
+ pattern_map.count(mul_const_convert_m) > 0 && !ov::is_type<ov::op::v0::Constant>(pattern_map.at(mul_const_m).get_node());
+ const ov::Output<Node> scale_output = scale_convert_absorbed ? pattern_map.at(mul_const_convert_m) : pattern_map.at(mul_const_m);
+ auto scale_shape = scale_output.get_shape();
+ const bool with_zero_point = pattern_map.count(subtract_m) > 0;
bool sub_with_convert = pattern_map.count(sub_convert_const_m) > 0;
if (!fc->get_input_partial_shape(1).is_static()) {
@@ -58,12 +66,21 @@ ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedToFullyCon
bool is_weight_3d = (std::count_if(weight_shape.begin(), weight_shape.end(), [](size_t d) {
return d > 1;
}) == 3);
- bool grouped = scale_shape.size() == weight_shape.size() + 1;
-
bool weight_u8 = false;
const std::shared_ptr<ov::Node> weights_key = pattern_map.count(weights_m) ? weights_m : std::shared_ptr<ov::Node>(weights_param_m);
const auto weight_ptr = pattern_map.at(weights_key).get_node_shared_ptr();
const bool weights_are_constant = ov::is_type<ov::op::v0::Constant>(weight_ptr);
+ // A scale/zp rank above the squeezed weights is grouped per the rank convention ([G, N] style) —
+ // unless the dequantized output carried an extra leading unit batch dim that the final Reshape
+ // squeezed away (weights [1, N, K] or [N, K] broadcast by [1, N, 1] scale, flattened to [N, K]):
+ // then the extra parameter dim is a batch, not a group axis. MoveFCReshapeToWeights normalizes such
+ // graphs upstream for Constants, but runtime scale/zp Parameters reach this pass with the 3D shapes
+ // intact. Read the pre-squeeze Multiply shape (never the weights node: weights_param_m may be dynamic).
+ const auto dequantized_pshape = pattern_map.at(mul_m).get_partial_shape();
+ const bool weights_batch_squeezed = dequantized_pshape.is_static() && dequantized_pshape.size() == weight_shape.size() + 1 &&
+ dequantized_pshape[0] == 1 &&
+ std::equal(weight_shape.begin(), weight_shape.end(), dequantized_pshape.to_shape().begin() + 1);
+ bool grouped = scale_shape.size() == weight_shape.size() + 1 && (!weights_batch_squeezed || scale_shape.back() != 1);
if (has_transpose_before_reshape) {
if (weight_ptr->get_element_type() != ov::element::u2) {
return false;
@@ -86,18 +103,19 @@ ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedToFullyCon
weight_u8 = true;
}
- auto reshape_const = [has_transpose, grouped, is_weight_3d](std::shared_ptr<ov::Node> node) {
- auto constant = ov::as_type_ptr<ov::op::v0::Constant>(node);
- OPENVINO_ASSERT(constant != nullptr);
- ov::Shape current_shape = constant->get_shape();
+ std::vector<std::shared_ptr<ov::Node>> result_nodes = {};
+ auto reshape_input = [has_transpose, grouped, is_weight_3d, &result_nodes](std::shared_ptr<ov::Node> node) {
+ const auto& partial_shape = node->get_output_partial_shape(0);
+ OPENVINO_ASSERT(partial_shape.is_static());
+ const ov::Shape current_shape = partial_shape.to_shape();
if (current_shape.size() <= 2) {
- return constant;
+ return node;
}
ov::Shape new_shape;
if (current_shape.size() == 3) {
if (is_weight_3d) {
- return constant;
+ return node;
}
new_shape = (has_transpose || !grouped) ? ov::Shape{current_shape[0] * current_shape[1], current_shape[2]}
: ov::Shape{current_shape[0], current_shape[1] * current_shape[2]};
@@ -110,52 +128,86 @@ ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedToFullyCon
} else {
OPENVINO_THROW("Unexpected constant shape rank ", current_shape.size(), " with is_weight_3d=", is_weight_3d);
}
- auto new_constant = std::make_shared<ov::op::v0::Constant>(*constant, new_shape);
-
- ov::copy_weightless_cache_attr(constant, new_constant);
- return new_constant;
+ if (auto constant = ov::as_type_ptr<ov::op::v0::Constant>(node)) {
+ auto new_constant = std::make_shared<ov::op::v0::Constant>(*constant, new_shape);
+ ov::copy_weightless_cache_attr(constant, new_constant);
+ return std::static_pointer_cast<ov::Node>(new_constant);
+ }
+ auto shape_const =
+ std::make_shared<ov::op::v0::Constant>(ov::element::i32, ov::Shape{new_shape.size()}, std::vector<int64_t>(new_shape.begin(), new_shape.end()));
+ auto reshape = std::make_shared<ov::op::v1::Reshape>(node, shape_const, false);
+ reshape->set_friendly_name(node->get_friendly_name() + "_reshape");
+ ov::copy_runtime_info(node, {shape_const, reshape});
+ result_nodes.push_back(shape_const);
+ result_nodes.push_back(reshape);
+ return std::static_pointer_cast<ov::Node>(reshape);
};
auto convert_zp_const = [&](std::shared_ptr<ov::Node> node) {
auto constant = ov::as_type_ptr<ov::op::v0::Constant>(node);
- std::shared_ptr<ov::Node> result = nullptr;
+ const auto zp_type = node->get_element_type();
+ std::shared_ptr<ov::Node> result = node;
// Convert ZP to u8 (or i8 for a scalar i4 ZP)
- if (constant->get_element_type() == ov::element::u8) {
- result = constant;
- } else if (constant->get_element_type() == ov::element::u4 || constant->get_element_type() == ov::element::u3 ||
- constant->get_element_type() == ov::element::u2) {
+ if (zp_type == ov::element::u8) {
+ result = node;
+ } else if (zp_type == ov::element::u4 || zp_type == ov::element::u3 || zp_type == ov::element::u2) {
result = std::make_shared<ov::op::v0::Convert>(node, ov::element::u8);
// Only unsigned ZP types can be converted to u8.
- } else if (weight_u8 && sub_with_convert && !constant->get_element_type().is_signed()) {
+ } else if (weight_u8 && sub_with_convert && !zp_type.is_signed()) {
result = std::make_shared<ov::op::v0::Convert>(node, ov::element::u8);
- } else if (constant->get_element_type() == ov::element::i4 && ov::shape_size(constant->get_shape()) == 1) {
+ } else if (zp_type == ov::element::i4 && node->get_output_partial_shape(0).is_static() &&
+ ov::shape_size(node->get_output_shape(0)) == 1) {
// oneDNN doesn't support sub-byte per-tensor (common) zero points, so a scalar i4 ZP is converted to i8.
result = std::make_shared<ov::op::v0::Convert>(node, ov::element::i8);
- } else {
- result = constant;
}
- ov::copy_weightless_cache_attr(node, result);
+ if (result != node) {
+ ov::copy_runtime_info(node, result);
+ if (constant) {
+ ov::copy_weightless_cache_attr(constant, result);
+ }
+ }
return result;
};
const ov::Output<Node>& fc_input_a = fc->input(0).get_source_output();
- const auto& scale = has_transpose_before_reshape
- ? pattern_map.at(mul_const_m).get_node_shared_ptr()
- : reshape_const(pattern_map.at(mul_const_m).get_node_shared_ptr());
+ const auto& scale = has_transpose_before_reshape ? scale_output.get_node_shared_ptr() : reshape_input(scale_output.get_node_shared_ptr());
std::shared_ptr<ov::Node> optional_zero_point = nullptr;
- const bool with_zero_point = pattern_map.count(subtract_m) > 0;
if (with_zero_point) {
- const auto zero_point = has_transpose_before_reshape
- ? pattern_map.at(sub_const_m).get_node_shared_ptr()
- : reshape_const(pattern_map.at(sub_const_m).get_node_shared_ptr());
+ // A Reshape over a precision-Convert of an integer zero point carries the converted precision
+ // (e.g. f16), while FullyConnectedCompressed requires the integer value: rebuild the Reshape
+ // directly over the integer source, the way the weights path drops its Convert.
+ auto normalize_zp_precision = [&result_nodes, &sub_with_convert](std::shared_ptr<ov::Node> node) -> std::shared_ptr<ov::Node> {
+ const auto reshape = ov::as_type_ptr<ov::op::v1::Reshape>(node);
+ if (!reshape) {
+ return node;
+ }
+ const auto zp_convert = ov::as_type_ptr<ov::op::v0::Convert>(reshape->get_input_node_shared_ptr(0));
+ if (!zp_convert) {
+ return node;
+ }
+ const auto zp_src = zp_convert->input_value(0);
+ if (zp_src.get_element_type().is_real()) {
+ // Nothing to recover: the source precision is already floating point.
+ return node;
+ }
+ // The graph did carry a precision Convert for this ZP; keep signalling it to convert_zp_const.
+ sub_with_convert = true;
+ auto reshaped_zp = std::make_shared<ov::op::v1::Reshape>(zp_src, reshape->input_value(1), reshape->get_special_zero());
+ reshaped_zp->set_friendly_name(node->get_friendly_name() + "_int_zp");
+ ov::copy_runtime_info({node, zp_convert}, reshaped_zp);
+ result_nodes.push_back(reshaped_zp);
+ return reshaped_zp;
+ };
+ const auto zp_value = normalize_zp_precision(pattern_map.at(sub_const_m).get_node_shared_ptr());
+ const auto zero_point = has_transpose_before_reshape ? zp_value : reshape_input(zp_value);
optional_zero_point = convert_zp_const(zero_point);
}
std::shared_ptr<ov::Node> fc_input_b = weight_ptr;
if (weights_are_constant && !has_transpose_before_reshape) {
- fc_input_b = reshape_const(weight_ptr);
+ fc_input_b = reshape_input(weight_ptr);
} else if (pattern_map.count(weights_reshape_m)) {
fc_input_b = pattern_map.at(weights_reshape_m).get_node_shared_ptr();
}
@@ -165,7 +217,6 @@ ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedToFullyCon
bool transpose_b_scale = fc->get_transpose_b();
bool transpose_b_zp = fc->get_transpose_b();
std::shared_ptr<ov::Node> fc_input_bias = pattern_map.at(bias_m).get_node_shared_ptr();
- std::vector<std::shared_ptr<ov::Node>> result_nodes = {};
if (with_zero_point && ov::is_type<ov::op::v0::Convert>(optional_zero_point)) {
result_nodes.push_back(optional_zero_point);
}
@@ -230,6 +281,7 @@ ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedToFullyCon
ov::Shape{output_shape.size()},
output_shape);
auto reshaped = std::make_shared<ov::op::v1::Reshape>(node, shape_const, false);
+ ov::copy_runtime_info(node, {shape_const, reshaped});
result_nodes.push_back(shape_const);
result_nodes.push_back(reshaped);
return std::static_pointer_cast<ov::Node>(reshaped);
@@ -244,6 +296,8 @@ ConvertFullyConnectedToFullyConnectedCompressed::ConvertFullyConnectedToFullyCon
if (pattern_map.count(mul2_m)) {
auto mul2_op_const = ov::as_type_ptr<ov::op::v0::Constant>(pattern_map.at(mul2_const_m).get_node_shared_ptr());
fc_input_scale = ov::op::util::make_try_fold<ov::op::v1::Multiply>(fc_input_scale, mul2_op_const);
+ // With a Parameter scale this can't fold and stays an executable Multiply, so it needs runtime info.
+ result_nodes.push_back(fc_input_scale);
}
std::shared_ptr<ov::Node> new_fc = nullptr;
diff --git a/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cpp b/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cpp
index 9211c81c6e7..e8fa5faa87a 100644
--- a/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/test_cases/fully_connected_gpu_test.cpp
@@ -20,6 +20,11 @@
#include "intel_gpu/runtime/compilation_context.hpp"
#include "fully_connected_inst.h"
+#include "intel_gpu/plugin/remote_context.hpp"
+#include "intel_gpu/plugin/transformations_pipeline.hpp"
+
+#include "openvino/op/ops.hpp"
+#include "openvino/runtime/core.hpp"
#include <cmath>
@@ -3275,6 +3280,102 @@ void test_compressed_int4_scale_dynamic_batch_gemv(bool is_caching_test,
}
}
+ void test_compressed_int8_parameter_scale_zp(bool is_per_group, bool transpose_scale_zp) {
+ auto& engine = get_test_engine();
+
+ constexpr int64_t ofm = 4;
+ constexpr int64_t ifm = 32;
+ const int64_t groups = is_per_group ? 2 : 1;
+ const int64_t group_size = ifm / groups;
+
+ // Non-transposed scale/zp are [groups, N]; transposed scale/zp are [N, groups].
+ const ov::PartialShape param_shape = transpose_scale_zp ? ov::PartialShape{ofm, groups} : ov::PartialShape{groups, ofm};
+ auto param_offset = [&](int64_t group, int64_t output) {
+ return static_cast<size_t>(transpose_scale_zp ? output * groups + group : group * ofm + output);
+ };
+
+ auto input_mem = engine.allocate_memory({ {1, 2, ifm}, data_types::f16, format::bfyx });
+ auto weights_mem = engine.allocate_memory({ {ofm, ifm}, data_types::u8, format::bfyx });
+ auto scale_mem = engine.allocate_memory({ param_shape, data_types::f16, format::bfyx });
+ auto zp_mem = engine.allocate_memory({ param_shape, data_types::u8, format::bfyx });
+
+ std::vector<float> input_data(2 * ifm);
+ for (size_t i = 0; i < input_data.size(); ++i) {
+ input_data[i] = static_cast<float>(static_cast<int64_t>(i % 3) - 1);
+ }
+ std::vector<uint8_t> weights_data(ofm * ifm);
+ for (int64_t output = 0; output < ofm; ++output) {
+ for (int64_t k = 0; k < ifm; ++k) {
+ weights_data[output * ifm + k] = static_cast<uint8_t>((output * 3 + k) % 8);
+ }
+ }
+ std::vector<float> scale_data(ofm * groups);
+ std::vector<uint8_t> zp_data(ofm * groups);
+ for (int64_t group = 0; group < groups; ++group) {
+ for (int64_t output = 0; output < ofm; ++output) {
+ scale_data[param_offset(group, output)] = 0.5f * static_cast<float>((group + output) % 2 + 1);
+ zp_data[param_offset(group, output)] = static_cast<uint8_t>((group + output) % 3);
+ }
+ }
+
+ std::vector<ov::float16> input_f16(input_data.begin(), input_data.end());
+ std::vector<ov::float16> scale_f16(scale_data.begin(), scale_data.end());
+ set_values(input_mem, input_f16);
+ set_values(weights_mem, weights_data);
+ set_values(scale_mem, scale_f16);
+ set_values(zp_mem, zp_data);
+
+ topology topology(
+ input_layout("input", input_mem->get_layout()),
+ data("weights", weights_mem),
+ input_layout("scale", scale_mem->get_layout()),
+ input_layout("zp", zp_mem->get_layout()),
+ fully_connected("fc_prim", input_info("input"), "weights", "", "scale", "zp", data_types::f16, 3, 2, true,
+ transpose_scale_zp, transpose_scale_zp));
+
+ auto config = get_test_default_config(engine);
+ config.set_property(ov::intel_gpu::allow_new_shape_infer(true));
+ config.set_property(ov::intel_gpu::optimize_data(true));
+
+ network network(engine, topology, config);
+ network.set_input_data("input", input_mem);
+ network.set_input_data("scale", scale_mem);
+ network.set_input_data("zp", zp_mem);
+
+ // Grouped transposed scale/zp [N, groups] must be reordered from bfyx to fbyx to make N innermost.
+ // Per-channel [N, 1] already has N innermost, so it stays as the bfyx parameter.
+ const bool expect_reorder = transpose_scale_zp && is_per_group;
+ auto fc_inst = network.get_primitive("fc_prim");
+ for (size_t idx : {size_t{2}, size_t{3}}) {
+ const auto& dep = fc_inst->get_node().get_dependency(idx);
+ if (expect_reorder) {
+ EXPECT_TRUE(dep.is_type<reorder>()) << "input " << idx;
+ EXPECT_EQ(fc_inst->get_input_layout(idx).format, format::fbyx) << "input " << idx;
+ } else {
+ EXPECT_TRUE(dep.is_type<input_layout>()) << "input " << idx;
+ EXPECT_EQ(fc_inst->get_input_layout(idx).format, format::bfyx) << "input " << idx;
+ }
+ }
+
+ auto outputs = network.execute();
+ auto output_mem = outputs.at("fc_prim").get_memory();
+ cldnn::mem_lock<ov::float16, mem_lock_type::read> output_ptr(output_mem, get_test_stream());
+ ASSERT_EQ((ov::PartialShape{1, 2, ofm}), output_mem->get_layout().get_partial_shape());
+
+ for (int64_t token = 0; token < 2; ++token) {
+ for (int64_t output = 0; output < ofm; ++output) {
+ float expected = 0.0f;
+ for (int64_t k = 0; k < ifm; ++k) {
+ const auto offset = param_offset(k / group_size, output);
+ const float weight = (static_cast<float>(weights_data[output * ifm + k]) - zp_data[offset]) * scale_data[offset];
+ expected += input_data[token * ifm + k] * weight;
+ }
+ EXPECT_NEAR(static_cast<float>(output_ptr[token * ofm + output]), expected, 1e-2f)
+ << "token = " << token << ", output = " << output;
+ }
+ }
+ }
+
void test_dynamic(bool is_caching_test) {
auto& engine = get_test_engine();
@@ -6115,6 +6216,107 @@ TEST_F(fully_connected_gpu_tests, compressed_int8_transpose_scale_zp) {
this->test_compressed_int8_transpose_scale_zp(true);
}
+TEST_F(fully_connected_gpu_tests, compressed_int8_parameter_scale_zp_per_channel) {
+ this->test_compressed_int8_parameter_scale_zp(false, false);
+}
+
+TEST_F(fully_connected_gpu_tests, compressed_int8_parameter_scale_zp_per_channel_transposed) {
+ this->test_compressed_int8_parameter_scale_zp(false, true);
+}
+
+TEST_F(fully_connected_gpu_tests, compressed_int8_parameter_scale_zp_per_group) {
+ this->test_compressed_int8_parameter_scale_zp(true, false);
+}
+
+TEST_F(fully_connected_gpu_tests, compressed_int8_parameter_scale_zp_per_group_transposed) {
+ this->test_compressed_int8_parameter_scale_zp(true, true);
+}
+
+// ov::Core resolves plain "GPU" to the first enumerated device and ignores --device_suffix, so pin the
+// execution device to the one behind get_test_engine() (the plugin reports the very cldnn device_info uuid).
+static std::string get_engine_gpu_device_name() {
+ auto& engine = get_test_engine();
+ const auto engine_uuid = engine.get_device_info().uuid;
+ ov::Core core;
+ for (const auto& device : core.get_available_devices()) {
+ if (device.rfind("GPU", 0) != 0) {
+ continue;
+ }
+ try {
+ if (core.get_property(device, ov::device::uuid).uuid == engine_uuid.uuid) {
+ return device;
+ }
+ } catch (const ov::Exception&) {
+ }
+ }
+ return "GPU";
+}
+
+// Full-pipeline regression for runtime scale/zp: an f32 scale Parameter and a u8 zp Parameter feeding a
+// compressed MatMul reach GPU:PostLPT through ConvertPrecision, so the scale arrives as a bare
+// Convert(Parameter) and the zp as Convert(Parameter) over the Subtract operand. The pipeline must
+// create FullyConnectedCompressed with an f16 scale (Convert preserved) and a u8 integer zero point,
+// and the device must compute the dequantized values.
+TEST_F(fully_connected_gpu_tests, compressed_int8_parameter_scale_zp_full_pipeline) {
+ auto& engine = get_test_engine();
+ auto context = std::make_shared<ov::intel_gpu::RemoteContextImpl>("GPU", std::vector<cldnn::device::ptr>{engine.get_device()});
+
+ // weights u8 [N=4, K=16] = 5, data all ones -> out[n] = 16 * (5 - zp[n]) * scale[n]
+ auto make_model = [](ov::PartialShape data_ps) {
+ auto data = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, data_ps);
+ auto weights = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{4, 16}, {5});
+ auto weights_convert = std::make_shared<ov::op::v0::Convert>(weights, ov::element::f32);
+ auto scale = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{4, 1});
+ auto zp = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, ov::PartialShape{4, 1});
+ auto zp_convert = std::make_shared<ov::op::v0::Convert>(zp, ov::element::f32);
+ auto sub = std::make_shared<ov::op::v1::Subtract>(weights_convert, zp_convert);
+ auto mul = std::make_shared<ov::op::v1::Multiply>(sub, scale);
+ auto matmul = std::make_shared<ov::op::v0::MatMul>(data, mul, false, true);
+ return std::make_shared<ov::Model>(ov::OutputVector{matmul}, ov::ParameterVector{data, scale, zp});
+ };
+
+ auto model = make_model({2, 16});
+ auto config = get_test_default_config(engine);
+ config.finalize(context.get(), model.get());
+ ov::intel_gpu::TransformationsPipeline pipeline(config, context);
+ pipeline.apply(model);
+
+ std::shared_ptr<ov::Node> fc_compressed;
+ for (const auto& op : model->get_ordered_ops()) {
+ if (op->get_type_name() == std::string("FullyConnectedCompressed")) {
+ fc_compressed = op;
+ }
+ }
+ ASSERT_TRUE(fc_compressed != nullptr) << "runtime scale/zp graph was not compressed";
+ EXPECT_EQ(fc_compressed->get_input_element_type(3), ov::element::f16) << "scale input must keep the graph precision (its Convert must not be stripped)";
+ EXPECT_EQ(fc_compressed->get_input_element_type(4), ov::element::u8) << "zero point input must stay an integer value";
+
+ // Execute through the real plugin entry point, on the device selected by --device_suffix.
+ ov::Core core;
+ const auto device_name = get_engine_gpu_device_name();
+ auto compiled = core.compile_model(make_model({2, 16}), device_name, ov::hint::inference_precision(ov::element::f16));
+ const auto execution_devices = compiled.get_property(ov::execution_devices);
+ ASSERT_FALSE(execution_devices.empty());
+ // A single GPU is listed as "GPU" but reported as "GPU.0", so compare by uuid rather than by name.
+ EXPECT_EQ(core.get_property(execution_devices.front(), ov::device::uuid).uuid, engine.get_device_info().uuid.uuid)
+ << "test must run on the get_test_engine() device";
+ auto request = compiled.create_infer_request();
+ std::vector<float> data_data(2 * 16, 1.0f);
+ std::vector<float> scale_data = {2.f, 1.f, 1.f, 2.f};
+ std::vector<uint8_t> zp_data = {4, 4, 5, 4};
+ request.set_input_tensor(0, ov::Tensor(ov::element::f32, {2, 16}, data_data.data()));
+ request.set_input_tensor(1, ov::Tensor(ov::element::f32, {4, 1}, scale_data.data()));
+ request.set_input_tensor(2, ov::Tensor(ov::element::u8, {4, 1}, zp_data.data()));
+ request.infer();
+ const float* output = request.get_output_tensor().data<const float>();
+ const float expected[4] = {32.f, 16.f, 0.f, 32.f}; // 16 * (5 - zp) * scale
+ for (int b = 0; b < 2; ++b) {
+ for (int n = 0; n < 4; ++n) {
+ EXPECT_NEAR(expected[n], output[b * 4 + n], 1e-1f) << "batch = " << b << ", output = " << n;
+ }
+ }
+}
+
TEST_F(fully_connected_gpu_tests, compressed_int8_scale_b1) {
this->test_compressed_int8_scale(false, true, 1, false, false);
}
diff --git a/src/plugins/intel_gpu/tests/unit/transformations/convert_fc_to_compressed_test.cpp b/src/plugins/intel_gpu/tests/unit/transformations/convert_fc_to_compressed_test.cpp
index d6c7c61c1dd..103e34cc3ae 100644
--- a/src/plugins/intel_gpu/tests/unit/transformations/convert_fc_to_compressed_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/transformations/convert_fc_to_compressed_test.cpp
@@ -83,6 +83,337 @@ TEST_F(TransformationTestsF, ConvertFCToCompressed2) {
}
}
+enum class ScaleZpTopology { ReshapeOfConvert, ConvertOfReshape, ConvertOnly };
+
+struct ParameterScaleZpParams {
+ ScaleZpTopology topology;
+ bool with_zp;
+};
+
+class ConvertFCToCompressedParameterScaleZpTest : public testing::WithParamInterface<ParameterScaleZpParams>,
+ public TransformationTestsF {
+public:
+ ConvertFCToCompressedParameterScaleZpTest() : TransformationTestsF() {
+ comparator.enable(FunctionsComparator::ATTRIBUTES);
+ }
+
+ static std::string getTestCaseName(const testing::TestParamInfo<ParameterScaleZpParams>& info) {
+ const auto& [topology, with_zp] = info.param;
+ std::string name;
+ switch (topology) {
+ case ScaleZpTopology::ReshapeOfConvert:
+ name = "ReshapeOfConvert";
+ break;
+ case ScaleZpTopology::ConvertOfReshape:
+ name = "ConvertOfReshape";
+ break;
+ default:
+ name = "ConvertOnly";
+ break;
+ }
+ return name + (with_zp ? "_WithZp" : "_NoZp");
+ }
+};
+
+// Scale and zero point are model Parameters [32, 1, 1] with a Convert to f16, optionally reshaped to [32, 1].
+// The pass must create FullyConnectedCompressed whose scale keeps the Convert(f32 -> f16), so the FC input
+// precision matches the graph, and whose zero point keeps the integer value (Convert dropped, Reshape kept).
+TEST_P(ConvertFCToCompressedParameterScaleZpTest, ConvertsParameterScaleAndZeroPoint) {
+ const auto topology = GetParam().topology;
+ const auto with_zp = GetParam().with_zp;
+
+ auto to_f16 = [](const ov::Output<ov::Node>& node) -> std::shared_ptr<ov::Node> {
+ return std::make_shared<ov::op::v0::Convert>(node, ov::element::f16);
+ };
+ auto reshape_to_2d = [](const ov::Output<ov::Node>& node) -> std::shared_ptr<ov::Node> {
+ auto shape = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {32, 1});
+ return std::make_shared<ov::op::v1::Reshape>(node, shape, false);
+ };
+ auto build = [&](const ov::Output<ov::Node>& param) -> std::shared_ptr<ov::Node> {
+ switch (topology) {
+ case ScaleZpTopology::ReshapeOfConvert:
+ return reshape_to_2d(to_f16(param));
+ case ScaleZpTopology::ConvertOfReshape:
+ return to_f16(reshape_to_2d(param));
+ default:
+ return to_f16(param);
+ }
+ };
+ // ConvertOnly supplies 2D parameters directly (no Reshape anywhere in the graph).
+ const ov::Shape param_shape = topology == ScaleZpTopology::ConvertOnly ? ov::Shape{32, 1} : ov::Shape{32, 1, 1};
+
+ {
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 16});
+ auto weights = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});
+ auto scale = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, param_shape);
+ ov::ParameterVector params{input, scale};
+ std::shared_ptr<ov::Node> dequantized = to_f16(weights);
+ if (with_zp) {
+ auto zp = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, param_shape);
+ params.push_back(zp);
+ dequantized = std::make_shared<ov::op::v1::Subtract>(dequantized, build(zp));
+ }
+ dequantized = std::make_shared<ov::op::v1::Multiply>(dequantized, build(scale));
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+ auto fc = std::make_shared<ov::intel_gpu::op::FullyConnected>(input, dequantized, no_bias, ov::element::f16, true);
+
+ model = std::make_shared<ov::Model>(ov::OutputVector{fc}, params);
+ manager.register_pass<ConvertFullyConnectedToFullyConnectedCompressed>();
+ }
+ {
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 16});
+ auto weights = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});
+ auto scale = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, param_shape);
+ ov::ParameterVector params{input, scale};
+ // The Convert(f32 -> f16) of a runtime scale must survive the rewrite in all topologies: either it is
+ // part of the matched mul_const_m node, or the Convert absorbed by mul_const_convert_m is re-used as is.
+ auto expected_scale = build(scale);
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+ std::shared_ptr<ov::Node> fc_compressed;
+ if (with_zp) {
+ auto zp = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, param_shape);
+ params.push_back(zp);
+ // The zero point reaches the FC as an integer value: its Convert is dropped and any Reshape over it
+ // is rebuilt over the Parameter, since FullyConnectedCompressed requires an integer zero point.
+ const auto expected_zp = topology == ScaleZpTopology::ConvertOnly ? std::static_pointer_cast<ov::Node>(zp) : reshape_to_2d(zp);
+ fc_compressed = std::make_shared<ov::intel_gpu::op::FullyConnectedCompressed>(input,
+ weights,
+ no_bias,
+ expected_scale,
+ expected_zp,
+ ov::element::f16,
+ true,
+ true,
+ true);
+ } else {
+ fc_compressed = std::make_shared<ov::intel_gpu::op::FullyConnectedCompressed>(input,
+ weights,
+ no_bias,
+ expected_scale,
+ ov::element::f16,
+ true,
+ true,
+ true);
+ }
+
+ model_ref = std::make_shared<ov::Model>(ov::OutputVector{fc_compressed}, params);
+ }
+}
+
+INSTANTIATE_TEST_SUITE_P(TransformationTests,
+ ConvertFCToCompressedParameterScaleZpTest,
+ testing::Values(ParameterScaleZpParams{ScaleZpTopology::ReshapeOfConvert, true},
+ ParameterScaleZpParams{ScaleZpTopology::ReshapeOfConvert, false},
+ ParameterScaleZpParams{ScaleZpTopology::ConvertOfReshape, true},
+ ParameterScaleZpParams{ScaleZpTopology::ConvertOfReshape, false},
+ ParameterScaleZpParams{ScaleZpTopology::ConvertOnly, true},
+ ParameterScaleZpParams{ScaleZpTopology::ConvertOnly, false}),
+ ConvertFCToCompressedParameterScaleZpTest::getTestCaseName);
+
+// f32 Parameter scale with a Convert, no zero point, followed by the post-reshape Multiply (mul2_m tail) whose
+// Constant is f16 after ConvertPrecision. The folded scale must keep the f16 precision of the graph: stripping
+// the Convert here used to throw NodeValidationFailure on the f32 x f16 Multiply.
+TEST_F(TransformationTestsF, ConvertFCToCompressedParameterScaleF32WithExtraMultiply) {
+ comparator.enable(FunctionsComparator::ATTRIBUTES);
+ {
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 64});
+ auto weights = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{8, 4, 16}, {1});
+ auto convert = std::make_shared<ov::op::v0::Convert>(weights, ov::element::f16);
+ auto scale = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{8, 4, 1});
+ auto scale_16 = std::make_shared<ov::op::v0::Convert>(scale, ov::element::f16);
+ auto mul = std::make_shared<ov::op::v1::Multiply>(convert, scale_16);
+ auto reshape_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {8, 64});
+ auto reshape = std::make_shared<ov::op::v1::Reshape>(mul, reshape_const, false);
+ auto mul2_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{8, 1}, {2});
+ auto extra_mul = std::make_shared<ov::op::v1::Multiply>(reshape, mul2_const);
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+ auto fc = std::make_shared<ov::intel_gpu::op::FullyConnected>(input, extra_mul, no_bias, ov::element::f16, true);
+
+ model = std::make_shared<ov::Model>(ov::OutputVector{fc}, ov::ParameterVector{input, scale});
+ manager.register_pass<ConvertFullyConnectedToFullyConnectedCompressed>();
+ }
+ {
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 64});
+ // The rank-3 Constant weights are folded to the FC weights shape by the pass.
+ auto weights = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{8, 64}, {1});
+ auto scale = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{8, 4, 1});
+ auto scale_16 = std::make_shared<ov::op::v0::Convert>(scale, ov::element::f16);
+ auto scale_shape = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {8, 4});
+ auto scale_reshaped = std::make_shared<ov::op::v1::Reshape>(scale_16, scale_shape, false);
+ auto mul2_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{8, 1}, {2});
+ auto scaled = std::make_shared<ov::op::v1::Multiply>(scale_reshaped, mul2_const);
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+ auto fc_compressed = std::make_shared<ov::intel_gpu::op::FullyConnectedCompressed>(input, weights, no_bias, scaled, ov::element::f16, true, true, true);
+
+ model_ref = std::make_shared<ov::Model>(ov::OutputVector{fc_compressed}, ov::ParameterVector{input, scale});
+ }
+}
+
+// Per-tensor (1-element) runtime scale/zp Parameters are not supported, so the pass must not fire.
+TEST_P(ConvertFCToCompressedParameterScaleZpTest, SkipsPerTensorParameterScaleAndZeroPoint) {
+ const auto& [topology, with_zp] = GetParam();
+ const bool reshape_of_convert = topology == ScaleZpTopology::ReshapeOfConvert;
+
+ auto to_f16 = [](const ov::Output<ov::Node>& node) -> std::shared_ptr<ov::Node> {
+ return std::make_shared<ov::op::v0::Convert>(node, ov::element::f16);
+ };
+ auto reshape_to_2d = [](const ov::Output<ov::Node>& node) -> std::shared_ptr<ov::Node> {
+ auto shape = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {1, 1});
+ return std::make_shared<ov::op::v1::Reshape>(node, shape, false);
+ };
+ auto build = [&](const ov::Output<ov::Node>& param) {
+ return reshape_of_convert ? reshape_to_2d(to_f16(param)) : to_f16(reshape_to_2d(param));
+ };
+
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 16});
+ auto weights = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});
+ auto scale = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::Shape{1, 1});
+ ov::ParameterVector params{input, scale};
+ std::shared_ptr<ov::Node> dequantized = to_f16(weights);
+ if (with_zp) {
+ auto zp = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, ov::Shape{1, 1});
+ params.push_back(zp);
+ dequantized = std::make_shared<ov::op::v1::Subtract>(dequantized, build(zp));
+ }
+ dequantized = std::make_shared<ov::op::v1::Multiply>(dequantized, build(scale));
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+ auto fc = std::make_shared<ov::intel_gpu::op::FullyConnected>(input, dequantized, no_bias, ov::element::f16, true);
+
+ model = std::make_shared<ov::Model>(ov::OutputVector{fc}, params);
+ model_ref = model->clone();
+ manager.register_pass<ConvertFullyConnectedToFullyConnectedCompressed>();
+}
+
+// Batch-1 weights [1, 32, 16] squeezed to [32, 16] by a Reshape, with ungrouped Parameter scale/zp [1, 32, 1].
+// MoveFCReshapeToWeights normalizes Constant forms only, so the pass must not read the leading unit batch
+// dimension of the runtime parameters as a group axis: scale/zp are flattened to [32, 1], weights to [32, 16].
+TEST_F(TransformationTestsF, ConvertFCToCompressedParameterScaleZpWithLeadingBatchDim) {
+ comparator.enable(FunctionsComparator::ATTRIBUTES);
+ {
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 16});
+ auto weights = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, ov::Shape{1, 32, 16});
+ auto convert = std::make_shared<ov::op::v0::Convert>(weights, ov::element::f16);
+ auto zp = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, ov::Shape{1, 32, 1});
+ auto zp_convert = std::make_shared<ov::op::v0::Convert>(zp, ov::element::f16);
+ auto sub = std::make_shared<ov::op::v1::Subtract>(convert, zp_convert);
+ auto scale = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::Shape{1, 32, 1});
+ auto mul = std::make_shared<ov::op::v1::Multiply>(sub, scale);
+ auto reshape_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {32, 16});
+ auto reshape = std::make_shared<ov::op::v1::Reshape>(mul, reshape_const, false);
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+ auto fc = std::make_shared<ov::intel_gpu::op::FullyConnected>(input, reshape, no_bias, ov::element::f16, true);
+
+ model = std::make_shared<ov::Model>(ov::OutputVector{fc}, ov::ParameterVector{input, weights, zp, scale});
+ manager.register_pass<ConvertFullyConnectedToFullyConnectedCompressed>();
+ }
+ {
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 16});
+ auto weights = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, ov::Shape{1, 32, 16});
+ auto zp = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, ov::Shape{1, 32, 1});
+ auto scale = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::Shape{1, 32, 1});
+ auto squeeze = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {32, 1});
+ auto zp_reshaped = std::make_shared<ov::op::v1::Reshape>(zp, squeeze, false);
+ auto scale_reshaped = std::make_shared<ov::op::v1::Reshape>(scale, squeeze, false);
+ auto weights_shape = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {32, 16});
+ auto weights_reshaped = std::make_shared<ov::op::v1::Reshape>(weights, weights_shape, false);
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+ auto fc_compressed = std::make_shared<ov::intel_gpu::op::FullyConnectedCompressed>(input,
+ weights_reshaped,
+ no_bias,
+ scale_reshaped,
+ zp_reshaped,
+ ov::element::f16,
+ true,
+ true,
+ true);
+
+ model_ref = std::make_shared<ov::Model>(ov::OutputVector{fc_compressed}, ov::ParameterVector{input, weights, zp, scale});
+ }
+}
+
+// ONNX-style Reshape(Convert(zp), [0, 1], special_zero = true): rebuilding the Reshape over the integer ZP
+// must preserve the special_zero flag, otherwise the rebuilt op interprets 0 as a literal zero dimension
+// and validation throws.
+TEST_F(TransformationTestsF, ConvertFCToCompressedParameterZpSpecialZeroReshape) {
+ comparator.enable(FunctionsComparator::ATTRIBUTES);
+ {
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 16});
+ auto weights = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});
+ auto zp = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, ov::Shape{32, 1, 1});
+ auto zp_convert = std::make_shared<ov::op::v0::Convert>(zp, ov::element::f16);
+ auto zp_shape = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {0, 1});
+ auto zp_reshape = std::make_shared<ov::op::v1::Reshape>(zp_convert, zp_shape, true);
+ auto sub = std::make_shared<ov::op::v1::Subtract>(std::make_shared<ov::op::v0::Convert>(weights, ov::element::f16), zp_reshape);
+ auto scale = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::Shape{32, 1});
+ auto mul = std::make_shared<ov::op::v1::Multiply>(sub, scale);
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+ auto fc = std::make_shared<ov::intel_gpu::op::FullyConnected>(input, mul, no_bias, ov::element::f16, true);
+
+ model = std::make_shared<ov::Model>(ov::OutputVector{fc}, ov::ParameterVector{input, zp, scale});
+ manager.register_pass<ConvertFullyConnectedToFullyConnectedCompressed>();
+ }
+ {
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 16});
+ auto weights = ov::op::v0::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});
+ auto zp = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, ov::Shape{32, 1, 1});
+ auto zp_shape = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {0, 1});
+ // The integer-source Reshape keeps the original special_zero = true.
+ auto zp_reshaped = std::make_shared<ov::op::v1::Reshape>(zp, zp_shape, true);
+ auto scale = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::Shape{32, 1});
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+ auto fc_compressed =
+ std::make_shared<ov::intel_gpu::op::FullyConnectedCompressed>(input, weights, no_bias, scale, zp_reshaped, ov::element::f16, true, true, true);
+
+ model_ref = std::make_shared<ov::Model>(ov::OutputVector{fc_compressed}, ov::ParameterVector{input, zp, scale});
+ }
+}
+
+// Grouped weights with a Parameter scale followed by the extra post-reshape Multiply (mul2_m tail).
+// w: Parameter u8 [8,4,16] → Convert f16 ─┐
+// scale: Parameter f16 [8,4,1] ──────────┴→ Multiply → Reshape [8,64] → Multiply(·, Constant [8,1]) → FullyConnected
+TEST_F(TransformationTestsF, ConvertFCToCompressedParameterWeightsAndScaleWithExtraMultiply) {
+ comparator.enable(FunctionsComparator::ATTRIBUTES);
+ {
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 64});
+ auto weights = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, ov::Shape{8, 4, 16});
+ auto convert = std::make_shared<ov::op::v0::Convert>(weights, ov::element::f16);
+ auto scale = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::Shape{8, 4, 1});
+ auto mul = std::make_shared<ov::op::v1::Multiply>(convert, scale);
+ auto reshape_const = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {8, 64});
+ auto reshape = std::make_shared<ov::op::v1::Reshape>(mul, reshape_const, false);
+ auto extra_mul_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{8, 1}, {2});
+ auto extra_mul = std::make_shared<ov::op::v1::Multiply>(reshape, extra_mul_const);
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+ auto fc = std::make_shared<ov::intel_gpu::op::FullyConnected>(input, extra_mul, no_bias, ov::element::f16, true);
+
+ model = std::make_shared<ov::Model>(ov::OutputVector{fc}, ov::ParameterVector{input, weights, scale});
+ manager.register_pass<ConvertFullyConnectedToFullyConnectedCompressed>();
+ }
+ {
+ auto input = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::PartialShape{-1, 64});
+ auto weights = std::make_shared<ov::op::v0::Parameter>(ov::element::u8, ov::Shape{8, 4, 16});
+ // Non-constant weights can't be folded; the [8,4,16] Parameter is reshaped to the FC weights shape [8,64].
+ auto weights_shape = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {8, 64});
+ auto weights_reshape = std::make_shared<ov::op::v1::Reshape>(weights, weights_shape, false);
+ auto scale = std::make_shared<ov::op::v0::Parameter>(ov::element::f16, ov::Shape{8, 4, 1});
+ auto scale_shape = ov::op::v0::Constant::create(ov::element::i32, ov::Shape{2}, {8, 4});
+ auto scale_reshape = std::make_shared<ov::op::v1::Reshape>(scale, scale_shape, false);
+ auto extra_mul_const = ov::op::v0::Constant::create(ov::element::f16, ov::Shape{8, 1}, {2});
+ auto scaled = std::make_shared<ov::op::v1::Multiply>(scale_reshape, extra_mul_const);
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+ auto fc_compressed = std::make_shared<ov::intel_gpu::op::FullyConnectedCompressed>(input,
+ weights_reshape,
+ no_bias,
+ scaled,
+ ov::element::f16,
+ true,
+ true,
+ true);
+
+ model_ref = std::make_shared<ov::Model>(ov::OutputVector{fc_compressed}, ov::ParameterVector{input, weights, scale});
+ }
+}
+
TEST_F(TransformationTestsF, ConvertFCToCompressed3) {
{
auto input1 = std::make_shared<ov::op::v0::Parameter>(ov::element::f32, ov::PartialShape{ -1, 16 });
diff --git a/src/plugins/intel_gpu/tests/unit/transformations/convert_matmul_to_fc_test.cpp b/src/plugins/intel_gpu/tests/unit/transformations/convert_matmul_to_fc_test.cpp
index 76c6cba66ae..27a9edcefec 100644
--- a/src/plugins/intel_gpu/tests/unit/transformations/convert_matmul_to_fc_test.cpp
+++ b/src/plugins/intel_gpu/tests/unit/transformations/convert_matmul_to_fc_test.cpp
@@ -636,6 +636,132 @@ TEST_F(TransformationTestsF, ConvertMatMulToFullyConnectedTest_compressed_u4_wei
}
}
+TEST_F(TransformationTestsF, ConvertMatMulToFullyConnectedTest_compressed_u8_weights_static_scale_zp_parameters) {
+ {
+ auto data = std::make_shared<ov::opset1::Parameter>(ov::element::f16, ov::PartialShape{-1, 16});
+ auto weights = ov::opset1::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});
+ auto convert = std::make_shared<ov::opset1::Convert>(weights, ov::element::f16);
+ auto zp = std::make_shared<ov::opset1::Parameter>(ov::element::u8, ov::Shape{32, 1});
+ auto zp_convert = std::make_shared<ov::opset1::Convert>(zp, ov::element::f16);
+ auto sub = std::make_shared<ov::opset1::Subtract>(convert, zp_convert);
+ auto scale = std::make_shared<ov::opset1::Parameter>(ov::element::f16, ov::Shape{32, 1});
+ auto mul = std::make_shared<ov::opset1::Multiply>(sub, scale);
+ auto matmul = std::make_shared<ov::opset1::MatMul>(data, mul, false, true);
+
+ model = std::make_shared<ov::Model>(ov::OutputVector{matmul}, ov::ParameterVector{data, zp, scale});
+ manager.register_pass<ConvertMatMulToFullyConnected>(true);
+ manager.register_pass<ConvertFullyConnectedToFullyConnectedCompressed>();
+ }
+ {
+ auto data = std::make_shared<ov::opset1::Parameter>(ov::element::f16, ov::PartialShape{-1, 16});
+ auto weights = ov::opset1::Constant::create(ov::element::u8, ov::Shape{32, 16}, {1});
+ auto zp = std::make_shared<ov::opset1::Parameter>(ov::element::u8, ov::Shape{32, 1});
+ auto scale = std::make_shared<ov::opset1::Parameter>(ov::element::f16, ov::Shape{32, 1});
+ auto no_bias = std::make_shared<ov::intel_gpu::op::Placeholder>();
+ auto fc_compressed = std::make_shared<ov::intel_gpu::op::FullyConnectedCompressed>(data,
+ weights,
+ no_bias,
+ scale,
+ zp,
+ ov::element::f16,
+ true,
+ true,
+ true);
+
+ model_ref = std::make_shared<ov::Model>(ov::OutputVector{fc_compressed}, ov::ParameterVector{data, zp, scale});
+ }
+ comparator.enable(FunctionsComparator::ATTRIBUTES);
+}
+
+enum class DynamicScaleZpInput { Scale, ZeroPoint };
+enum class DynamicScaleZpSource { Parameter, ReshapeOfConvert, ConvertOfReshape };
+
+struct DynamicScaleZpParams {
+ DynamicScaleZpInput input;
+ DynamicScaleZpSource source;
+};
+
+class ConvertMatMulToFullyConnectedDynamicScaleZpTest : public testing::WithParamInterface<DynamicScaleZpParams>,
+ public TransformationTestsF {
+public:
+ ConvertMatMulToFullyConnectedDynamicScaleZpTest() : TransformationTestsF() {
+ comparator.enable(FunctionsComparator::ATTRIBUTES);
+ }
+
+ static std::string getTestCaseName(const testing::TestParamInfo<DynamicScaleZpParams>& info) {
+ const auto& [input, source] = info.param;
+ std::string name = input == DynamicScaleZpInput::Scale ? "Scale" : "ZeroPoint";
+ switch (source) {
+ case DynamicScaleZpSource::Parameter:
+ return name + "_DynamicParameter";
+ case DynamicScaleZpSource::ReshapeOfConvert:
+ return name + "_ReshapeOfConvert_DynamicTarget";
+ case DynamicScaleZpSource::ConvertOfReshape:
+ return name + "_ConvertOfReshape_DynamicTarget";
+ }
+ return name;
+ }
+};
+
+// The scale or zero point has a dynamic shape, either as a dynamic Parameter [?, 1] or as a static Parameter reshaped to a
+// non-constant target shape. It broadcasts the decompressed weights to a dynamic shape, which FullyConnected can't take,
+// so the MatMul must be left unchanged instead of failing on shape_b.is_static() in ConvertMatMulToFullyConnected.
+TEST_P(ConvertMatMulToFullyConnectedDynamicScaleZpTest, KeepsMatMul) {
+ const auto& [input_kind, source] = GetParam();
+ const bool is_scale = input_kind == DynamicScaleZpInput::Scale;
+
+ auto data = std::make_shared<ov::opset1::Parameter>(ov::element::f16, ov::PartialShape{-1, 16});
+ auto weights = ov::opset1::Constant::create(ov::element::u8, ov::Shape{1, 16}, {1});
+ std::shared_ptr<ov::Node> dequantized = std::make_shared<ov::opset1::Convert>(weights, ov::element::f16);
+ ov::ParameterVector params{data};
+
+ const auto param_type = is_scale ? ov::element::f32 : ov::element::u8;
+ std::shared_ptr<ov::Node> value;
+ if (source == DynamicScaleZpSource::Parameter) {
+ auto param = std::make_shared<ov::opset1::Parameter>(param_type, ov::PartialShape{-1, 1});
+ params.push_back(param);
+ value = std::make_shared<ov::opset1::Convert>(param, ov::element::f16);
+ } else {
+ auto param = std::make_shared<ov::opset1::Parameter>(param_type, ov::Shape{1, 1, 1});
+ auto target_shape = std::make_shared<ov::opset1::Parameter>(ov::element::i32, ov::Shape{2});
+ params.push_back(param);
+ params.push_back(target_shape);
+ if (source == DynamicScaleZpSource::ReshapeOfConvert) {
+ auto convert = std::make_shared<ov::opset1::Convert>(param, ov::element::f16);
+ value = std::make_shared<ov::opset1::Reshape>(convert, target_shape, false);
+ } else {
+ auto reshape = std::make_shared<ov::opset1::Reshape>(param, target_shape, false);
+ value = std::make_shared<ov::opset1::Convert>(reshape, ov::element::f16);
+ }
+ }
+
+ if (is_scale) {
+ dequantized = std::make_shared<ov::opset1::Multiply>(dequantized, value);
+ } else {
+ dequantized = std::make_shared<ov::opset1::Subtract>(dequantized, value);
+ auto scale = ov::opset1::Constant::create(ov::element::f16, ov::Shape{1, 1}, {1});
+ dequantized = std::make_shared<ov::opset1::Multiply>(dequantized, scale);
+ }
+ ASSERT_TRUE(dequantized->get_output_partial_shape(0).is_dynamic());
+ auto matmul = std::make_shared<ov::opset1::MatMul>(data, dequantized, false, true);
+
+ // No model_ref: the model is expected to be unchanged.
+ model = std::make_shared<ov::Model>(ov::OutputVector{matmul}, params);
+ manager.register_pass<ConvertMatMulToFullyConnected>(true);
+ manager.register_pass<ConvertFullyConnectedToFullyConnectedCompressed>();
+}
+
+INSTANTIATE_TEST_SUITE_P(
+ TransformationTests,
+ ConvertMatMulToFullyConnectedDynamicScaleZpTest,
+ testing::Values(DynamicScaleZpParams{DynamicScaleZpInput::Scale, DynamicScaleZpSource::Parameter},
+ DynamicScaleZpParams{DynamicScaleZpInput::Scale, DynamicScaleZpSource::ReshapeOfConvert},
+ DynamicScaleZpParams{DynamicScaleZpInput::Scale, DynamicScaleZpSource::ConvertOfReshape},
+ DynamicScaleZpParams{DynamicScaleZpInput::ZeroPoint, DynamicScaleZpSource::Parameter},
+ DynamicScaleZpParams{DynamicScaleZpInput::ZeroPoint, DynamicScaleZpSource::ReshapeOfConvert},
+ DynamicScaleZpParams{DynamicScaleZpInput::ZeroPoint, DynamicScaleZpSource::ConvertOfReshape}),
+ ConvertMatMulToFullyConnectedDynamicScaleZpTest::getTestCaseName);
+
// Checked blocked cases
TEST(TransformationTests, ConvertMatMulToFullyConnectedExceptionTest_sibling_matmul_no_convert) {
auto CreateMatMul = [&](bool mat1_transpose_a, bool mat1_transpose_b,