Skip to content

not shrink rank of shape when unroll tensor iterator#36381

Open
michal-miotk wants to merge 4 commits into
openvinotoolkit:masterfrom
michal-miotk:fix_unroll
Open

not shrink rank of shape when unroll tensor iterator#36381
michal-miotk wants to merge 4 commits into
openvinotoolkit:masterfrom
michal-miotk:fix_unroll

Conversation

@michal-miotk

Copy link
Copy Markdown
Contributor

Details:

  • creating constants from parameter with scalar unconditionally may leads to lowering rank of output of indices input rank fragile
    gather
image

Tickets:

  • 186471

@michal-miotk michal-miotk requested a review from a team as a code owner June 12, 2026 13:34
@github-actions github-actions Bot added the category: transformations OpenVINO Runtime library - Transformations label Jun 12, 2026

@CuriousPanCake CuriousPanCake left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you please provide a better title/description of the PR? Also, it would be good to see a test and an example of what's happening

@michal-miotk michal-miotk changed the title not lose shape when unroll tensor iterator not shrink rank of shape when unroll tensor iterator Jun 24, 2026

@CuriousPanCake CuriousPanCake left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM
@praasz please take a look

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes a shape-rank regression in the UnrollTensorIterator transformation when replacing the Loop body’s current_iteration parameter with a Constant, ensuring the replacement preserves the original parameter rank (avoiding accidental scalarization that can break shape-sensitive ops like Gather).

Changes:

  • Update UnrollTensorIterator to create the replacement current_iteration Constant using the original parameter shape (instead of always using scalar {}).
  • Add a regression test that validates the replacement Constant rank and resulting Gather output rank remain unchanged after unrolling.

Reviewed changes

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

File Description
src/common/transformations/tests/control_flow/unroll_tensor_iterator_test.cpp Adds a regression test covering shape-rank preservation for current_iteration replacement and Gather output after unrolling.
src/common/transformations/src/transformations/control_flow/unroll_tensor_iterator.cpp Adjusts current_iteration replacement Constant construction to use the parameter’s shape (rank-preserving behavior).

Comment on lines +196 to +198
auto cur_iter_const = std::make_shared<v0::Constant>(param_to_delete->get_element_type(),
param_to_delete->get_shape(),
idx);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

according to doc: Trip count: A scalar or 1D tensor with 1 element of int64 or int32 type specifying maximum number of iterations. source: https://docs.openvino.ai/2026/documentation/openvino-ir-format/operation-sets/operation-specs/infrastructure/loop-5.html I don't think that above code is needed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If this is Parameter it can be also defined as PartialShape::dynamic() which mean it can be 1D, but get_shape will not work.
@CuriousPanCake
Or the dynamic shape is not possible here?

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

Labels

category: transformations OpenVINO Runtime library - Transformations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants