Skip to content
This repository was archived by the owner on Jul 1, 2025. It is now read-only.
This repository was archived by the owner on Jul 1, 2025. It is now read-only.

[GraphOptimizer] Reshape sinking #5247

@aturetsk

Description

@aturetsk

While Reshape nodes are noops and do not directly contribute to model execution time, having them in a graph might prevent other optimizations/transformations from happening. So, sinking Reshapes (similar to Transposes) and merging them might potentially lead to better optimized graph.

One particular use case I encountered is coming from OptimizeTransposeIntoReshape optimization (#2630). There was a Transpose in a graph which Glow wasn't able to optimize out in a single glow::optimize run, so it sank till a specific point and then became a Reshape. On the next glow::optimize iteration, while conditions for further Transpose sinking were satisfied, it didn't happen because it was a Reshape now, not Transpose. Having Reshape sinking logic along with Transpose sinking should help to resolve such cases.

So, does it make sense to have Reshape sinking transformations in GraphOptimizer?

Also, I've noticed there is a transformation in Glow which is opposite to Reshape sinking - Reshape hoisting over Clip (#4074). @jfix71, could you give any comment on why we would do that?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions