Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reshape should take each shape dimension as a separate input #881

Open
ricardoV94 opened this issue Jul 4, 2024 · 0 comments
Open

Reshape should take each shape dimension as a separate input #881

ricardoV94 opened this issue Jul 4, 2024 · 0 comments

Comments

@ricardoV94
Copy link
Member

ricardoV94 commented Jul 4, 2024

Description

Reshape has only two inputs, x, and a vector of the output shape. This is cumbersome because many times we want to analyze the individual dimensions to rewrite Reshape as expand_dims or get rid of useless Reshape. Also the Reshape Op needs to be parametrized with the output length, because historically we didn't have static shapes, and couldn't always guess how many entries the shape vector had.

Most times Reshape is used to concatenate dimensions, so we end up with stuff like [x.shape[0], ..., x.shape[n] * x.shape[m], ..., x.shape[-1]], wrapped in a MakeVector. This makes Resahpe rewrites harder because they have to handle the case where things are joined in a MakeVector or may have been constant folded into a single tensor.

# Since output_shape is a symbolic vector, we trust extract_constant
# to go through however it is formed to see if its i-th element is 1.
# We need only_process_constants=False for that.
dim = extract_constant(
output_shape[i], only_process_constants=False, elemwise=False
)

SpecifyShape already works with a variable number of inputs and we haven't any trouble with it.

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

No branches or pull requests

1 participant