|
| 1 | +// Copyright (C) 2018-2025 Intel Corporation |
| 2 | +// SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +#include "core/operator_set.hpp" |
| 5 | +#include "exceptions.hpp" |
| 6 | +#include "openvino/frontend/exception.hpp" |
| 7 | +#include "openvino/op/add.hpp" |
| 8 | +#include "openvino/op/concat.hpp" |
| 9 | +#include "openvino/op/convert.hpp" |
| 10 | +#include "openvino/op/divide.hpp" |
| 11 | +#include "openvino/op/multiply.hpp" |
| 12 | +#include "openvino/op/subtract.hpp" |
| 13 | +#include "utils/common.hpp" |
| 14 | + |
| 15 | +using namespace ov::op; |
| 16 | + |
| 17 | +namespace ov { |
| 18 | +namespace frontend { |
| 19 | +namespace onnx { |
| 20 | +namespace com_microsoft { |
| 21 | +namespace opset_1 { |
| 22 | + |
| 23 | +ov::OutputVector qlinear_concat(const ov::frontend::onnx::Node& node) { |
| 24 | + common::default_op_checks(node, 3); |
| 25 | + |
| 26 | + auto inputs = node.get_ov_inputs(); |
| 27 | + auto Y_scale = inputs[0]; |
| 28 | + auto Y_zero_point = inputs[1]; |
| 29 | + |
| 30 | + std::vector<std::shared_ptr<ov::Node>> dequantized_inputs; |
| 31 | + for (size_t i = 2; i < inputs.size(); i += 3) { |
| 32 | + auto X = inputs[i]; |
| 33 | + auto X_scale = inputs[i + 1]; |
| 34 | + auto X_zero_point = inputs[i + 2]; |
| 35 | + |
| 36 | + auto X_minus_zero_point = std::make_shared<v1::Subtract>(X, X_zero_point); |
| 37 | + auto X_minus_zero_point_float = std::make_shared<v0::Convert>(X_minus_zero_point, X_scale.get_element_type()); |
| 38 | + auto dequantized_X = std::make_shared<v1::Multiply>(X_scale, X_minus_zero_point_float); |
| 39 | + |
| 40 | + dequantized_inputs.push_back(dequantized_X); |
| 41 | + } |
| 42 | + |
| 43 | + auto axis = node.get_attribute_value<int64_t>("axis"); |
| 44 | + auto concatenated = |
| 45 | + std::make_shared<v0::Concat>(ov::OutputVector(dequantized_inputs.begin(), dequantized_inputs.end()), axis); |
| 46 | + |
| 47 | + auto requantized = std::make_shared<v1::Divide>(concatenated, Y_scale); |
| 48 | + auto Y_zero_point_float = std::make_shared<v0::Convert>(Y_zero_point, Y_scale.get_element_type()); |
| 49 | + auto Y_float = std::make_shared<v1::Add>(requantized, Y_zero_point_float); |
| 50 | + auto Y = std::make_shared<v0::Convert>(Y_float, inputs[2].get_element_type()); |
| 51 | + |
| 52 | + return {Y}; |
| 53 | +} |
| 54 | + |
| 55 | +ONNX_OP("QLinearConcat", OPSET_SINCE(1), com_microsoft::opset_1::qlinear_concat, MICROSOFT_DOMAIN); |
| 56 | + |
| 57 | +} // namespace opset_1 |
| 58 | +} // namespace com_microsoft |
| 59 | +} // namespace onnx |
| 60 | +} // namespace frontend |
| 61 | +} // namespace ov |
0 commit comments