Skip to content

Commit

Permalink
Fixes dynamic shapes (#27776)
Browse files Browse the repository at this point in the history
### Details:

* Aligns fixes in dynamic shape serializing with
intel-innersource/applications.ai.vpu-accelerators.vpux-plugin#14490
* Fix parsing of shapes for SIT

### Tickets:
 - E147314
 - E147315

---------

Signed-off-by: Skrebkov, Artemy <[email protected]>
Co-authored-by: Pawel Raasz <[email protected]>
  • Loading branch information
ArtemySkrebkov and praasz authored Jan 17, 2025
1 parent a705714 commit 9e0463d
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 25 deletions.
17 changes: 8 additions & 9 deletions samples/cpp/benchmark_app/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,9 +523,7 @@ int main(int argc, char* argv[]) {
}
}
auto result = std::find_if(config.begin(), config.end(), [&](const std::pair<std::string, ov::AnyMap>& item) {
if (device_name.find(item.first) == 0)
return true;
return false;
return device_name.find(item.first) == 0;
});
ov::AnyMap device_config = {};
if (result != config.end())
Expand All @@ -548,6 +546,11 @@ int main(int argc, char* argv[]) {
}

bool isDynamicNetwork = false;
auto areNetworkInputsDynamic = [](const benchmark_app::InputsInfo& input_info) {
return std::any_of(input_info.begin(), input_info.end(), [](const auto& info) {
return info.second.partialShape.is_dynamic();
});
};

if (FLAGS_load_from_file && !isNetworkCompiled) {
if (!FLAGS_mean_values.empty() || !FLAGS_scale_values.empty()) {
Expand Down Expand Up @@ -722,12 +725,7 @@ int main(int argc, char* argv[]) {
model = preproc.build();

// Check if network has dynamic shapes
auto input_info = app_inputs_info[0];
isDynamicNetwork = std::any_of(input_info.begin(),
input_info.end(),
[](const std::pair<std::string, benchmark_app::InputInfo>& i) {
return i.second.partialShape.is_dynamic();
});
isDynamicNetwork = areNetworkInputsDynamic(app_inputs_info.at(0));

topology_name = model->get_friendly_name();

Expand Down Expand Up @@ -789,6 +787,7 @@ int main(int argc, char* argv[]) {
FLAGS_scale_values,
FLAGS_mean_values,
compiledModel.inputs());
isDynamicNetwork = areNetworkInputsDynamic(app_inputs_info.at(0));

batchSize = get_batch_size(app_inputs_info.at(0));
warn_if_no_batch(app_inputs_info.at(0));
Expand Down
5 changes: 2 additions & 3 deletions src/plugins/intel_npu/src/backend/src/zero_infer_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ void check_level_zero_attributes_match(const IODescriptor& ioDescriptor, const A
'\n' + "Given: " + std::to_string(ovDimensions.size()));

for (size_t index = 0; index < ovDimensions.size(); ++index) {
OPENVINO_ASSERT(
ioDescriptor.shapeFromCompiler.is_dynamic() || ovDimensions[index] == zeDescriptor.info.dims[index],
"Shape mismatch for input/output named " + ioDescriptor.nameFromCompiler);
OPENVINO_ASSERT(ovDimensions[index] == zeDescriptor.info.dims[index],
"Shape mismatch for input/output named " + ioDescriptor.nameFromCompiler);
}
for (size_t index = ovDimensions.size(); index < ZE_MAX_GRAPH_ARGUMENT_DIMENSIONS_SIZE; ++index) {
OPENVINO_ASSERT(zeDescriptor.info.dims[index] == 0 || zeDescriptor.info.dims[index] == 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@
#include "intel_npu/utils/zero/zero_api.hpp"
#include "intel_npu/utils/zero/zero_result.hpp"
#include "intel_npu/utils/zero/zero_wrappers.hpp"
#include "openvino/core/dimension.hpp"
#include "openvino/core/model.hpp"
#include "openvino/core/partial_shape.hpp"

#define NotSupportQuery(T) (T <= ZE_GRAPH_EXT_VERSION_1_2)

Expand Down Expand Up @@ -400,7 +402,8 @@ ze_graph_handle_t ZeGraphExtWrappers::getGraphHandle(const std::vector<uint8_t>&
static IODescriptor getIODescriptor(const ze_graph_argument_properties_3_t& arg,
const std::optional<ze_graph_argument_metadata_t>& metadata) {
ov::element::Type_t precision = toOVElementType(arg.devicePrecision);
ov::Shape shapeFromCompiler, shapeFromIRModel;
ov::Shape shapeFromCompiler;
ov::PartialShape shapeFromIRModel;
std::unordered_set<std::string> outputTensorNames;

for (uint32_t id = 0; id < arg.associated_tensor_names_count; id++) {
Expand All @@ -410,8 +413,17 @@ static IODescriptor getIODescriptor(const ze_graph_argument_properties_3_t& arg,
shapeFromCompiler.push_back(arg.dims[id]);
}
if (metadata.has_value()) {
const auto dynamicDim = std::numeric_limits<uint64_t>::max();
shapeFromIRModel.reserve(metadata->shape_size);
for (uint32_t id = 0; id < metadata->shape_size; id++) {
shapeFromIRModel.push_back(metadata->shape[id]);
if (metadata->shape[id] != dynamicDim) {
shapeFromIRModel.push_back(metadata->shape[id]);
} else {
// lower bound is ignored, so we set it to 1 just to satisfy the Dimension constructor,
// upper bound is set to the value from shapeFromCompiler as it is filled with upper bounds
// in case of dynamic dimensions
shapeFromIRModel.push_back(ov::Dimension(1, shapeFromCompiler[id]));
}
}
}

Expand All @@ -433,7 +445,7 @@ static IODescriptor getIODescriptor(const ze_graph_argument_properties_3_t& arg,

return {std::move(nameFromCompiler),
precision,
std::move(shapeFromCompiler),
shapeFromCompiler,
isStateInput,
isStateOutput,
isShapeTensor,
Expand Down
26 changes: 16 additions & 10 deletions src/plugins/intel_npu/tools/single-image-test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1569,8 +1569,8 @@ std::pair<TensorMap, ProfVec> runInfer(ov::InferRequest& inferRequest, ov::Compi

TensorMap out;
for (const auto& outputInfo : compiledModel.outputs()) {
const std::string layer_name = outputInfo.get_any_name();
out.insert({layer_name, inferRequest.get_tensor(layer_name)});
const std::string layerName = outputInfo.get_any_name();
out.insert({layerName, inferRequest.get_tensor(layerName)});
}

ProfVec profData{};
Expand Down Expand Up @@ -1807,11 +1807,17 @@ bool testMeanIoU(const TensorMap& outputs, const TensorMap& references, const La
}

static ov::Shape parseDataShape(const std::string& dataShapeStr) {
std::vector<size_t> dataShape;
std::istringstream ss(dataShapeStr);
std::string token;
while (std::getline(ss, token, ',')) {
dataShape.push_back(std::stoul(token));
std::vector<uint64_t> dataShape;
std::stringstream ss(dataShapeStr);

char ch; // To discard non-numeric characters
int64_t dim;
while (ss >> ch) {
if (std::isdigit(ch)) {
ss.putback(ch);
ss >> dim;
dataShape.push_back(dim);
}
}
return ov::Shape(dataShape);
}
Expand Down Expand Up @@ -1906,11 +1912,11 @@ static int runSingleImageTest() {
auto model = core.read_model(FLAGS_network);
nameIOTensors(model);

auto inputs_info = std::const_pointer_cast<ov::Model>(model)->inputs();
InputsInfo info_map;
auto inputsInfo = std::const_pointer_cast<ov::Model>(model)->inputs();
InputsInfo infoMap;

std::cout << "Performing reshape" << std::endl;
reshape(std::move(inputs_info), info_map, model, FLAGS_shape,
reshape(std::move(inputsInfo), infoMap, model, FLAGS_shape,
FLAGS_override_model_batch_size, FLAGS_device);

ov::preprocess::PrePostProcessor ppp(model);
Expand Down

0 comments on commit 9e0463d

Please sign in to comment.