llvm / llvm/torch-mlir

error: failed to legalize operation 'torch.operator' that was explicitly marked illegal

Open
#4,575 3 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

When lowering some KernelBench programs (level1: 12, 96, 99), I get this error:

error: failed to legalize operation 'torch.operator' that was explicitly marked illegal

Reproducer:

  1. Clone Lighthouse
  2. Init uv as in README
  3. Run: $ uv run examples/KernelBench/test-kernel-bench.py --kernel level1/12_

Error message:

loc("/home/rengolin/devel/llvm/lighthouse/third_party/KernelBench/KernelBench/level1/12_Matmul_with_diagonal_matrices_.py":23:0): error: failed to legalize operation 'torch.operator' that was explicitly marked illegal
ERROR: got an error converting /home/rengolin/devel/llvm/lighthouse/third_party/KernelBench/KernelBench/level1/12_Matmul_with_diagonal_matrices_.py to MLIR:
...
stack trace
...
torch_mlir.compiler_utils.TorchMlirCompilerError: Lowering TorchFX IR -> Torch Backend IR failed with the following diagnostics:


python exception: Failure while executing pass pipeline

For Torch-MLIR developers, the error can be reproduced with:
$ torch-mlir-opt -pass-pipeline='builtin.module(func.func(torch-match-quantized-custom-ops), torchdynamo-export-to-torch-backend-pipeline{ extra-library=})' /tmp/UnnammedModule.mlir
Add '-mlir-print-ir-after-all -mlir-disable-threading' to get the IR dump for debugging purpose.

Kernel 12, Line 23 is:
return torch.diag(A) @ B

Kernel 96, line 15 is:
return torch.nn.functional.smooth_l1_loss(predictions, targets)

Kernel 99, line 16 is:
return self.loss_fn(anchor, positive, negative)

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

Reproduce the failure with the stated uv command for KernelBench level1/12, then compare the same torch-mlir-opt pass pipeline against the failing kernels 12, 96, and 99. Use the suggested IR dump flags and the referenced kernel lines to trace the illegal torch.operator; done means all three programs convert to MLIR without the legalization error.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, python
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.