Skip to content

[TRANSFORMATIONS] Destroy constants after replacement in constant folding#33961

Open
mryzhov wants to merge 13 commits intoopenvinotoolkit:masterfrom
mryzhov:constant_folding_oom_fix
Open

[TRANSFORMATIONS] Destroy constants after replacement in constant folding#33961
mryzhov wants to merge 13 commits intoopenvinotoolkit:masterfrom
mryzhov:constant_folding_oom_fix

Conversation

@mryzhov
Copy link
Contributor

@mryzhov mryzhov commented Feb 4, 2026

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:

  • 176571

@mryzhov mryzhov requested a review from Copilot February 4, 2026 09:34
@mryzhov mryzhov requested review from a team as code owners February 4, 2026 09:34
@github-actions github-actions bot added the category: Core OpenVINO Core (aka ngraph) label Feb 4, 2026
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR modifies the constant folding pass to use a deque-based iteration approach instead of a range-based for loop, allowing for dynamic modification of the node processing queue. The change also adds an early exit condition in the can_constant_fold method to check if a node has an evaluate method before attempting constant folding.

Changes:

  • Modified the main loop in ConstantFolding::run_on_model to use a deque instead of iterating directly over ordered operations
  • Added has_evaluate() check to can_constant_fold to prevent folding attempts on nodes without evaluation capability

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/core/src/pass/constant_folding.cpp Replaced range-based for loop with deque-based iteration pattern, adding explicit pop_front() calls
src/core/src/node.cpp Added early return condition in can_constant_fold to check for evaluate method existence

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mryzhov mryzhov self-assigned this Feb 4, 2026
mryzhov and others added 2 commits February 4, 2026 10:44
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mryzhov mryzhov requested a review from Copilot February 4, 2026 10:10
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mryzhov mryzhov requested a review from Copilot February 4, 2026 10:55
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mryzhov mryzhov requested a review from Copilot February 4, 2026 12:41
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mryzhov mryzhov changed the title [DRAFT][TRANSFORMATIONS]Destroy constants after replacement in constant folding [TRANSFORMATIONS] Destroy constants after replacement in constant folding Feb 5, 2026
@mryzhov mryzhov requested a review from praasz February 5, 2026 12:36
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: Core OpenVINO Core (aka ngraph)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants