Skip to content

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

NPUW: Fix FP8-NF4 LUT representation (#30904)

Dmitry Matveev3f99c9c1c801
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cpp
index f303e17672a..6d908979de9 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/partitioning.cpp
@@ -362,6 +362,10 @@ std::shared_ptr<ov::Node> Partitioner::new_f16ic_cvt(ov::Output<ov::Node> out, o
return new_src;
}
+struct Precalculated_Bound_Const {
+ static constexpr const char* name = "NPUW::Precalculated_Bound_Const";
+};
+
void Partitioner::identifySubgraphs() {
LOG_INFO("Identifying subgraphs for model " << model->get_friendly_name() << "...");
LOG_BLOCK();
@@ -468,6 +472,7 @@ void Partitioner::identifySubgraphs() {
if (output_tensor.has_and_set_bound()) {
// if has_and_set_bound() == true, lower/upper values are the same tensor.
auto new_const = std::make_shared<ov::op::v0::Constant>(output_tensor.get_upper_value());
+ new_const->set_friendly_name(ov::npuw::util::Unique<Precalculated_Bound_Const>::name());
result = std::static_pointer_cast<ov::Node>(new_const);
LOG_VERB("Found bound value in " << output << ", substituting it with " << new_const);
} else {
@@ -1374,6 +1379,7 @@ void Partitioner::saveRepeatedConstants(const std::string& func_name) {
HANDLE_CASE(u16, uint16_t);
HANDLE_CASE(i32, int);
HANDLE_CASE(i64, int64_t);
+ HANDLE_CASE(f8e4m3, uint8_t);
HANDLE_CASE(f16, uint16_t);
HANDLE_CASE(f32, float);
#undef HANDLE_CASE
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/opt.cpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/opt.cpp
index 34750528067..365b7ef3222 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/opt.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/patterns/opt.cpp
@@ -1847,6 +1847,10 @@ ConvToMatmul::ConvToMatmul(Context::Ref ctx) {
register_matcher(std::make_shared<opp::Matcher>(transpose_out, "ConvToMatmul"), std::move(callback));
}
+struct Untangled_Const {
+ static constexpr const char* name = "NPUW::Untangled_Const";
+};
+
void untangleConst(std::shared_ptr<ov::Model> model) {
// Duplicate small Constants which are consumed by multiple operators
// to simplify match bank validation in the future
@@ -1854,6 +1858,7 @@ void untangleConst(std::shared_ptr<ov::Model> model) {
if (!ov::op::util::is_constant(ov_node)) {
continue;
}
+
const auto readers = ov_node->output(0).get_target_inputs();
if (readers.size() <= 1) {
continue;
@@ -1861,13 +1866,16 @@ void untangleConst(std::shared_ptr<ov::Model> model) {
auto this_const = std::static_pointer_cast<ov::op::v0::Constant>(ov_node);
auto this_type = this_const->get_element_type();
auto this_shape = ov_node->output(0).get_shape();
- if (this_type == ov::element::i64 && this_shape.size() == 0) {
+
+ const bool is_single = (this_shape.size() == 0u) || (this_shape.size() == 1u && this_shape[0] == 1);
+ if (this_type == ov::element::i64 && is_single) {
// Keep the first reader with the original const, but redirect
// all others to use their individual instance
auto this_val = this_const->get_tensor_view();
auto it = readers.begin();
while (++it != readers.end()) {
auto new_const = std::make_shared<ov::op::v0::Constant>(this_val);
+ new_const->set_friendly_name(util::Unique<Untangled_Const>::name());
it->replace_source_output(new_const);
}
}
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/traits.cpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/traits.cpp
index 7d2ac6b7c87..46bae3715b4 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/traits.cpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/traits.cpp
@@ -13,7 +13,8 @@ bool partitioning::traits::is_tiny_shape(const ov::Shape& shape) {
const auto total = std::accumulate(shape.begin(), shape.end(), std::size_t{1}, std::multiplies<std::size_t>());
// The initial check
- if ((shape.size() == 0 || (shape.size() == 1 && shape[0] <= 10)) || (total <= 10)) {
+ const std::size_t TINY_THRESHOLD = 16;
+ if ((shape.size() == 0 || (shape.size() == 1 && shape[0] <= TINY_THRESHOLD)) || (total <= TINY_THRESHOLD)) {
return true;
}
return false;
diff --git a/src/plugins/intel_npu/src/plugin/npuw/util.hpp b/src/plugins/intel_npu/src/plugin/npuw/util.hpp
index 5952638ecab..a91ea46e430 100644
--- a/src/plugins/intel_npu/src/plugin/npuw/util.hpp
+++ b/src/plugins/intel_npu/src/plugin/npuw/util.hpp
@@ -157,6 +157,14 @@ void non_parallel_for(std::size_t count, F&& f) {
}
}
+template <class CountedType>
+struct Unique {
+ static std::string name() {
+ static std::size_t counter = 0u;
+ return std::string(CountedType::name) + "_" + std::to_string(counter++);
+ }
+};
+
} // namespace util
} // namespace npuw
} // namespace ov