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

Support AtenNonzeroOp via DecomposeComplexOps #3721

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

renxida
Copy link
Collaborator

@renxida renxida commented Sep 20, 2024

Implements part of: #3293

Uses logic by GPetters from #615

Prototyped on google colab in this notebook

@renxida renxida marked this pull request as draft September 20, 2024 18:24
@renxida
Copy link
Collaborator Author

renxida commented Sep 20, 2024

@gpetters94 does some shape-related things in his previous attempt at this op that I don't understand. I think I should maybe replicate those. Specifically:

  1. The input is flattened coming into the decomposition: 33f9101#diff-bec402e56f7c88a9b22018c90df7e9ca721bdd097d4ffdd7c13d9d3f4c2e0688R681-R686

  2. There is some stacking / transposing that I don't do: 33f9101#diff-bec402e56f7c88a9b22018c90df7e9ca721bdd097d4ffdd7c13d9d3f4c2e0688R764-R769

@lionsky
Copy link

lionsky commented Oct 16, 2024

Using below testcase, it seems to generate illegal aten.slice.Tensor

func.func @test_nonzero(%1199 : !torch.vtensor<[2,5],si64>) -> !torch.vtensor<[?,2],si64> {
    %1200 = torch.aten.nonzero %1199 : !torch.vtensor<[2,5],si64> -> !torch.vtensor<[?,2],si64>
    return %1200 : !torch.vtensor<[?,2],si64>

}

command line to reproduce

 torch-mlir-opt -pass-pipeline='builtin.module(func.func(torch-decompose-complex-ops),torch-backend-to-linalg-on-tensors-backend-pipeline)' nonzero.mlir

from the debug, one SliceTensor is illegal, since the slice dim is >= input rank.

  * Pattern : 'torch.aten.slice.Tensor -> ()' {
Trying to match "(anonymous namespace)::ConvertAtenSliceTensorOp"
    ** Insert  : 'arith.constant'(0x55651ccbcd90)
    ** Insert  : 'arith.constant'(0x55651ccbeea0)
    ** Insert  : 'arith.constant'(0x55651ccbef10)
    ** Failure : dim is statically invalid
"(anonymous namespace)::ConvertAtenSliceTensorOp" result 0
  } -> FAILURE : pattern failed to match

%20 rank is 1, but the dim is also %int1

%21 = torch.aten.slice.Tensor %20, %int1, %int1, %int2, %int1 : !torch.vtensor<[2],si64>, !torch.int, !torch.int, !torch.int, !torch.int -> !torch.vtensor<[1],si64>

Do you have any suggestion? @renxida

@lionsky
Copy link

lionsky commented Oct 16, 2024

It seems the second slice tensor should happen at the zero dimension, since the strides tensor is 1-D tensor

    Value slicedStrides = rewriter.create<AtenSliceTensorOp>(
        loc, slicedStrideType, flippedCumulativeProduct, /*dim*/ c(0),
        /*start=*/strideSliceStart, /*end=*/strideSliceEnd, /*step=*/c(1));

@renxida
Copy link
Collaborator Author

renxida commented Oct 18, 2024

on this one today while Stella looks at my shortfin thing.

@renxida
Copy link
Collaborator Author

renxida commented Oct 18, 2024

@lionsky nice catch. i'll fix this one!

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.

2 participants