Created
December 15, 2022 21:30
-
-
Save AmosLewis/2f18434397025211da4491735bcc6db6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func.func @torch.aten.gather(%arg0: !torch.vtensor<[1,4,3],f32>, %arg1: !torch.vtensor<[1,4,2],si64>) -> !torch.vtensor<[1,4,2],f32> { | |
%int-1 = torch.constant.int -1 | |
%false = torch.constant.bool false | |
%0 = torch.aten.gather %arg0, %int-1, %arg1, %false : !torch.vtensor<[1,4,3],f32>, !torch.int, !torch.vtensor<[1,4,2],si64>, !torch.bool -> !torch.vtensor<[1,4,2],f32> | |
return %0 : !torch.vtensor<[1,4,2],f32> | |
} |
Author
AmosLewis
commented
Dec 15, 2022
•
➜ torch-mlir git:(gather-deberta) ✗ torch-mlir-opt -convert-torch-to-tosa /tmp/gathernd_torch.mlir
module {
func.func @torch.aten.gather(%arg0: !torch.vtensor<[1,4,3],f32>, %arg1: !torch.vtensor<[1,4,2],si64>) -> !torch.vtensor<[1,4,2],f32> {
%0 = torch_c.to_builtin_tensor %arg0 : !torch.vtensor<[1,4,3],f32> -> tensor<1x4x3xf32>
%1 = torch_c.to_builtin_tensor %arg1 : !torch.vtensor<[1,4,2],si64> -> tensor<1x4x2xi64>
%int-1 = torch.constant.int -1
%false = torch.constant.bool false
%2 = "tosa.reshape"(%1) {new_shape = [1, 4, 2, 1]} : (tensor<1x4x2xi64>) -> tensor<1x4x2x1xi64>
%3 = "tosa.cast"(%2) : (tensor<1x4x2x1xi64>) -> tensor<1x4x2x1xi32>
%4 = "tosa.const"() {value = dense<0> : tensor<1x4x2x1xi32>} : () -> tensor<1x4x2x1xi32>
%5 = "tosa.const"() {value = dense<[[[[0], [0]], [[1], [1]], [[2], [2]], [[3], [3]]]]> : tensor<1x4x2x1xi32>} : () -> tensor<1x4x2x1xi32>
%6 = "tosa.concat"(%4, %5, %3) {axis = 3 : i64} : (tensor<1x4x2x1xi32>, tensor<1x4x2x1xi32>, tensor<1x4x2x1xi32>) -> tensor<1x4x2x3xi32>
%7 = "tosa.reshape"(%0) {new_shape = [1, 12, 1]} : (tensor<1x4x3xf32>) -> tensor<1x12x1xf32>
%8 = "tosa.reshape"(%6) {new_shape = [8, 3]} : (tensor<1x4x2x3xi32>) -> tensor<8x3xi32>
%9 = "tosa.const"() {value = dense<[12, 3, 1]> : tensor<3xi32>} : () -> tensor<3xi32>
%10 = "tosa.mul"(%8, %9) {shift = 0 : i32} : (tensor<8x3xi32>, tensor<3xi32>) -> tensor<8x3xi32>
%11 = "tosa.reduce_sum"(%10) {axis = 1 : i64} : (tensor<8x3xi32>) -> tensor<8x1xi32>
%12 = "tosa.reshape"(%11) {new_shape = [1, 8]} : (tensor<8x1xi32>) -> tensor<1x8xi32>
%13 = "tosa.gather"(%7, %12) : (tensor<1x12x1xf32>, tensor<1x8xi32>) -> tensor<1x8x1xf32>
%14 = "tosa.reshape"(%13) {new_shape = [1, 4, 2]} : (tensor<1x8x1xf32>) -> tensor<1x4x2xf32>
%15 = torch_c.from_builtin_tensor %14 : tensor<1x4x2xf32> -> !torch.vtensor<[1,4,2],f32>
return %15 : !torch.vtensor<[1,4,2],f32>
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment