From 124f2bc5c99e27152ca20916857df2d870cba359 Mon Sep 17 00:00:00 2001 From: Ilya Churaev Date: Tue, 24 Oct 2023 19:19:16 +0400 Subject: [PATCH] Remove NF4 Convert from public API (#20666) * Remove NF4 Convert from public API * Fixed build --- src/core/{include => dev_api}/openvino/core/type/nf4.hpp | 0 src/core/include/openvino/core/type/element_type.hpp | 1 - src/core/include/openvino/op/constant.hpp | 7 ++++--- src/core/reference/include/openvino/reference/convert.hpp | 3 ++- src/core/src/op/constant.cpp | 7 +++++++ 5 files changed, 13 insertions(+), 5 deletions(-) rename src/core/{include => dev_api}/openvino/core/type/nf4.hpp (100%) diff --git a/src/core/include/openvino/core/type/nf4.hpp b/src/core/dev_api/openvino/core/type/nf4.hpp similarity index 100% rename from src/core/include/openvino/core/type/nf4.hpp rename to src/core/dev_api/openvino/core/type/nf4.hpp diff --git a/src/core/include/openvino/core/type/element_type.hpp b/src/core/include/openvino/core/type/element_type.hpp index 1534e9e0cc8..78e200d5035 100644 --- a/src/core/include/openvino/core/type/element_type.hpp +++ b/src/core/include/openvino/core/type/element_type.hpp @@ -20,7 +20,6 @@ #include "openvino/core/rtti.hpp" #include "openvino/core/type/bfloat16.hpp" #include "openvino/core/type/float16.hpp" -#include "openvino/core/type/nf4.hpp" /** * @defgroup ov_element_cpp_api Element types diff --git a/src/core/include/openvino/op/constant.hpp b/src/core/include/openvino/op/constant.hpp index 100ed2f7e18..6299dde4590 100644 --- a/src/core/include/openvino/op/constant.hpp +++ b/src/core/include/openvino/op/constant.hpp @@ -705,15 +705,15 @@ private: auto p = get_data_ptr_nc(); size_t i = 0; for (; i < source.size() / 2; i++) { - const auto idx1 = ConvertNF4::quantize(static_cast(source[i * 2])); - const auto idx2 = ConvertNF4::quantize(static_cast(source[i * 2 + 1])); + const auto idx1 = quantize_nf4(static_cast(source[i * 2])); + const auto idx2 = quantize_nf4(static_cast(source[i * 2 + 1])); const auto v1 = value_in_range(idx1) & 0x0F; const auto v2 = value_in_range(idx2) & 0x0F; const auto v = (v2 << 4) | v1; p[i] = static_cast(v); } if (source.size() % 2) { - const auto idx1 = ConvertNF4::quantize(static_cast(source[i * 2])); + const auto idx1 = quantize_nf4(static_cast(source[i * 2])); const auto v = value_in_range(idx1) & 0x0F; p[i] = static_cast(v); } @@ -853,6 +853,7 @@ private: } return shape_size(m_shape) * m_element_type.size(); } + static uint8_t quantize_nf4(float x); element::Type m_element_type; Shape m_shape{}; diff --git a/src/core/reference/include/openvino/reference/convert.hpp b/src/core/reference/include/openvino/reference/convert.hpp index bd36b50b033..3924ce69055 100644 --- a/src/core/reference/include/openvino/reference/convert.hpp +++ b/src/core/reference/include/openvino/reference/convert.hpp @@ -8,6 +8,7 @@ #include "openvino/core/type/element_type.hpp" #include "openvino/core/type/float16.hpp" +#include "openvino/core/type/nf4.hpp" namespace ov { namespace reference { @@ -87,7 +88,7 @@ void lp_convert(const TI* arg, TO* out, size_t count, element::Type_t src_type, } else if (dst_type == element::i4) { detail::set_i4(output, i, detail::get_value(input, i, src_type)); } else if (src_type == element::nf4) { - ConvertNF4::unpack(out, input, i); + ov::ConvertNF4::unpack(out, input, i); } else { out[i] = detail::get_value(input, i, src_type); } diff --git a/src/core/src/op/constant.cpp b/src/core/src/op/constant.cpp index 2fe3d024fd9..34e97d73eee 100644 --- a/src/core/src/op/constant.cpp +++ b/src/core/src/op/constant.cpp @@ -13,6 +13,9 @@ #include "ngraph/runtime/aligned_buffer.hpp" #include "ngraph/runtime/host_tensor.hpp" #include "ngraph/runtime/tensor.hpp" +#include "openvino/core/type/element_type.hpp" +#include "openvino/core/type/float16.hpp" +#include "openvino/core/type/nf4.hpp" #include "openvino/runtime/shared_buffer.hpp" template @@ -606,3 +609,7 @@ bool ov::op::v0::Constant::evaluate_lower(TensorVector& outputs) const { bool ov::op::v0::Constant::evaluate_upper(TensorVector& outputs) const { return evaluate(outputs, {}); } + +uint8_t ov::op::v0::Constant::quantize_nf4(float x) { + return ov::ConvertNF4::quantize(x); +}