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

Fixing reshape op so it supports reshaping of scalars #1322

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

ajakovljevicTT
Copy link
Contributor

As described in #1306, tt-xla produces some reshapes on scalars which are currently not supported by our stableHLO to TTIR dialect lowering (issue #1317). In addition, tt-metal currently throws an error when trying to reshape to a 1-dimensional shape (issue tenstorrent/tt-metal#15201).

To fix both of these issues and fully support scalar testing on tt-xla, I've ingested some of the changes from @mmanzoorTT 's change (#1319) - will merge this PR after it. In addition, I've added that the reshape lowering pass omits the ttir.reshape op completely if the types of the input op and the target shape are the same, which will fix the unnecessary calls to the ttnn reshape op from tt-xla.

Fixes #1306

@kmitrovicTT
Copy link
Contributor

Run

> pre-commit install
> pre-commit run --all-files

to fix failing check.

@mmanzoorTT
Copy link
Contributor

There is another PR (PR #1252 by @uazizTT) for handling the same issue for broadcast op (remove redundant ops). These two PRs are handling the same problem in two different location. Redundant broadcast op is removed in TTIR->TTIR conversion pass, whereas redundant reshape op is removed in StableHLO->TTIR conversion pass. These two PRs should remove redundant ops in a consistent way.

@mmanzoorTT
Copy link
Contributor

Please add some tests for these changes.

@@ -50,6 +50,10 @@ struct TTIRToTTIRDecompositionPass
target.addIllegalOp<ttir::ConvolutionOp>();
target.addIllegalOp<ttir::GetDimensionSizeOp>();
target.addIllegalOp<ttir::PoolingOp>();
target.addDynamicallyLegalOp<ttir::ReshapeOp>([](ttir::ReshapeOp op) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a need for this? Do you not want to design it in such a way that this reshape op is either deleted specifically or removed by remove-dead-values pass?

Copy link
Contributor Author

@ajakovljevicTT ajakovljevicTT Nov 19, 2024

Choose a reason for hiding this comment

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

As I have implemented the pattern inside the TTIRtoTTIRDecompositionPass, I have to mark the ReshapeOp conditionally illegal, so that the pattern will actually try to match the op. The other possible solution is to make a transform pass from scratch, as was done in #1252. Since we currently do not have a dedicated transformations pass, I put it here, but I am open to changing that and making a transformations pass folder.

@ajakovljevicTT
Copy link
Contributor Author

ajakovljevicTT commented Nov 19, 2024

There is another PR (PR #1252 by @uazizTT) for handling the same issue for broadcast op (remove redundant ops). These two PRs are handling the same problem in two different location. Redundant broadcast op is removed in TTIR->TTIR conversion pass, whereas redundant reshape op is removed in StableHLO->TTIR conversion pass. These two PRs should remove redundant ops in a consistent way.

The reshape of here is remove in the TTIR->TTIR decomposition, which is currently a part of the larger TTIR->TTNN conversion, not StableHLO->TTIR. Will look into the referenced PR to get the idea how it is solved there.
I personally prefer the elimination to happen in the TTIR->TTNN part of the pipeline, as it then doesn't disturb the simple StableHLO->TTIR conversion that we agreed on.

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

Successfully merging this pull request may close these issues.

TT-xla not supporting scalar values
4 participants