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
[NPUW] Fix unit test compilation issue (#35482)
Ding Zhang5f343ea600e0
diff --git a/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/kv_cache_compressed.cpp b/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/kv_cache_compressed.cppindex f841ec0ff84..9bd57d0d04f 100644--- a/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/kv_cache_compressed.cpp+++ b/src/plugins/intel_npu/src/plugin/npuw/npuw_transformations/kv_cache_compressed.cpp@@ -100,7 +100,8 @@ ov::OutputVector dynamic_quantize_linear(std::shared_ptr<ov::Node> input, size_tov::OutputVector dynamic_quantize_linear_v3(const ov::Output<ov::Node>& input,size_t reduction_axis,- const std::string& name_prefix) {+ const std::string& name_prefix,+ const ov::npuw::util::DynamicQuantStorageTypes& storage_types) {auto make_name = [&name_prefix](const std::string& suffix) {return name_prefix + "/" + suffix;};@@ -131,13 +132,11 @@ ov::OutputVector dynamic_quantize_linear_v3(const ov::Output<ov::Node>& input,auto multiplyInput = std::make_shared<ov::op::v1::Multiply>(input, cst_255);multiplyInput->set_friendly_name(make_name("Multiply_input_255"));- // ONNX spec: zp = qmin - (minClamped / scale)- auto cst_qmin = ov::op::v0::Constant::create(ov::element::f32, ov::Shape{1}, {-128.0f});- auto minDivScale = std::make_shared<ov::op::v1::Divide>(minClamped, multiplyScale);- minDivScale->set_friendly_name(make_name("Divide_min_by_scale"));+ auto minNegated = std::make_shared<ov::op::v1::Subtract>(cst_zero, minClamped);+ minNegated->set_friendly_name(make_name("Negate_min"));- auto zpFloat = std::make_shared<ov::op::v1::Subtract>(cst_qmin, minDivScale);- zpFloat->set_friendly_name(make_name("Subtract_zp"));+ auto zpFloat = std::make_shared<ov::op::v1::Divide>(minNegated, multiplyScale);+ zpFloat->set_friendly_name(make_name("Divide_min_by_scale"));auto divideSpan = std::make_shared<ov::op::v1::Divide>(multiplyInput, subtractSpan);divideSpan->set_friendly_name(make_name("Divide_span"));@@ -148,22 +147,29 @@ ov::OutputVector dynamic_quantize_linear_v3(const ov::Output<ov::Node>& input,auto roundSpan = std::make_shared<ov::op::v5::Round>(divideSpan, ov::op::v5::Round::RoundMode::HALF_TO_EVEN);roundSpan->set_friendly_name(make_name("Round_span"));- auto clampZp = std::make_shared<ov::op::v0::Clamp>(roundZp, -128.0, 127.0);+ auto clampZp = std::make_shared<ov::op::v0::Clamp>(roundZp, 0.0, 255.0);clampZp->set_friendly_name(make_name("Clamp_zp"));auto addQuant = std::make_shared<ov::op::v1::Add>(roundSpan, clampZp);addQuant->set_friendly_name(make_name("Add_quant"));- auto clampOutput = std::make_shared<ov::op::v0::Clamp>(addQuant, -128.0, 127.0);+ auto clampOutput = std::make_shared<ov::op::v0::Clamp>(addQuant, 0.0, 255.0);clampOutput->set_friendly_name(make_name("Clamp_output"));- auto convertZp = std::make_shared<ov::op::v0::Convert>(clampZp, ov::element::i8);+ auto convertZp = std::make_shared<ov::op::v0::Convert>(clampZp, storage_types.zero_point_type);convertZp->set_friendly_name(make_name("Convert_zp"));- auto convertOutput = std::make_shared<ov::op::v0::Convert>(clampOutput, ov::element::i8);+ auto convertOutput = std::make_shared<ov::op::v0::Convert>(clampOutput, storage_types.quantized_data_type);convertOutput->set_friendly_name(make_name("Convert_output"));- return {convertOutput->output(0), multiplyScale->output(0), convertZp->output(0)};+ std::shared_ptr<ov::Node> scaleOutput = multiplyScale;+ if (storage_types.scale_type != ov::element::f32) {+ auto convertScale = std::make_shared<ov::op::v0::Convert>(multiplyScale, storage_types.scale_type);+ convertScale->set_friendly_name(make_name("Convert_scale"));+ scaleOutput = convertScale;+ }++ return {convertOutput->output(0), scaleOutput->output(0), convertZp->output(0)};}} // anonymous namespace@@ -218,6 +224,18 @@ ov::npuw::DecomposeDynamicQuantize3::DecomposeDynamicQuantize3() {auto dq_ptr = node_to_output.at(dynamic_quantize).get_node_shared_ptr();auto dq_node = ov::as_type_ptr<ov::op::internal::DynamicQuantize>(dq_ptr);+ const auto& attrs = dq_node->get_attrs();++ if (attrs.quantization_type != ov::op::internal::DynamicQuantize::QuantizationType::Asymmetric ||+ attrs.quantization_dt != ov::element::i8) {+ return false;+ }++ const auto storage_types = ov::npuw::util::resolve_dynamic_quant_storage_types(+ ov::npuw::util::DynamicQuantDecomposeMode::CompilerPatternI8,+ false,+ attrs.quantization_dt,+ attrs.scale_dt);LOG_DEBUG("Found DynamicQuantize : " << dq_ptr->get_friendly_name() << " decomposing");LOG_BLOCK();@@ -230,7 +248,8 @@ ov::npuw::DecomposeDynamicQuantize3::DecomposeDynamicQuantize3() {auto dq_input = dq_ptr->input_value(0);auto has_zp = dq_ptr->outputs().size() == 3;- auto dq_results = dynamic_quantize_linear_v3(dq_input, reduction_axis, dq_ptr->get_friendly_name());+ auto dq_results =+ dynamic_quantize_linear_v3(dq_input, reduction_axis, dq_ptr->get_friendly_name(), storage_types);dq_ptr->output(0).replace(dq_results[0]);dq_ptr->output(1).replace(dq_results[1]);@@ -437,8 +456,11 @@ void ov::npuw::run_kv_cache_dynamic_quantization_passes(const std::shared_ptr<ovbool is_key,const KVCacheCompressionConfig& cfg) -> std::shared_ptr<ov::op::internal::DynamicQuantize> {const std::string kv_name = cacheName(is_key);-const bool is_asym = cfg.quantization_type == KVCacheCompressionConfig::QuantizationType::Asymmetric;+ const auto storage_types = ov::npuw::util::resolve_dynamic_quant_storage_types(+ ov::npuw::util::DynamicQuantDecomposeMode::HandcraftedSymmetricI8,+ !is_asym,+ cfg.quantization_dt);auto rank = dq_input.get_partial_shape().size();std::vector<uint64_t> shape_group_size(rank, 1);@@ -452,7 +474,7 @@ void ov::npuw::run_kv_cache_dynamic_quantization_passes(const std::shared_ptr<ovdq_config.group_sizes = shape_group_size;if (is_asym) {- dq_config.zp_dt = cfg.quantization_dt; // zp same type as quantized data+ dq_config.zp_dt = storage_types.zero_point_type;}auto kv_dyn_quant = std::make_shared<ov::op::internal::DynamicQuantize>(dq_input, dq_config);@@ -477,6 +499,11 @@ void ov::npuw::run_kv_cache_dynamic_quantization_passes(const std::shared_ptr<ovbool isKey,const KVCacheCompressionConfig& cfg) {const std::string node_name = isKey ? g_key_cache_name : g_value_cache_name;+ const bool is_asym = cfg.quantization_type == KVCacheCompressionConfig::QuantizationType::Asymmetric;+ const auto storage_types = ov::npuw::util::resolve_dynamic_quant_storage_types(+ ov::npuw::util::DynamicQuantDecomposeMode::HandcraftedSymmetricI8,+ !is_asym,+ cfg.quantization_dt);// TODO: adding back slash here kills partitioning - fix thatauto make_dq_name = [&make_name, &node_name](auto base_name) {@@ -500,9 +527,9 @@ void ov::npuw::run_kv_cache_dynamic_quantization_passes(const std::shared_ptr<ov// reconstruct k and v caches intgeres values to matmul using one of Dequantize approach// use zp on quant/dequant only in case od assymstd::shared_ptr<ov::Node> fp_subtracted_zp = start_node;- if (cfg.quantization_type == KVCacheCompressionConfig::QuantizationType::Asymmetric) {+ if (is_asym) {// Subtract zero-point - TODO: share this memory with DynamicQuantize/read/assign?- auto zp = create_parameter_with_name(cfg.quantization_dt,+ auto zp = create_parameter_with_name(storage_types.zero_point_type,clear_embedding_index(start_node, isKey),make_dq_param_name("zp"));diff --git a/src/plugins/intel_npu/src/plugin/npuw/util.cpp b/src/plugins/intel_npu/src/plugin/npuw/util.cppindex 64a2e81a4ed..07a2f38a957 100644--- a/src/plugins/intel_npu/src/plugin/npuw/util.cpp+++ b/src/plugins/intel_npu/src/plugin/npuw/util.cpp@@ -59,6 +59,25 @@ bool ov::npuw::util::is_set(const std::size_t sub_idx,return false;}+ov::npuw::util::DynamicQuantStorageTypes ov::npuw::util::resolve_dynamic_quant_storage_types(+ DynamicQuantDecomposeMode decompose_mode,+ bool is_symmetric,+ const ov::element::Type& quant_dt,+ const ov::element::Type& scale_dt) {+ DynamicQuantStorageTypes resolved;+ resolved.quantized_data_type = quant_dt;+ resolved.zero_point_type = is_symmetric ? ov::element::dynamic : quant_dt;+ resolved.scale_type = scale_dt;++ if (!is_symmetric && decompose_mode == DynamicQuantDecomposeMode::CompilerPatternI8 &&+ quant_dt == ov::element::i8) {+ resolved.quantized_data_type = ov::element::u8;+ resolved.zero_point_type = ov::element::u8;+ }++ return resolved;+}+namespace {inline uint8_t hi4(uint8_t x) {return x >> 4;diff --git a/src/plugins/intel_npu/src/plugin/npuw/util.hpp b/src/plugins/intel_npu/src/plugin/npuw/util.hppindex 8907b1358fb..2d5073a9c0e 100644--- a/src/plugins/intel_npu/src/plugin/npuw/util.hpp+++ b/src/plugins/intel_npu/src/plugin/npuw/util.hpp@@ -37,6 +37,31 @@ bool starts_with(const std::string& str, const std::string& prefix);std::string fmt(std::size_t number, std::size_t total);+// Matches the three DynamicQuantize decomposition implementations declared in+// kv_cache_compressed.hpp.+enum class DynamicQuantDecomposeMode {+ // V1: handcrafted symmetric-style path, i8 range [-127, 127].+ HandcraftedSymmetricI8 = 1,++ // V2: ONNX DynamicQuantizeLinear-style path, u8 range [0, 255].+ OnnxDynamicQuantizeLinear = 2,++ // V3: compiler pattern-style path. i8 requests are materialized as u8+ // storage for the asymmetric decomposition branch.+ CompilerPatternI8 = 3,+};++struct DynamicQuantStorageTypes {+ ov::element::Type quantized_data_type = ov::element::dynamic;+ ov::element::Type zero_point_type = ov::element::dynamic;+ ov::element::Type scale_type = ov::element::f32;+};++DynamicQuantStorageTypes resolve_dynamic_quant_storage_types(DynamicQuantDecomposeMode decompose_mode,+ bool is_symmetric,+ const ov::element::Type& quant_dt,+ const ov::element::Type& scale_dt = ov::element::f32);+struct UnpackOptions {bool bUseOvParallelFor;size_t nPartitions; // if 0 we use 64 elements step in parallel for, otherwise target workload is dynamicallydiff --git a/src/plugins/intel_npu/tests/unit/CMakeLists.txt b/src/plugins/intel_npu/tests/unit/CMakeLists.txtindex 72a1a63381c..1ac668537c0 100644--- a/src/plugins/intel_npu/tests/unit/CMakeLists.txt+++ b/src/plugins/intel_npu/tests/unit/CMakeLists.txt@@ -137,6 +137,7 @@ target_sources(${TARGET_NAME} PRIVATE${CMAKE_CURRENT_SOURCE_DIR}/npuw/lincache_utils_test.cpp${CMAKE_CURRENT_SOURCE_DIR}/npuw/partitioning_options_test.cpp${CMAKE_CURRENT_SOURCE_DIR}/npuw/npuw_options_smoke_test.cpp+ ${CMAKE_CURRENT_SOURCE_DIR}/npuw/resolve_dynamic_quant_storage_types_test.cpp${CMAKE_CURRENT_SOURCE_DIR}/npuw/orc.cpp${CMAKE_CURRENT_SOURCE_DIR}/npuw/sdpa_pattern_nodes_test.cpp${CMAKE_CURRENT_SOURCE_DIR}/npuw/subgraph_pipeline.cppdiff --git a/src/plugins/intel_npu/tests/unit/npuw/dynamic_quantize_accuracy_test.cpp b/src/plugins/intel_npu/tests/unit/npuw/dynamic_quantize_accuracy_test.cppindex 8df3e8de40c..d5c9bcdb220 100644--- a/src/plugins/intel_npu/tests/unit/npuw/dynamic_quantize_accuracy_test.cpp+++ b/src/plugins/intel_npu/tests/unit/npuw/dynamic_quantize_accuracy_test.cpp@@ -14,7 +14,7 @@// Parameter(f16) -> Convert(f32) -> DynamicQuantize -> [q, scale, zp] Results//// 2. Dequantize model (applied when reading cached tokens for attention):-// Parameters(q_i8, scale_f32, zp_i8) -> dequant chain -> Result(f16)+// Parameters(q_storage, scale_f32, zp_storage) -> dequant chain -> Result(f16)//// Test cases:// RoundtripAccuracy - single fused roundtrip model via evaluate()@@ -53,10 +53,12 @@#include "openvino/pass/manager.hpp"#include "openvino/runtime/intel_npu/properties.hpp"#include "ov_ops/dynamic_quantize.hpp"+#include "util.hpp"namespace {using namespace ov;+using DQMode = ov::npuw::util::DynamicQuantDecomposeMode;// ============================================================================// Accuracy metrics@@ -79,7 +81,8 @@ AccuracyMetrics compute_metrics(const float* original, const float* reconstructesum_sq_err += diff * diff;double abs_diff = std::abs(diff);sum_abs_err += abs_diff;- if (abs_diff > max_abs) max_abs = abs_diff;+ if (abs_diff > max_abs)+ max_abs = abs_diff;sum_sq_orig += static_cast<double>(original[i]) * static_cast<double>(original[i]);}@@ -97,7 +100,7 @@ AccuracyMetrics compute_metrics(const float* original, const float* reconstructeenum class DistributionKind { Uniform, GenGaussian };struct DQTestParams {- int decompose_version;+ DQMode decompose_mode;Shape shape;unsigned seed;DistributionKind dist_kind;@@ -107,16 +110,20 @@ struct DQTestParams {float ggd_alpha;float ggd_beta;// Quantization config overrides.- // quant_dt == element::dynamic → infer from decompose_version (u8 for v2, i8 otherwise)- element::Type quant_dt = element::dynamic;- bool is_symmetric = false; // true = symmetric (no ZP, 2 DQ outputs)- double threshold = 0.02; // rel-L2 pass threshold+ // quant_dt == element::dynamic → infer from decompose mode (u8 for v2, i8 otherwise)+ element::Type quant_dt = element::dynamic;+ bool is_symmetric = false; // true = symmetric (no ZP, 2 DQ outputs)+ double threshold = 0.02; // rel-L2 pass threshold};+static int decompose_version(const DQTestParams& p) {+ return static_cast<int>(p.decompose_mode);+}+static element::Type resolve_quant_dt(const DQTestParams& p) {return (p.quant_dt != element::dynamic)? p.quant_dt- : (p.decompose_version == 2 ? element::u8 : element::i8);+ : (p.decompose_mode == DQMode::OnnxDynamicQuantizeLinear ? element::u8 : element::i8);}static std::string dist_to_token(DistributionKind kind) {@@ -164,17 +171,14 @@ static std::string sanitize_gtest_name(std::string name) {static std::string make_test_case_name(const DQTestParams& p) {std::ostringstream os;- os << "V" << p.decompose_version- << "_" << dist_to_token(p.dist_kind)- << "_" << (p.is_symmetric ? "Sym" : "Asym")- << "_" << type_to_token(resolve_quant_dt(p));+ os << "V" << decompose_version(p) << "_" << dist_to_token(p.dist_kind) << "_"+ << (p.is_symmetric ? "Sym" : "Asym") << "_" << type_to_token(resolve_quant_dt(p));if (p.dist_kind == DistributionKind::Uniform) {os << "_R" << float_to_token(p.uniform_min) << "_" << float_to_token(p.uniform_max);} else {- os << "_Mu" << float_to_token(p.ggd_mu)- << "_A" << float_to_token(p.ggd_alpha)- << "_B" << float_to_token(p.ggd_beta);+ os << "_Mu" << float_to_token(p.ggd_mu) << "_A" << float_to_token(p.ggd_alpha) << "_B"+ << float_to_token(p.ggd_beta);}os << "_S";@@ -192,46 +196,44 @@ std::ostream& operator<<(std::ostream& os, const DQTestParams& p) {return os << make_test_case_name(p);}-// ============================================================================// Shared helpers for DQ config and decompose pass// ============================================================================-op::internal::DynamicQuantize::Attributes make_dq_config(const Shape& shape,- const DQTestParams& p) {+op::internal::DynamicQuantize::Attributes make_dq_config(const Shape& shape, const DQTestParams& p) {using QT = op::internal::DynamicQuantize::QuantizationType;// Resolve effective quantization dtype: explicit override beats version default.const element::Type quant_dt = resolve_quant_dt(p);op::internal::DynamicQuantize::Attributes config;- config.scale_dt = element::f32;+ config.scale_dt = element::f32;config.quantization_dt = quant_dt;config.group_sizes = std::vector<uint64_t>(shape.size(), 1);if (p.is_symmetric) {config.quantization_type = QT::Symmetric;- config.zp_dt = element::dynamic; // no zero-point+ config.zp_dt = element::dynamic; // no zero-point} else {config.quantization_type = QT::Asymmetric;- config.zp_dt = quant_dt;+ config.zp_dt = quant_dt;}return config;}-void run_decompose_pass(const std::shared_ptr<Model>& model, int decompose_version) {+void run_decompose_pass(const std::shared_ptr<Model>& model, DQMode decompose_mode) {pass::Manager manager("decompose_dq");- switch (decompose_version) {- case 1:+ switch (decompose_mode) {+ case DQMode::HandcraftedSymmetricI8:manager.register_pass<ov::npuw::DecomposeDynamicQuantize>();break;- case 2:+ case DQMode::OnnxDynamicQuantizeLinear:manager.register_pass<ov::npuw::DecomposeDynamicQuantize2>();break;- case 3:+ case DQMode::CompilerPatternI8:manager.register_pass<ov::npuw::DecomposeDynamicQuantize3>();break;default:- OPENVINO_THROW("Unknown decompose version: ", decompose_version);+ OPENVINO_THROW("Unknown decompose mode: ", static_cast<int>(decompose_mode));}manager.run_passes(model);model->validate_nodes_and_infer_types();@@ -244,8 +246,7 @@ void run_decompose_pass(const std::shared_ptr<Model>& model, int decompose_versi// The DynamicQuantize node is named with "key" so the decomposition pass// selects reduction_axis=3 (the key-cache embedding dimension).// ============================================================================-std::shared_ptr<Model> build_roundtrip_model(const Shape& shape,- const DQTestParams& p) {+std::shared_ptr<Model> build_roundtrip_model(const Shape& shape, const DQTestParams& p) {auto input = std::make_shared<op::v0::Parameter>(element::f16, shape);input->set_friendly_name("input");@@ -276,13 +277,12 @@ std::shared_ptr<Model> build_roundtrip_model(const Shape& shape,auto result = std::make_shared<op::v0::Result>(output_cvt);result->set_friendly_name("result_reconstructed");- auto model = std::make_shared<Model>(- ResultVector{result},- ParameterVector{input},- "roundtrip_fp16_v" + std::to_string(p.decompose_version));+ auto model = std::make_shared<Model>(ResultVector{result},+ ParameterVector{input},+ "roundtrip_fp16_v" + std::to_string(decompose_version(p)));model->validate_nodes_and_infer_types();- run_decompose_pass(model, p.decompose_version);+ run_decompose_pass(model, p.decompose_mode);return model;}@@ -294,8 +294,7 @@ std::shared_ptr<Model> build_roundtrip_model(const Shape& shape,// failure here (which has been observed) would go unnoticed with a single// fused roundtrip model.// ============================================================================-std::shared_ptr<Model> build_quantize_model(const Shape& shape,- const DQTestParams& p) {+std::shared_ptr<Model> build_quantize_model(const Shape& shape, const DQTestParams& p) {auto input = std::make_shared<op::v0::Parameter>(element::f16, shape);input->set_friendly_name("input");@@ -320,29 +319,29 @@ std::shared_ptr<Model> build_quantize_model(const Shape& shape,results.push_back(result_zp);}- auto model = std::make_shared<Model>(- results,- ParameterVector{input},- "quantize_fp16_v" + std::to_string(p.decompose_version));+ auto model = std::make_shared<Model>(results,+ ParameterVector{input},+ "quantize_fp16_v" + std::to_string(decompose_version(p)));model->validate_nodes_and_infer_types();- run_decompose_pass(model, p.decompose_version);+ run_decompose_pass(model, p.decompose_mode);return model;}// ============================================================================// Build a dequantize-only model (matches the real "read cached tokens" path):-// Parameters(q, scale, zp) -> (convert(q,f32) - convert(zp,f32)) * scale+// Parameters(q_storage, scale, zp_storage) -> (convert(q,f32) - convert(zp,f32)) * scale// -> Convert(f16) -> Result//// This mirrors create_dequant_nodes() in the production code.// No decompose pass needed -- the dequant chain is plain arithmetic.// ============================================================================-std::shared_ptr<Model> build_dequantize_model(const Shape& shape,- const DQTestParams& p) {- auto config = make_dq_config(shape, p);+std::shared_ptr<Model> build_dequantize_model(const Shape& shape, const DQTestParams& p) {+ const auto storage_types = ov::npuw::util::resolve_dynamic_quant_storage_types(p.decompose_mode,+ p.is_symmetric,+ resolve_quant_dt(p));- auto param_q = std::make_shared<op::v0::Parameter>(config.quantization_dt, shape);+ auto param_q = std::make_shared<op::v0::Parameter>(storage_types.quantized_data_type, shape);param_q->set_friendly_name("quantized_data");// Scale/ZP shape: same as data but with embedding dim (last) collapsed to 1@@ -364,7 +363,7 @@ std::shared_ptr<Model> build_dequantize_model(const Shape& shape,if (p.is_symmetric) {dequant_input = q_f32;} else {- auto param_zp = std::make_shared<op::v0::Parameter>(config.zp_dt, scale_shape);+ auto param_zp = std::make_shared<op::v0::Parameter>(storage_types.zero_point_type, scale_shape);param_zp->set_friendly_name("zero_point");params.push_back(param_zp);@@ -384,10 +383,9 @@ std::shared_ptr<Model> build_dequantize_model(const Shape& shape,auto result = std::make_shared<op::v0::Result>(output_cvt);result->set_friendly_name("result_dequantized");- auto model = std::make_shared<Model>(- ResultVector{result},- params,- "dequantize_fp16_v" + std::to_string(p.decompose_version));+ auto model = std::make_shared<Model>(ResultVector{result},+ params,+ "dequantize_fp16_v" + std::to_string(decompose_version(p)));model->validate_nodes_and_infer_types();return model;@@ -431,9 +429,7 @@ std::vector<float> generate_gen_gaussian_data(size_t count, float mu, float alph// ============================================================================// Helper: evaluate a roundtrip model via the reference interpreter.// ============================================================================-AccuracyMetrics evaluate_roundtrip(const std::shared_ptr<Model>& model,- const float* input_data,- size_t element_count) {+AccuracyMetrics evaluate_roundtrip(const std::shared_ptr<Model>& model, const float* input_data, size_t element_count) {auto input_tensor = Tensor(element::f16, model->get_parameters()[0]->get_shape());auto* dst = input_tensor.data<ov::float16>();for (size_t i = 0; i < element_count; ++i) {@@ -530,7 +526,7 @@ AccuracyMetrics evaluate_split_roundtrip_on_device(const std::shared_ptr<Model>&quant_request.set_input_tensor(quant_input);quant_request.infer();- auto tensor_q = quant_request.get_output_tensor(0);+ auto tensor_q = quant_request.get_output_tensor(0);auto tensor_scale = quant_request.get_output_tensor(1);// Step 2: compile and run dequantize model@@ -558,7 +554,6 @@ AccuracyMetrics evaluate_split_roundtrip_on_device(const std::shared_ptr<Model>&return compute_metrics(input_data, output_f32.data(), element_count);}-// ============================================================================// Helper: get the target device from the environment, empty if not set// ============================================================================@@ -567,7 +562,6 @@ std::string get_test_device() {return env ? std::string(env) : std::string{};}-// ============================================================================// Parameterized test fixture// ============================================================================@@ -575,9 +569,7 @@ class DynamicQuantizeAccuracyTest : public ::testing::TestWithParam<DQTestParamsprotected:static std::string format_metrics(const AccuracyMetrics& m) {std::ostringstream os;- os << "L2=" << m.l2_norm- << ", relL2=" << m.rel_l2_norm- << ", maxAbs=" << m.max_abs_error+ os << "L2=" << m.l2_norm << ", relL2=" << m.rel_l2_norm << ", maxAbs=" << m.max_abs_error<< ", meanAbs=" << m.mean_abs_error;return os.str();}@@ -650,8 +642,7 @@ TEST_P(DynamicQuantizeAccuracyTest, RoundtripAccuracy) {auto metrics = evaluate_roundtrip(model, data.data(), element_count);SCOPED_TRACE("roundtrip metrics: " + format_metrics(metrics));- EXPECT_LT(metrics.rel_l2_norm, p.threshold)- << "V" << p.decompose_version << " relative L2 too high";+ EXPECT_LT(metrics.rel_l2_norm, p.threshold) << "V" << decompose_version(p) << " relative L2 too high";}// -- Reference interpreter test -- split quantize + dequantize models ---------@@ -662,12 +653,11 @@ TEST_P(DynamicQuantizeAccuracyTest, SplitModelRoundtripAccuracy) {auto [quant_model, dequant_model, data, element_count] = setup_split_test();const auto& p = GetParam();- auto metrics = evaluate_split_roundtrip(quant_model, dequant_model,- data.data(), element_count);+ auto metrics = evaluate_split_roundtrip(quant_model, dequant_model, data.data(), element_count);SCOPED_TRACE("split roundtrip metrics: " + format_metrics(metrics));- EXPECT_LT(metrics.rel_l2_norm, p.threshold)- << "V" << p.decompose_version << " split model relative L2 too high";+ EXPECT_LT(metrics.rel_l2_norm, p.threshold) << "V" << decompose_version(p)+ << " split model relative L2 too high";}// -- Device-based inference test -- split models (opt-in via OV_DQ_TEST_DEVICE)@@ -688,13 +678,12 @@ TEST_P(DynamicQuantizeAccuracyTest, DeviceRoundtripAccuracy) {const auto& p = GetParam();// Reference: interpreter on the split models- auto ref_metrics = evaluate_split_roundtrip(quant_model, dequant_model,- data.data(), element_count);+ auto ref_metrics = evaluate_split_roundtrip(quant_model, dequant_model, data.data(), element_count);AccuracyMetrics dev_metrics;try {- dev_metrics = evaluate_split_roundtrip_on_device(quant_model, dequant_model,- device, data.data(), element_count);+ dev_metrics =+ evaluate_split_roundtrip_on_device(quant_model, dequant_model, device, data.data(), element_count);} catch (const std::exception& e) {GTEST_SKIP() << "Device '" << device << "' is not available: " << e.what();}@@ -703,13 +692,12 @@ TEST_P(DynamicQuantizeAccuracyTest, DeviceRoundtripAccuracy) {SCOPED_TRACE("device metrics: " + format_metrics(dev_metrics));EXPECT_LT(dev_metrics.rel_l2_norm, p.threshold)- << "V" << p.decompose_version << " on " << device << ": relative L2 too high";+ << "V" << decompose_version(p) << " on " << device << ": relative L2 too high";if (ref_metrics.rel_l2_norm > 1e-9) {double ratio = dev_metrics.rel_l2_norm / ref_metrics.rel_l2_norm;- EXPECT_LT(ratio, 4.0)- << "V" << p.decompose_version << " on " << device- << ": device accuracy is " << ratio << "x worse than interpreter";+ EXPECT_LT(ratio, 4.0) << "V" << decompose_version(p) << " on " << device+ << ": device accuracy is " << ratio << "x worse than interpreter";}}@@ -721,23 +709,23 @@ static std::string get_test_case_name(const ::testing::TestParamInfo<DQTestParam}// clang-format off-static DQTestParams make_uniform(int version, Shape shape,+static DQTestParams make_uniform(DQMode mode, Shape shape,float lo, float hi, unsigned seed) {- return {version, shape, seed, DistributionKind::Uniform,+ return {mode, shape, seed, DistributionKind::Uniform,lo, hi, 0.0f, 0.0f, 0.0f};}-static DQTestParams make_ggd(int version, Shape shape,+static DQTestParams make_ggd(DQMode mode, Shape shape,float mu, float alpha, float beta, unsigned seed) {- return {version, shape, seed, DistributionKind::GenGaussian,+ return {mode, shape, seed, DistributionKind::GenGaussian,0.0f, 0.0f, mu, alpha, beta};}-// Symmetric i4 factories: decompose_version=1 (V1 now handles i4 via dtype dispatch),+// Symmetric i4 factories: decompose mode V1 (V1 now handles i4 via dtype dispatch),// is_symmetric=true (2 DQ outputs, no ZP), higher threshold (coarser 4-bit grid).static DQTestParams make_sym_i4_uniform(Shape shape,float lo, float hi, unsigned seed) {- DQTestParams p = make_uniform(1, shape, lo, hi, seed);+ DQTestParams p = make_uniform(DQMode::HandcraftedSymmetricI8, shape, lo, hi, seed);p.quant_dt = element::i4;p.is_symmetric = true;p.threshold = 0.15; // i4: ±7 levels → higher quantisation error@@ -746,7 +734,7 @@ static DQTestParams make_sym_i4_uniform(Shape shape,static DQTestParams make_sym_i4_ggd(Shape shape,float mu, float alpha, float beta, unsigned seed) {- DQTestParams p = make_ggd(1, shape, mu, alpha, beta, seed);+ DQTestParams p = make_ggd(DQMode::HandcraftedSymmetricI8, shape, mu, alpha, beta, seed);p.quant_dt = element::i4;p.is_symmetric = true;// GGD heavy-tail distributions produce outliers that compress the i4 scale,@@ -756,20 +744,20 @@ static DQTestParams make_sym_i4_ggd(Shape shape,}// clang-format on-static std::vector<DQTestParams> make_uniform_cases(int version) {+static std::vector<DQTestParams> make_uniform_cases(DQMode mode) {return {- make_uniform(version, {1, 8, 64, 128}, -1.0f, 1.0f, 42),- make_uniform(version, {1, 8, 64, 128}, -10.0f, 10.0f, 77),- make_uniform(version, {1, 8, 64, 128}, 0.0f, 5.0f, 999),- make_uniform(version, {1, 8, 1024, 128}, -3.0f, 3.0f, 314),+ make_uniform(mode, {1, 8, 64, 128}, -1.0f, 1.0f, 42),+ make_uniform(mode, {1, 8, 64, 128}, -10.0f, 10.0f, 77),+ make_uniform(mode, {1, 8, 64, 128}, 0.0f, 5.0f, 999),+ make_uniform(mode, {1, 8, 1024, 128}, -3.0f, 3.0f, 314),};}-static std::vector<DQTestParams> make_ggd_cases(int version) {+static std::vector<DQTestParams> make_ggd_cases(DQMode mode) {return {- make_ggd(version, {1, 8, 1024, 128}, 0.018f, 1.121f, 0.923f, 42),- make_ggd(version, {1, 8, 1024, 128}, 0.032f, 1.388f, 1.016f, 77),- make_ggd(version, {1, 8, 1024, 128}, -0.027f, 1.830f, 1.271f, 123),+ make_ggd(mode, {1, 8, 1024, 128}, 0.018f, 1.121f, 0.923f, 42),+ make_ggd(mode, {1, 8, 1024, 128}, 0.032f, 1.388f, 1.016f, 77),+ make_ggd(mode, {1, 8, 1024, 128}, -0.027f, 1.830f, 1.271f, 123),};}@@ -793,62 +781,54 @@ static std::vector<DQTestParams> make_sym_i4_ggd_cases() {// ============================================================================// Test instantiation -- V1: handcrafted symmetric i8 [-127, 127]// ============================================================================-INSTANTIATE_TEST_SUITE_P(- V1_Uniform,- DynamicQuantizeAccuracyTest,- ::testing::ValuesIn(make_uniform_cases(1)),- get_test_case_name);+INSTANTIATE_TEST_SUITE_P(V1_Uniform,+ DynamicQuantizeAccuracyTest,+ ::testing::ValuesIn(make_uniform_cases(DQMode::HandcraftedSymmetricI8)),+ get_test_case_name);-INSTANTIATE_TEST_SUITE_P(- V1_GenGaussian,- DynamicQuantizeAccuracyTest,- ::testing::ValuesIn(make_ggd_cases(1)),- get_test_case_name);+INSTANTIATE_TEST_SUITE_P(V1_GenGaussian,+ DynamicQuantizeAccuracyTest,+ ::testing::ValuesIn(make_ggd_cases(DQMode::HandcraftedSymmetricI8)),+ get_test_case_name);// ============================================================================// Test instantiation -- V2: ONNX DynamicQuantizeLinear u8 [0, 255]// ============================================================================-INSTANTIATE_TEST_SUITE_P(- V2_Uniform,- DynamicQuantizeAccuracyTest,- ::testing::ValuesIn(make_uniform_cases(2)),- get_test_case_name);+INSTANTIATE_TEST_SUITE_P(V2_Uniform,+ DynamicQuantizeAccuracyTest,+ ::testing::ValuesIn(make_uniform_cases(DQMode::OnnxDynamicQuantizeLinear)),+ get_test_case_name);-INSTANTIATE_TEST_SUITE_P(- V2_GenGaussian,- DynamicQuantizeAccuracyTest,- ::testing::ValuesIn(make_ggd_cases(2)),- get_test_case_name);+INSTANTIATE_TEST_SUITE_P(V2_GenGaussian,+ DynamicQuantizeAccuracyTest,+ ::testing::ValuesIn(make_ggd_cases(DQMode::OnnxDynamicQuantizeLinear)),+ get_test_case_name);// ============================================================================// Test instantiation -- V3: compiler pattern style i8 [-128, 127]// ============================================================================-INSTANTIATE_TEST_SUITE_P(- V3_Uniform,- DynamicQuantizeAccuracyTest,- ::testing::ValuesIn(make_uniform_cases(3)),- get_test_case_name);+INSTANTIATE_TEST_SUITE_P(V3_Uniform,+ DynamicQuantizeAccuracyTest,+ ::testing::ValuesIn(make_uniform_cases(DQMode::CompilerPatternI8)),+ get_test_case_name);-INSTANTIATE_TEST_SUITE_P(- V3_GenGaussian,- DynamicQuantizeAccuracyTest,- ::testing::ValuesIn(make_ggd_cases(3)),- get_test_case_name);+INSTANTIATE_TEST_SUITE_P(V3_GenGaussian,+ DynamicQuantizeAccuracyTest,+ ::testing::ValuesIn(make_ggd_cases(DQMode::CompilerPatternI8)),+ get_test_case_name);// ============================================================================// Test instantiation -- V1 symmetric i4: handcrafted symmetric i4 [-7, 7]// ============================================================================-INSTANTIATE_TEST_SUITE_P(- V1_Symmetric_i4_Uniform,- DynamicQuantizeAccuracyTest,- ::testing::ValuesIn(make_sym_i4_uniform_cases()),- get_test_case_name);+INSTANTIATE_TEST_SUITE_P(V1_Symmetric_i4_Uniform,+ DynamicQuantizeAccuracyTest,+ ::testing::ValuesIn(make_sym_i4_uniform_cases()),+ get_test_case_name);-INSTANTIATE_TEST_SUITE_P(- V1_Symmetric_i4_GenGaussian,- DynamicQuantizeAccuracyTest,- ::testing::ValuesIn(make_sym_i4_ggd_cases()),- get_test_case_name);+INSTANTIATE_TEST_SUITE_P(V1_Symmetric_i4_GenGaussian,+ DynamicQuantizeAccuracyTest,+ ::testing::ValuesIn(make_sym_i4_ggd_cases()),+ get_test_case_name);// ============================================================================// Test instantiation -- asymmetric i8 offset distributions for all versions.@@ -859,24 +839,25 @@ INSTANTIATE_TEST_SUITE_P(// This can fail until V1 formula is corrected to use -min/scale.// ============================================================================static std::vector<DQTestParams> make_asym_i8_offset_cases() {- static constexpr std::array<int, 3> versions = {1, 2, 3};+ static constexpr std::array<DQMode, 3> versions = {DQMode::HandcraftedSymmetricI8,+ DQMode::OnnxDynamicQuantizeLinear,+ DQMode::CompilerPatternI8};std::vector<DQTestParams> cases;cases.reserve(versions.size() * 3u);- for (const int version : versions) {- cases.push_back(make_uniform(version, {1, 8, 64, 128}, 0.5f, 5.0f, 42));- cases.push_back(make_uniform(version, {1, 8, 64, 128}, 1.0f, 5.0f, 77));- cases.push_back(make_uniform(version, {1, 8, 64, 128}, -5.0f, -0.5f, 99));+ for (const auto mode : versions) {+ cases.push_back(make_uniform(mode, {1, 8, 64, 128}, 0.5f, 5.0f, 42));+ cases.push_back(make_uniform(mode, {1, 8, 64, 128}, 1.0f, 5.0f, 77));+ cases.push_back(make_uniform(mode, {1, 8, 64, 128}, -5.0f, -0.5f, 99));}return cases;}-INSTANTIATE_TEST_SUITE_P(- Asymmetric_i8_OffsetCoverage,- DynamicQuantizeAccuracyTest,- ::testing::ValuesIn(make_asym_i8_offset_cases()),- get_test_case_name);+INSTANTIATE_TEST_SUITE_P(Asymmetric_i8_OffsetCoverage,+ DynamicQuantizeAccuracyTest,+ ::testing::ValuesIn(make_asym_i8_offset_cases()),+ get_test_case_name);} // namespacediff --git a/src/plugins/intel_npu/tests/unit/npuw/pipeline_passes/convert_kvcache_to_precision_test.cpp b/src/plugins/intel_npu/tests/unit/npuw/pipeline_passes/convert_kvcache_to_precision_test.cppindex 1b0019f7136..fb36080fe44 100644--- a/src/plugins/intel_npu/tests/unit/npuw/pipeline_passes/convert_kvcache_to_precision_test.cpp+++ b/src/plugins/intel_npu/tests/unit/npuw/pipeline_passes/convert_kvcache_to_precision_test.cpp@@ -2,15 +2,16 @@// SPDX-License-Identifier: Apache-2.0//+#include "npuw_transformations/convert_kvcache_to_precision.hpp"+#include <gtest/gtest.h>#include <map>#include <sstream>#include <string>-#include "llm_pass_test_fixture.hpp"#include "../util.hpp"-#include "npuw_transformations/convert_kvcache_to_precision.hpp"+#include "llm_pass_test_fixture.hpp"#include "openvino/pass/stateful_to_stateless.hpp"#include "openvino/runtime/properties.hpp"#include "whisper/prepare_whisper_model.hpp"@@ -36,24 +37,29 @@ bool any_name_contains(const ov::Output<const ov::Node>& port, std::string_viewreturn false;}-const std::map<ov::element::Type, std::map<std::string, ov::element::Type>>& precision_key_matrix() {+const std::map<ov::element::Type, std::map<std::string, ov::element::Type>>& precision_key_input_matrix() {+ static const std::map<ov::element::Type, std::map<std::string, ov::element::Type>> matrix = {+ {ov::element::u8, {{"value", ov::element::u8}, {"scale", ov::element::f32}, {"zero_point", ov::element::u8}}},+ {ov::element::i8, {{"value", ov::element::i8}, {"scale", ov::element::f32}, {"zero_point", ov::element::i8}}}};+ return matrix;+}++const std::map<ov::element::Type, std::map<std::string, ov::element::Type>>& precision_key_output_matrix() {static const std::map<ov::element::Type, std::map<std::string, ov::element::Type>> matrix = {{ov::element::u8, {{"value", ov::element::u8}, {"scale", ov::element::f32}, {"zero_point", ov::element::u8}}},- {ov::element::i8, {{"value", ov::element::i8}, {"scale", ov::element::f32}, {"zero_point", ov::element::i8}}}- };+ {ov::element::i8, {{"value", ov::element::i8}, {"scale", ov::element::f32}, {"zero_point", ov::element::i8}}}};return matrix;}const std::map<ov::element::Type, std::map<std::string, ov::element::Type>>& precision_value_matrix() {static const std::map<ov::element::Type, std::map<std::string, ov::element::Type>> matrix = {{ov::element::u8, {{"value", ov::element::i8}, {"scale", ov::element::f32}}},- {ov::element::i8, {{"value", ov::element::i8}, {"scale", ov::element::f32}}}- };+ {ov::element::i8, {{"value", ov::element::i8}, {"scale", ov::element::f32}}}};return matrix;}bool is_quantized_kv_type(const ov::element::Type kv_type) {- return precision_key_matrix().count(kv_type) > 0;+ return precision_key_input_matrix().count(kv_type) > 0;}bool is_fp8_kv_type(const ov::element::Type kv_type) {@@ -71,7 +77,7 @@ ov::AnyMap make_kv_precision_props(const ov::element::Type kv_type) {void expect_kv_cache_input_types(const std::shared_ptr<ov::Model>& model,const ov::element::Type kv_type,const bool check_quant_aux_ports = true) {- // Key cache: asymmetric quantization -> value tensor + scale (f32) + zero_point (same as quant type).+ // Key cache: asymmetric quantization -> value tensor + scale (f32) + zero_point.// Value cache: symmetric quantization -> value tensor (i4) + scale (f32), no zero_point.const bool is_quantized = is_quantized_kv_type(kv_type);@@ -102,7 +108,7 @@ void expect_kv_cache_input_types(const std::shared_ptr<ov::Model>& model,if (is_past_key) {found_key_cache_input = true;- const auto expected = is_quantized ? precision_key_matrix().at(kv_type).at("value") : kv_type;+ const auto expected = is_quantized ? precision_key_input_matrix().at(kv_type).at("value") : kv_type;EXPECT_EQ(input.get_element_type(), expected)<< "past_key_values.<N>.key input must have type " << expected;}@@ -116,23 +122,20 @@ void expect_kv_cache_input_types(const std::shared_ptr<ov::Model>& model,if (check_quant_aux_ports && any_name_contains(input, past_key_scale_name)) {found_key_scale_input = true;- const auto expected = precision_key_matrix().at(kv_type).at("scale");- EXPECT_EQ(input.get_element_type(), expected)- << "past_key scale input must have type " << expected;+ const auto expected = precision_key_input_matrix().at(kv_type).at("scale");+ EXPECT_EQ(input.get_element_type(), expected) << "past_key scale input must have type " << expected;}if (check_quant_aux_ports && any_name_contains(input, past_key_zp_name)) {found_key_zp_input = true;- const auto expected = precision_key_matrix().at(kv_type).at("zero_point");- EXPECT_EQ(input.get_element_type(), expected)- << "past_key zero-point input must have type " << expected;+ const auto expected = precision_key_input_matrix().at(kv_type).at("zero_point");+ EXPECT_EQ(input.get_element_type(), expected) << "past_key zero-point input must have type " << expected;}if (check_quant_aux_ports && any_name_contains(input, past_value_scale_name)) {found_value_scale_input = true;const auto expected = precision_value_matrix().at(kv_type).at("scale");- EXPECT_EQ(input.get_element_type(), expected)- << "past_value scale input must have type " << expected;+ EXPECT_EQ(input.get_element_type(), expected) << "past_value scale input must have type " << expected;}if (check_quant_aux_ports && any_name_contains(input, past_value_zp_name)) {@@ -144,14 +147,10 @@ void expect_kv_cache_input_types(const std::shared_ptr<ov::Model>& model,EXPECT_TRUE(found_value_cache_input) << "No past_key_values.<N>.value input found in model";if (is_quantized && check_quant_aux_ports) {- EXPECT_TRUE(found_key_scale_input)- << "Asymmetric quantized KV key-cache must expose scale input";- EXPECT_TRUE(found_key_zp_input)- << "Asymmetric quantized KV key-cache must expose zero-point input";- EXPECT_TRUE(found_value_scale_input)- << "Symmetric quantized KV value-cache must expose scale input";- EXPECT_FALSE(found_value_zp_input)- << "Symmetric quantized KV value-cache must not expose zero-point input";+ EXPECT_TRUE(found_key_scale_input) << "Asymmetric quantized KV key-cache must expose scale input";+ EXPECT_TRUE(found_key_zp_input) << "Asymmetric quantized KV key-cache must expose zero-point input";+ EXPECT_TRUE(found_value_scale_input) << "Symmetric quantized KV value-cache must expose scale input";+ EXPECT_FALSE(found_value_zp_input) << "Symmetric quantized KV value-cache must not expose zero-point input";} else if (!is_quantized && check_quant_aux_ports) {EXPECT_FALSE(found_key_scale_input) << "Non-quantized KV-cache must not expose key scale input";EXPECT_FALSE(found_key_zp_input) << "Non-quantized KV-cache must not expose key zero-point input";@@ -192,28 +191,25 @@ void expect_kv_cache_present_output_types(const std::shared_ptr<ov::Model>& modeif (is_present_key) {found_present_key = true;- const auto expected = is_quantized ? precision_key_matrix().at(kv_type).at("value") : kv_type;- EXPECT_EQ(output.get_element_type(), expected)- << "present.<N>.key output must have type " << expected;+ const auto expected = is_quantized ? precision_key_output_matrix().at(kv_type).at("value") : kv_type;+ EXPECT_EQ(output.get_element_type(), expected) << "present.<N>.key output must have type " << expected;}if (is_present_value) {found_present_value = true;const auto expected = is_quantized ? precision_value_matrix().at(kv_type).at("value") : kv_type;- EXPECT_EQ(output.get_element_type(), expected)- << "present.<N>.value output must have type " << expected;+ EXPECT_EQ(output.get_element_type(), expected) << "present.<N>.value output must have type " << expected;}if (check_quant_aux_ports && any_name_contains(output, present_key_scale_name)) {found_present_key_scale = true;- const auto expected = precision_key_matrix().at(kv_type).at("scale");- EXPECT_EQ(output.get_element_type(), expected)- << "present key scale output must have type " << expected;+ const auto expected = precision_key_output_matrix().at(kv_type).at("scale");+ EXPECT_EQ(output.get_element_type(), expected) << "present key scale output must have type " << expected;}if (check_quant_aux_ports && any_name_contains(output, present_key_zp_name)) {found_present_key_zp = true;- const auto expected = precision_key_matrix().at(kv_type).at("zero_point");+ const auto expected = precision_key_output_matrix().at(kv_type).at("zero_point");EXPECT_EQ(output.get_element_type(), expected)<< "present key zero-point output must have type " << expected;}@@ -221,8 +217,7 @@ void expect_kv_cache_present_output_types(const std::shared_ptr<ov::Model>& modeif (check_quant_aux_ports && any_name_contains(output, present_value_scale_name)) {found_present_value_scale = true;const auto expected = precision_value_matrix().at(kv_type).at("scale");- EXPECT_EQ(output.get_element_type(), expected)- << "present value scale output must have type " << expected;+ EXPECT_EQ(output.get_element_type(), expected) << "present value scale output must have type " << expected;}if (check_quant_aux_ports && any_name_contains(output, present_value_zp_name)) {@@ -234,21 +229,15 @@ void expect_kv_cache_present_output_types(const std::shared_ptr<ov::Model>& modeEXPECT_TRUE(found_present_value) << "No present.<N>.value output found in model";if (is_quantized && check_quant_aux_ports) {- EXPECT_TRUE(found_present_key_scale)- << "Asymmetric quantized KV key-cache must expose present scale output";- EXPECT_TRUE(found_present_key_zp)- << "Asymmetric quantized KV key-cache must expose present zero-point output";- EXPECT_TRUE(found_present_value_scale)- << "Symmetric quantized KV value-cache must expose present scale output";+ EXPECT_TRUE(found_present_key_scale) << "Asymmetric quantized KV key-cache must expose present scale output";+ EXPECT_TRUE(found_present_key_zp) << "Asymmetric quantized KV key-cache must expose present zero-point output";+ EXPECT_TRUE(found_present_value_scale) << "Symmetric quantized KV value-cache must expose present scale output";EXPECT_FALSE(found_present_value_zp)<< "Symmetric quantized KV value-cache must not expose present zero-point output";} else if (!is_quantized && check_quant_aux_ports) {- EXPECT_FALSE(found_present_key_scale)- << "Non-quantized KV-cache must not expose present key scale output";- EXPECT_FALSE(found_present_key_zp)- << "Non-quantized KV-cache must not expose present key zero-point output";- EXPECT_FALSE(found_present_value_scale)- << "Non-quantized KV-cache must not expose present value scale output";+ EXPECT_FALSE(found_present_key_scale) << "Non-quantized KV-cache must not expose present key scale output";+ EXPECT_FALSE(found_present_key_zp) << "Non-quantized KV-cache must not expose present key zero-point output";+ EXPECT_FALSE(found_present_value_scale) << "Non-quantized KV-cache must not expose present value scale output";EXPECT_FALSE(found_present_value_zp)<< "Non-quantized KV-cache must not expose present value zero-point output";}@@ -264,11 +253,7 @@ class ConvertKVCacheHintPrecisionTest : public ov::test::npuw::LLMPassTestFixturINSTANTIATE_TEST_SUITE_P(KVCachePrecisions,ConvertKVCacheHintPrecisionTest,- ::testing::Values(ov::element::f16,- ov::element::f8e4m3,- ov::element::f8e5m2,- ov::element::i8,- ov::element::u8),+ ::testing::Values(ov::element::f16, ov::element::f8e4m3, ov::element::f8e5m2, ov::element::i8, ov::element::u8),[](const ::testing::TestParamInfo<ov::element::Type>& info) -> std::string {std::ostringstream ss;ss << info.param;@@ -391,15 +376,14 @@ TEST_F(ConvertKVCacheToPrecisionPassTest, OptimizeFp8WithPlainModelKeepsF16KvCacexpect_kv_cache_present_output_types(prefill.model, ov::element::f16);}-// Chunked-prefill: past_key inputs of the prefill model are converted to f16.TEST_F(ConvertKVCacheToPrecisionPassTest, ChunkedPrefillModelPastKeyInputsAreF16) {RecordingFactory recorder;std::unique_ptr<ov::npuw::LLMCompiledModel> compiled;- ASSERT_NO_THROW(compiled = create_compiled_model({{"NPUW_LLM_PREFILL_HINT", "DYNAMIC"},- {"NPUW_LLM_PREFILL_CHUNK_SIZE", "32"}},- recorder));+ ASSERT_NO_THROW(+ compiled = create_compiled_model({{"NPUW_LLM_PREFILL_HINT", "DYNAMIC"}, {"NPUW_LLM_PREFILL_CHUNK_SIZE", "32"}},+ recorder));ASSERT_NE(compiled, nullptr);const auto& prefill = require_sub_model(recorder, "_prefill");diff --git a/src/plugins/intel_npu/tests/unit/npuw/resolve_dynamic_quant_storage_types_test.cpp b/src/plugins/intel_npu/tests/unit/npuw/resolve_dynamic_quant_storage_types_test.cppnew file mode 100644index 00000000000..ab3a77b01c5--- /dev/null+++ b/src/plugins/intel_npu/tests/unit/npuw/resolve_dynamic_quant_storage_types_test.cpp@@ -0,0 +1,238 @@+// Copyright (C) 2018-2026 Intel Corporation+// SPDX-License-Identifier: Apache-2.0+//++#include <gtest/gtest.h>++#include <sstream>+#include <string>+#include <vector>++#include "util.hpp"++namespace {++using DQMode = ov::npuw::util::DynamicQuantDecomposeMode;++struct ResolveStorageTypesParams {+ DQMode mode;+ bool is_symmetric;+ ov::element::Type quant_dt;+ ov::element::Type scale_dt;+ ov::element::Type expected_quantized_data_type;+ ov::element::Type expected_zero_point_type;+ ov::element::Type expected_scale_type;+};++const char* mode_to_token(DQMode mode) {+ switch (mode) {+ case DQMode::HandcraftedSymmetricI8:+ return "V1";+ case DQMode::OnnxDynamicQuantizeLinear:+ return "V2";+ case DQMode::CompilerPatternI8:+ return "V3";+ default:+ return "Unknown";+ }+}++const char* type_to_token(const ov::element::Type& type) {+ if (type == ov::element::u8) {+ return "u8";+ }+ if (type == ov::element::i8) {+ return "i8";+ }+ if (type == ov::element::i4) {+ return "i4";+ }+ if (type == ov::element::f16) {+ return "f16";+ }+ if (type == ov::element::f32) {+ return "f32";+ }+ if (type == ov::element::dynamic) {+ return "dyn";+ }+ return "other";+}++std::string make_test_name(const ResolveStorageTypesParams& p) {+ std::ostringstream os;+ os << mode_to_token(p.mode) << "_" << (p.is_symmetric ? "Sym" : "Asym") << "_Q" << type_to_token(p.quant_dt) << "_S"+ << type_to_token(p.scale_dt) << "_RQ" << type_to_token(p.expected_quantized_data_type) << "_RZ"+ << type_to_token(p.expected_zero_point_type) << "_RS" << type_to_token(p.expected_scale_type);+ return os.str();+}++std::vector<ResolveStorageTypesParams> make_all_cases() {+ return {+ {DQMode::HandcraftedSymmetricI8,+ true,+ ov::element::u8,+ ov::element::f32,+ ov::element::u8,+ ov::element::dynamic,+ ov::element::f32},+ {DQMode::HandcraftedSymmetricI8,+ true,+ ov::element::i8,+ ov::element::f32,+ ov::element::i8,+ ov::element::dynamic,+ ov::element::f32},+ {DQMode::HandcraftedSymmetricI8,+ true,+ ov::element::i4,+ ov::element::f32,+ ov::element::i4,+ ov::element::dynamic,+ ov::element::f32},+ {DQMode::HandcraftedSymmetricI8,+ false,+ ov::element::u8,+ ov::element::f32,+ ov::element::u8,+ ov::element::u8,+ ov::element::f32},+ {DQMode::HandcraftedSymmetricI8,+ false,+ ov::element::i8,+ ov::element::f32,+ ov::element::i8,+ ov::element::i8,+ ov::element::f32},+ {DQMode::HandcraftedSymmetricI8,+ false,+ ov::element::i4,+ ov::element::f32,+ ov::element::i4,+ ov::element::i4,+ ov::element::f32},++ {DQMode::OnnxDynamicQuantizeLinear,+ true,+ ov::element::u8,+ ov::element::f32,+ ov::element::u8,+ ov::element::dynamic,+ ov::element::f32},+ {DQMode::OnnxDynamicQuantizeLinear,+ true,+ ov::element::i8,+ ov::element::f32,+ ov::element::i8,+ ov::element::dynamic,+ ov::element::f32},+ {DQMode::OnnxDynamicQuantizeLinear,+ true,+ ov::element::i4,+ ov::element::f32,+ ov::element::i4,+ ov::element::dynamic,+ ov::element::f32},+ {DQMode::OnnxDynamicQuantizeLinear,+ false,+ ov::element::u8,+ ov::element::f32,+ ov::element::u8,+ ov::element::u8,+ ov::element::f32},+ {DQMode::OnnxDynamicQuantizeLinear,+ false,+ ov::element::i8,+ ov::element::f32,+ ov::element::i8,+ ov::element::i8,+ ov::element::f32},+ {DQMode::OnnxDynamicQuantizeLinear,+ false,+ ov::element::i4,+ ov::element::f32,+ ov::element::i4,+ ov::element::i4,+ ov::element::f32},++ {DQMode::CompilerPatternI8,+ true,+ ov::element::u8,+ ov::element::f32,+ ov::element::u8,+ ov::element::dynamic,+ ov::element::f32},+ {DQMode::CompilerPatternI8,+ true,+ ov::element::i8,+ ov::element::f32,+ ov::element::i8,+ ov::element::dynamic,+ ov::element::f32},+ {DQMode::CompilerPatternI8,+ true,+ ov::element::i4,+ ov::element::f32,+ ov::element::i4,+ ov::element::dynamic,+ ov::element::f32},+ {DQMode::CompilerPatternI8,+ false,+ ov::element::u8,+ ov::element::f32,+ ov::element::u8,+ ov::element::u8,+ ov::element::f32},+ {DQMode::CompilerPatternI8,+ false,+ ov::element::i8,+ ov::element::f32,+ ov::element::u8,+ ov::element::u8,+ ov::element::f32},+ {DQMode::CompilerPatternI8,+ false,+ ov::element::i4,+ ov::element::f32,+ ov::element::i4,+ ov::element::i4,+ ov::element::f32},++ {DQMode::CompilerPatternI8,+ false,+ ov::element::i8,+ ov::element::f16,+ ov::element::u8,+ ov::element::u8,+ ov::element::f16},+ {DQMode::OnnxDynamicQuantizeLinear,+ true,+ ov::element::u8,+ ov::element::f16,+ ov::element::u8,+ ov::element::dynamic,+ ov::element::f16},+ };+}++class ResolveDynamicQuantStorageTypesTest : public ::testing::TestWithParam<ResolveStorageTypesParams> {};++TEST_P(ResolveDynamicQuantStorageTypesTest, CoversAllQuantDtSymmetryAndDecomposeModeCombinations) {+ const auto& p = GetParam();++ const auto resolved =+ ov::npuw::util::resolve_dynamic_quant_storage_types(p.mode, p.is_symmetric, p.quant_dt, p.scale_dt);++ EXPECT_EQ(resolved.quantized_data_type, p.expected_quantized_data_type);+ EXPECT_EQ(resolved.zero_point_type, p.expected_zero_point_type);+ EXPECT_EQ(resolved.scale_type, p.expected_scale_type);+}++INSTANTIATE_TEST_SUITE_P(AllCombinations,+ ResolveDynamicQuantStorageTypesTest,+ ::testing::ValuesIn(make_all_cases()),+ [](const ::testing::TestParamInfo<ResolveStorageTypesParams>& info) {+ return make_test_name(info.param);+ });++} // namespace