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
[TRANSFORMATIONS] Destroy constants after replacement in constant folding (#33961)
Mikhail Ryzhovab6e908c5083
diff --git a/src/core/src/pass/constant_folding.cpp b/src/core/src/pass/constant_folding.cppindex 5d95f7061fe..6057b6902e4 100644--- a/src/core/src/pass/constant_folding.cpp+++ b/src/core/src/pass/constant_folding.cpp@@ -106,7 +106,11 @@ bool ov::pass::ConstantFolding::run_on_model(const std::shared_ptr<ov::Model>& mbool rewritten = pre_calculated_values_folding(model);- for (const auto& original_node : model->get_ordered_ops()) {+ // Creating a local vector and moving each element to reduce memory peak.+ // Elements of 'nodes' vector are nullptr after the std::move in the loop.+ auto nodes = model->get_ordered_ops();+ for (size_t n = 0; n < nodes.size(); ++n) {+ auto original_node = std::move(nodes[n]);auto node = original_node;if (!original_node->can_constant_fold(original_node->input_values())) {if (auto sub_graph_node = ov::as_type_ptr<ov::op::util::MultiSubGraphOp>(node)) {