Repository navigation
Fix tf.reshape() to reject multiple -1 dims consistently - #125093
Merged
copybara-service[bot] merged 2 commits intoAug 13, 2026
Merged
copybara-service[bot] merged 2 commits into
copybara-service[bot] merged 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the shape inference logic for the Reshape operator to eagerly detect and reject shapes containing multiple unknown dimensions (i.e., more than one -1). However, the reviewer identified a critical regression: a dimension can be marked as unknown if the target shape tensor is dynamic and not statically constant, rather than explicitly being -1. Unconditionally raising an error in this case would break valid dynamic reshapes. The feedback recommends only raising the error when the shape tensor is a known constant and adding a corresponding test case to prevent future regressions.
AnupamKumar-1
force-pushed
the
fix-reshape-multiple-unknown-dims-124877
branch
from
August 11, 2026 19:29
a509f38 to
881a33b
Compare
AnupamKumar-1
force-pushed
the
fix-reshape-multiple-unknown-dims-124877
branch
from
August 12, 2026 10:25
881a33b to
a33eaa6
Compare
dmiltr3
self-requested a review
August 12, 2026 18:23
dmiltr3
approved these changes
Aug 12, 2026
Contributor
Author
|
@nithyak0204 , Could you please re-trigger the Windows CI check when convenient? Thanks! |
copybara-service
Bot
merged commit Aug 13, 2026
e27935d
into
tensorflow:master
16 of 17 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #124877
tf.reshape() only allows one component of shape to be -1 (per its
docstring), but the multi-unknown-dim check in shape inference was
nested inside a rank-known branch for the input tensor, so it was
skipped whenever the input's rank wasn't statically known at trace
time. Eager mode and jit_compile=True both correctly reject reshapes
with two -1 dims, but XLA autoclustering hit this skipped path and
silently returned a result instead of raising.
The check for multiple unknown dims in the target shape now runs
unconditionally in SetOutputShapeForReshape, before the input-rank
branch, so all three paths raise the same
"Only one input size may be -1, not both X and Y" error.
Added regression tests in array_ops_test.cc covering: unknown input
rank with two -1s, two -1s at non-adjacent positions, and the exact
shapes from #124877.