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: Improve the robustness check for F16IC assignment (#34641)
Dmitry Matveev5dfe50e6d383
diff --git a/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/snapshot.cpp b/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/snapshot.cppindex 6f0e3f38d75..24adfc19330 100644--- a/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/snapshot.cpp+++ b/src/plugins/intel_npu/src/plugin/npuw/partitioning/online/snapshot.cpp@@ -172,28 +172,39 @@ bool isRegularParameterCase(const std::unordered_map<std::shared_ptr<Repeated>,continue;}- auto firstGroup = *(gset.begin());- for (auto input_layer : firstGroup->getInputs()) {- // this is the reference mask expected from all other matched layers- // in the remaining groups of the repeated block- auto expected_producers_mask = getProducersMask(input_layer);-- auto this_layer_name = input_layer->get_friendly_name();- auto layer_bank_iter = std::find_if(matches.begin(), matches.end(), [&](const std::set<std::string>& lrs) {- return lrs.count(this_layer_name) > 0;- });-- NPUW_ASSERT(layer_bank_iter != matches.end());-- // match input layers across all groups in the repeated block- // and compare their producers mask- for (const auto& layer_name : *layer_bank_iter) {- auto layer_ptr = node_id_cache.at(layer_name);- auto actual_producers_mask = getProducersMask(layer_ptr);- if (actual_producers_mask != expected_producers_mask) {- LOG_INFO("This is NOT a regular parameter case. Producers mask mismatch found for "- << layer_name << " and " << this_layer_name << " input layers.");- return false;+ // Iterate over ALL groups' input layers instead of only the first group's.+ // A group whose boundary node reads exclusively from ov::Parameters (e.g.+ // the first transformer layer reading inputs_embeds) may not expose that+ // node via getInputs() — getInputs() filters out nodes whose only external+ // producers satisfy !isOp() (Parameter/Constant). Any sibling group in the+ // repeated set will have the corresponding boundary node in its getInputs()+ // (its producer is a computation node from the preceding group). That node's+ // match bank also contains the first-layer node, which will show a different+ // producers mask — exactly the mismatch we need to detect.+ for (const auto& gptr : gset) {+ for (auto input_layer : gptr->getInputs()) {+ // this is the reference mask expected from all other matched layers+ // in the remaining groups of the repeated block+ auto expected_producers_mask = getProducersMask(input_layer);++ auto this_layer_name = input_layer->get_friendly_name();+ auto layer_bank_iter =+ std::find_if(matches.begin(), matches.end(), [&](const std::set<std::string>& lrs) {+ return lrs.count(this_layer_name) > 0;+ });++ NPUW_ASSERT(layer_bank_iter != matches.end());++ // match input layers across all groups in the repeated block+ // and compare their producers mask+ for (const auto& layer_name : *layer_bank_iter) {+ auto layer_ptr = node_id_cache.at(layer_name);+ auto actual_producers_mask = getProducersMask(layer_ptr);+ if (actual_producers_mask != expected_producers_mask) {+ LOG_INFO("This is NOT a regular parameter case. Producers mask mismatch found for "+ << layer_name << " and " << this_layer_name << " input layers.");+ return false;+ }}}}diff --git a/src/plugins/intel_npu/tests/unit/npuw/online_partitioning.cpp b/src/plugins/intel_npu/tests/unit/npuw/online_partitioning.cppindex d0ce835c095..20a49e9657a 100644--- a/src/plugins/intel_npu/tests/unit/npuw/online_partitioning.cpp+++ b/src/plugins/intel_npu/tests/unit/npuw/online_partitioning.cpp@@ -12,11 +12,13 @@#include "openvino/op/ops.hpp"#include "openvino/op/util/op_types.hpp"#include "openvino/openvino.hpp"+#include "openvino/pass/stateful_to_stateless.hpp"#include "partitioning/online/compiler.hpp"#include "partitioning/online/group.hpp"#include "partitioning/online/snapshot.hpp"using ov::test::npuw::ModelBuilder;+using ov::test::npuw::ModelConfig;namespace {@@ -656,3 +658,78 @@ INSTANTIATE_TEST_SUITE_P(OnlinePartitioningTest,std::make_tuple(std::vector<std::size_t>{5}, /*irregular_io=*/true),// No blocks have an additional ov::Parameter producersstd::make_tuple(std::vector<std::size_t>{}, /*irregular_io=*/false)));++// Regression test for the isRegularParameterCase iteration-order bug.+//+// In a prefill-style model built with use_inputs_embeds=true, the first transformer+// layer's residual Add reads inputs_embeds (ov::Parameter) as its ONLY external+// producer -- the other input (o_proj/MatMul) is internal to the same partitioned+// group. Because isOp(Parameter)=false, updateInputLayers() excludes that Add from+// group 0's getInputs(). The old code used gset.begin() (hash-order-dependent) as+// the sole reference group: if it landed on group 0, the mismatch between layer 0's+// producers mask [true, false] and layers 1+'s mask [false, false] was invisible,+// so irregular_io was incorrectly set to false and F16IC was wrongly enabled,+// leading to a 26!=27 sanityCheck assertion failure at runtime.+//+// The fix iterates ALL groups in gset so that at least one sibling group (layers 1+)+// always exposes its boundary Add in getInputs(), detects the mask mismatch, and+// correctly sets irregular_io=true regardless of hash order.+TEST(OnlinePartitioningTest, IsRegularParameterCase_PrefillModel_InputsEmbeds) {+ ModelConfig config;+ config.num_layers = 4;+ config.hidden_size = 64;+ config.use_inputs_embeds = true; // layer 0's residual Add reads inputs_embeds (ov::Parameter)+ config.use_kv_cache = true;++ ModelBuilder mb;+ auto model = mb.build_model(config);++ // Partitioning requires a static-shape stateless model, matching the real+ // production path in LLMCompiledModel before getPartitioning() is called.+ ov::pass::StatefulToStateless().run_on_model(model);+ // StatefulToStateless removes Assign nodes from model sinks but does NOT sever+ // their incoming edges (Concat → Assign). clone() rebuilds the model from+ // get_ordered_ops(), which no longer includes the dangling Assigns, producing a+ // clean graph. This mirrors LLMCompiledModel's kvcache_model->clone() → prefill_model.+ model = model->clone();++ // Resolve dynamic dimensions using the same name-aware logic as the production+ // LLMCompiledModel::reshape_to_static():+ // - inputs_embeds -> [1, seq_len, hidden_size] (hidden_size stays static)+ // - attention_mask -> [1, kvcache_size] (covers full past + current)+ // - position_ids -> [1, seq_len]+ // - past KV tensors -> [1, kv_heads, past_kv_len, head_dim]+ // (axes 1 and 3 are already static in the model builder)+ const int64_t seq_len = 8;+ const int64_t past_kv_len = 8;+ const int64_t kvcache_size = seq_len + past_kv_len;+ std::map<std::string, ov::PartialShape> new_shapes;+ for (const auto& input : model->inputs()) {+ const auto& name = input.get_any_name();+ const auto& pshape = input.get_partial_shape();+ ov::PartialShape new_shape;+ if (name.find("inputs_embeds") != std::string::npos) {+ new_shape = {1, seq_len, pshape[2]}; // hidden_size is static+ } else if (name.find("attention_mask") != std::string::npos) {+ new_shape = {1, kvcache_size};+ } else if (name.find("position_ids") != std::string::npos) {+ new_shape = {1, seq_len};+ } else {+ // Past KV tensors: [batch, kv_heads, past_kv_len, head_dim]+ // (axes 1 and 3 are already static; set batch=1 and past_kv_len)+ new_shape = pshape;+ new_shape[0] = 1;+ new_shape[2] = past_kv_len;+ }+ new_shapes[name] = new_shape;+ }+ model->reshape(new_shapes);++ auto cfg = createConfigWithKeepBlockSize(4);+ auto ens = ov::npuw::online::buildPartitioning(model, cfg);++ EXPECT_GE(ens.repeated.size(), 1u); // sanity: transformer layers must form a repeated block+ // Layer 0 reads inputs_embeds (ov::Parameter); layers 1+ read from prior computation.+ // isRegularParameterCase must detect this structural asymmetry and set irregular_io=true.+ EXPECT_TRUE(ens.irregular_io);+}