From 42f0c4ae49513eb3bd14c243e9207f035e31f0af Mon Sep 17 00:00:00 2001 From: Surendar Rama Sitaraman Date: Thu, 13 Feb 2025 21:27:40 -0800 Subject: [PATCH] Fix quantized Pad op dimension check when QDQ optimizer is disabled This change addresses an issue where a Pad op in quantized models fails due to an unsupported dimension input. The fix adds logic to detect if a Pad op is part of a quantized model by checking for a DequantizeLinear input. If found, the op is marked as quantized and the unsupported dimension check is bypassed, ensuring that the pad_value remains constant as required by the VPUX compiler. Related-to: EISW-152222 --- .../openvino/ov_versions/data_ops.cc | 31 ++++++++++++++----- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/onnxruntime/core/providers/openvino/ov_versions/data_ops.cc b/onnxruntime/core/providers/openvino/ov_versions/data_ops.cc index 669d11ff3be7f..78e9d49a2c3de 100644 --- a/onnxruntime/core/providers/openvino/ov_versions/data_ops.cc +++ b/onnxruntime/core/providers/openvino/ov_versions/data_ops.cc @@ -752,16 +752,33 @@ bool DataOps::node_is_supported(const NodeIndex node_idx, bool& has_external_wei if (op_is_supported(optype, no_dimension_supported_)) { return; } - if (npu_qdq_optimizer_enabled_) { - // Pad Op with DQ inputs will be optimized out in the qdq optimization pass, so mark those no dim Pad ops - // supported here - if (optype == "Pad") { - for (Node::NodeConstIterator it_dq = node->InputNodesBegin(); it_dq != node->InputNodesEnd(); ++it_dq) { - const auto& DQ = &*it_dq; - if (DQ->OpType() == "DequantizeLinear") return; + // Special handling for the "Pad" operator + if (optype == "Pad") { + bool is_quantized = false; + // Detect a quantized model by checking for a DequantizeLinear input + for (Node::NodeConstIterator it_dq = node->InputNodesBegin(); it_dq != node->InputNodesEnd(); ++it_dq) { + const auto& DQ = &*it_dq; + if (DQ->OpType() == "DequantizeLinear") { + is_quantized = true; + break; } } + if (is_quantized) { + // For quantized Pad ops when the QDQ optimizer is disabled, + // bypass the unsupported dimension check to ensure 'pad_value' is constant + if (!npu_qdq_optimizer_enabled_) { +#ifndef NDEBUG + if (openvino_ep::backend_utils::IsDebugEnabled()) { + // Pad Op with DQ inputs gets optimized in the downstream, + // so mark those no dim quantized Pad ops supported here + std::cout << "QDQ optimizer disabled; quantized Pad op detected (DequantizeLinear present), so marking those no dim quantized Pad ops as supported" << std::endl; + } +#endif + } + return; + } } + // For ops that haven't been handled above, mark as unsupported dim has_unsupported_dimension = true; return; } else {