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

[TorchToLinalg] Incorrect lowering for simple dynamic collapse in aten.view #3852

Open
zjgarvey opened this issue Nov 4, 2024 · 1 comment
Assignees

Comments

@zjgarvey
Copy link
Collaborator

zjgarvey commented Nov 4, 2024

The following IR is incorrectly lowered to linalg:

func.func @main_graph(%arg0: !torch.vtensor<[?,?,768],f32>) -> !torch.vtensor<[?,768],f32> {
  %int-1 = torch.constant.int -1
  %int768 = torch.constant.int 768
  %42 = torch.prim.ListConstruct %int-1, %int768 : (!torch.int, !torch.int) -> !torch.list<int>
  %43 = torch.aten.view %arg0, %42 : !torch.vtensor<[?,?,768],f32>, !torch.list<int> -> !torch.vtensor<[?,768],f32>
  return %43 : !torch.vtensor<[?,768],f32>
}

This converts to:

module {
  func.func @main_graph(%arg0: !torch.vtensor<[?,?,768],f32>) -> !torch.vtensor<[?,768],f32> {
    %0 = torch_c.to_builtin_tensor %arg0 : !torch.vtensor<[?,?,768],f32> -> tensor<?x?x768xf32>
    %int-1 = torch.constant.int -1
    %int768 = torch.constant.int 768
    %1 = torch.prim.ListConstruct %int-1, %int768 : (!torch.int, !torch.int) -> !torch.list<int>
    %c0 = arith.constant 0 : index
    %dim = tensor.dim %0, %c0 : tensor<?x?x768xf32>
    %c1 = arith.constant 1 : index
    %dim_0 = tensor.dim %0, %c1 : tensor<?x?x768xf32>
    %c2 = arith.constant 2 : index
    %c768 = arith.constant 768 : index
    %c-1_i64 = arith.constant -1 : i64
    %c768_i64 = arith.constant 768 : i64
    %cast = tensor.cast %0 : tensor<?x?x768xf32> to tensor<?x1x768xf32>
    %collapsed = tensor.collapse_shape %cast [[0], [1, 2]] : tensor<?x1x768xf32> into tensor<?x768xf32>
    %2 = torch_c.from_builtin_tensor %collapsed : tensor<?x768xf32> -> !torch.vtensor<[?,768],f32>
    return %2 : !torch.vtensor<[?,768],f32>
  }
}

It seems the lowering is unable to figure out that the back dim is untouched, and that the two dynamic dims are supposed to be flattened.

@zjgarvey
Copy link
Collaborator Author

zjgarvey commented Nov 4, 2024

I found this issue when debugging the IREE runtime failures for the model model--finetuned_distilgpt2_sst2_negation0.0001_pretrainedTrue_epochs1--jhaochenz in our onnx test suite.

@zjgarvey zjgarvey self-assigned this Nov 4, 2024
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

No branches or pull requests

1 participant