Skip to content

[TorchOnnxToTorch] Generate unexpected unflatten for ScatterND #4699

Description

@vfdff
  • reproduce command: torch-mlir-opt -convert-torch-onnx-to-torch scatternd.mlir
  func.func @test_scatternd(
      %data: !torch.vtensor<[18,8,64,64],f32>,
      %indices: !torch.vtensor<[18,4,2],si64>,
      %updates: !torch.vtensor<[18,4,64,64],f32>
  ) -> !torch.vtensor<[18,8,64,64],f32>
  attributes {torch.onnx_meta.opset_version = 13 : si64} {
    %0 = torch.operator "onnx.ScatterND"(%data, %indices, %updates)
      : (!torch.vtensor<[18,8,64,64],f32>, !torch.vtensor<[18,4,2],si64>, !torch.vtensor<[18,4,64,64],f32>)
      -> !torch.vtensor<[18,8,64,64],f32>
    return %0 : !torch.vtensor<[18,8,64,64],f32>
  }
  • Now it generate following IR for last unflatten, whose indices is [18,8,64,64], so it is wrong (record issue 4686), and we expect the %25 = torch.prim.ListConstruct %0, %1 : (!torch.int, !torch.int) -> !torch.list
    %25 = torch.prim.ListConstruct %0, %1, %2, %3 : (!torch.int, !torch.int, !torch.int, !torch.int) -> !torch.list<int>
    %26 = torch.aten.unflatten.int %24, %int0_0, %25 : !torch.vtensor<[144,64,64],f32>, !torch.int, !torch.list<int> -> !torch.vtensor<[18,8,64,64],f32>
  • the related code is ScatterND, the dataDims are the full shape of the unflatten, but we expect it is the shape related to the dim0 only, maybe something like unflattenIndicesDims
SmallVector<Value> unflattenIndicesDims;
for (int64_t i = 0; i < indicesLastDim; ++i) {
   unflattenIndicesDims.push_back(dataDims[i]);
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions