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

Fix DecomposeMultiDimSqueeze callback failure #52

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

meenakshiramanathan1
Copy link
Contributor

@meenakshiramanathan1 meenakshiramanathan1 commented Dec 10, 2024

Fixes #642

@@ -1883,6 +1883,8 @@ def __init__(self):
def callback(self, pre, post, node_map):
act = node_map[self.act][0]
axis = post.attrs.axis
if any([isinstance(dim, tvm.tir.expr.Any) for dim in pre.checked_type.shape]):
Copy link
Contributor

@dgolubovicTT dgolubovicTT Dec 12, 2024

Choose a reason for hiding this comment

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

Can you give some context in PR why the change? What is it solving...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@dgolubovicTT , this change fixes #642, the current status of this model is mentioned in the description here.

Copy link
Contributor

Choose a reason for hiding this comment

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

From what I understand, if any dimension is tvm.tir.expr.Any dimension size cannot be determined at compile-time. In that case we don't decompose multidimsqueeze? Am I right?
If that is true, shouldn't we give some warning? Also, I am curious what this multi-dim squeeze lowers later in the compiler? What is the last compile stage of this densenet model with this change included?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, in that case we skip removal of squeeze containing dynamic shapes, warning can be added. Squeeze op is supported in mlir as mentioned here.
Densenet model is failing with unsupported ops - argwhere and scatter_elements after this change

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, can you add a single squeeze test that will test this case, just to be sure everything after tvm will work.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These test cases for squeeze op were added as a part of this PR when DecomposeMultiDimSqueeze callback was added.

Copy link
Contributor

Choose a reason for hiding this comment

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

But is any of them actually testing this code path where this condition is not satisfied:

 if any([isinstance(dim, tvm.tir.expr.Any) for dim in pre.checked_type.shape]):

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will try this and let you know.

@nvukobratTT
Copy link
Contributor

@meenakshiramanathan1 can you provide a bit more context to this PR. Here are few questions I'm interested in:

  1. The one @dgolubovicTT already asked, are we testing this path? If no, let's try to reproduce this with simple op test.
  2. What are the results with and without your fix?
    • Before the change, you end up with failure in DecomposeMultiDimSqueeze
    • What about when you add this fix? Howe this multi-dim squeeze is further lowered in FFE, and latter on into MLIR? Can you share some reportify graphs for few compile stages (both TVM and FFE), as well a TTIR?
    • If you're unable to create simple unit test to cover this one, let's see screenshots from the original model.

@meenakshiramanathan1
Copy link
Contributor Author

meenakshiramanathan1 commented Dec 28, 2024

@meenakshiramanathan1 can you provide a bit more context to this PR. Here are few questions I'm interested in:

  1. The one @dgolubovicTT already asked, are we testing this path? If no, let's try to reproduce this with simple op test.

  2. What are the results with and without your fix?

    • Before the change, you end up with failure in DecomposeMultiDimSqueeze
    • What about when you add this fix? Howe this multi-dim squeeze is further lowered in FFE, and latter on into MLIR? Can you share some reportify graphs for few compile stages (both TVM and FFE), as well a TTIR?
    • If you're unable to create simple unit test to cover this one, let's see screenshots from the original model.
  1. Tried testing this path with dynamic inputs but in the all cases of trying to create dynamic inputs , it is ending up with formation of argwhere which is not supported in forge yet
    For example,
def test_dynamic_multi_squeeze(test_device):
    class Multi_Squeeze(torch.nn.Module):
        def __init__(self):
            super().__init__()

        def forward(self, input):
            mask = input > 5
            indices = torch.nonzero(mask)
            squeezed_tensor = indices.squeeze(0)
            return squeezed_tensor

Here non_zero is mapped to argwhere which was one of the cases which was tried, so if we want to test this out further , argwhere op tvm decomposition should be brought in.

Before fix , graps are dumped till relay passes.
Screenshot 2024-12-28 at 9 09 31 AM
While after fix, it is progressing till forge_passes
Screenshot 2024-12-28 at 9 09 37 AM

  1. With my fix , model is ending up with argwhere unsupported and without my fix, it would end up with this error.

  2. Screenshots from original model which is causing dynamic shapes:

Screenshot 2024-12-28 at 9 01 58 AM

@nvukobratTT
Copy link
Contributor

@meenakshiramanathan1

Tried testing this path with dynamic inputs but in the all cases of trying to create dynamic inputs , it is ending up with formation of argwhere which is not supported in forge yet

Thanks for the details! We're pushing the effort on outlining what and how our indexing should work.

Here non_zero is mapped to argwhere which was one of the cases which was tried, so if we want to test this out further , argwhere op tvm decomposition should be brought in.

Before fix , graps are dumped till relay passes.

Can you send actually screenshot of the graph? I'm interested in graph structure changes, rather than compile depth.

@meenakshiramanathan1
Copy link
Contributor Author

@meenakshiramanathan1

Tried testing this path with dynamic inputs but in the all cases of trying to create dynamic inputs , it is ending up with formation of argwhere which is not supported in forge yet

Thanks for the details! We're pushing the effort on outlining what and how our indexing should work.

Here non_zero is mapped to argwhere which was one of the cases which was tried, so if we want to test this out further , argwhere op tvm decomposition should be brought in.
Before fix , graps are dumped till relay passes.

Can you send actually screenshot of the graph? I'm interested in graph structure changes, rather than compile depth.

I will send this information.

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.

TypeError in DecomposeMultiDimSqueeze TVM callback in densenet xray variant
3 participants