Skip to content

Commit ab6e908

Browse files
mryzhovCopilotmitruska
authored
[TRANSFORMATIONS] Destroy constants after replacement in constant folding (#33961)
### Details: - Changed the for-each loop over `model->get_ordered_ops()` to an index-based for loop, using `std::move` to transfer ownership of each node from the `nodes` vector. That would allow us to destroy unused constants immediately and minimize the peak memory allocation. ### Tickets: - CVS-176571 --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Katarzyna Mitrus <katarzyna.mitrus@intel.com>
1 parent 647e952 commit ab6e908

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/core/src/pass/constant_folding.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ bool ov::pass::ConstantFolding::run_on_model(const std::shared_ptr<ov::Model>& m
106106

107107
bool rewritten = pre_calculated_values_folding(model);
108108

109-
for (const auto& original_node : model->get_ordered_ops()) {
109+
// Creating a local vector and moving each element to reduce memory peak.
110+
// Elements of 'nodes' vector are nullptr after the std::move in the loop.
111+
auto nodes = model->get_ordered_ops();
112+
for (size_t n = 0; n < nodes.size(); ++n) {
113+
auto original_node = std::move(nodes[n]);
110114
auto node = original_node;
111115
if (!original_node->can_constant_fold(original_node->input_values())) {
112116
if (auto sub_graph_node = ov::as_type_ptr<ov::op::util::MultiSubGraphOp>(node)) {

0 commit comments

Comments
 (0)