llvm / llvm/torch-mlir

Some failed ops when legalizing from torch to stablehlo

Open
#2,020 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
1.9k
Forks
736
Avg merge
5d 22h
Merged PRs (30d)
15

Description

Hi,
I'm experimenting with conversions of different pre-trained models to all 3 output dialects, and met 6 failures when converting to stablehlo. I'm showing the (simplified) examples below. Are this not implemented yet?
Note: some of these examples also fail when converting to tosa/linalg
Note2: examples with torch.constant depend on operations around the failing one: e.g. torch.constant.int 0 sometimes passes, sometimes fails.

1. error: failed to legalize operation 'torch.constant.int'
```
module attributes {torch.debug_module_name = "_lambda"} {
func.func @forward(%arg0: !torch.int) -> !torch.int {
%int0 = torch.constant.int 0
return %int0 : !torch.int
}
}
```

2.error: failed to legalize operation 'torch.constant.float'
```
module attributes {torch.debug_module_name = "_lambda"} {
func.func @forward(%arg0: !torch.float) -> !torch.float {
%float-Inf = torch.constant.float 0xFFF0000000000000
return %float-Inf : !torch.float
}
}
```

3.error: failed to legalize operation 'torch.aten.any'. (torch.constant.int 0 here seems ok!?)
```
module attributes {torch.debug_module_name = "_lambda"} {
func.func @forward(%arg0: !torch.vtensor<[2],si64>) -> !torch.vtensor<[],i1> {
%int0 = torch.constant.int 0
%0 = torch.aten.eq.Scalar %arg0, %int0 : !torch.vtensor<[2],si64>, !torch.int -> !torch.vtensor<[2],i1>
%1 = torch.aten.any %0 : !torch.vtensor<[2],i1> -> !torch.vtensor<[],i1>
return %1 : !torch.vtensor<[],i1>
}
}
```

4.error: failed to legalize operation 'torch.prim.ListConstruct'
```
module attributes {torch.debug_module_name = "_lambda"} {
func.func @forward(%arg0: !torch.vtensor<[1],si64>) -> !torch.list> {
%1 = torch.prim.ListConstruct %arg0 : (!torch.vtensor<[1],si64>) -> !torch.list>
return %1 : !torch.list>
}
}
```

5.error: failed to legalize operation 'torch.aten.detach'
```
module attributes {torch.debug_module_name = "_lambda"} {
func.func @forward(%arg0: !torch.vtensor<[1],si64>) -> !torch.vtensor<[1],si64> {
%0 = torch.aten.detach %arg0 : !torch.vtensor<[1],si64> -> !torch.vtensor<[1],si64>
return %0 : !torch.vtensor<[1],si64>
}
}
```

6.error: failed to legalize operation 'torch.aten.pow.Tensor_Tensor'
```
module attributes {torch.debug_module_name = "_lambda"} {
func.func @forward(%arg0: !torch.vtensor<[1,801,33],f32>, %arg1: !torch.vtensor<[],f32>) -> !torch.vtensor<[1,801,33],f32> {
%1 = torch.aten.pow.Tensor_Tensor %arg0, %arg1 : !torch.vtensor<[1,801,33],f32>, !torch.vtensor<[],f32> -> !torch.vtensor<[1,801,33],f32>
return %1 : !torch.vtensor<[1,801,33],f32>
}
}
```

I'm using standard command
torch-mlir-opt -pass-pipeline='builtin.module(torch-backend-to-stablehlo-backend-pipeline)'
All examples are reproduced on today's fresh torch-mlir.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running torch-mlir-opt with the torch-backend-to-stablehlo-backend-pipeline on the six minimized MLIR examples in the issue. No source file or test is named; done would mean determining which reported operations are expected to legalize successfully and adding coverage for the confirmed failures.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.