llvm / torch-mlir

The Torch-MLIR project aims to provide first class support from the PyTorch ecosystem to the MLIR ecosystem.
Other
1.34k stars 501 forks source link

`Required keyword attribute 'weight_arr' is undefined` during `compile()` #1973

Open avdhoeke opened 1 year ago

avdhoeke commented 1 year ago

I would like to compile a simple nn.Conv2d module using the following MWE:

import torch
import torch_mlir

conv = torch.nn.Conv2d(
  in_channels=1, out_channels=1, kernel_size=3, stride=1, padding=0
).eval()

module = torch_mlir.compile(
    conv,
    example_args=torch.randn(1, 1, 8, 8),
    output_type=torch_mlir.OutputType.LINALG_ON_TENSORS,
    use_tracing=True
)

with open("conv.mlir", "w", encoding="utf-8") as outf:
    outf.write(str(module))

Which returns the following error message:

---------------------------------------------------------------------------
Exception                                 Traceback (most recent call last)
/tmp/ipykernel_2546622/2410432908.py in <cell line: 7>()
      5 ).eval()
      6 
----> 7 module = torch_mlir.compile(
      8     conv,
      9     example_args=torch.randn(1, 1, 8, 8),

~/.pyenv/versions/3.10.1/envs/mlir/lib/python3.10/site-packages/torch_mlir/__init__.py in compile(model, example_args, output_type, use_tracing, ignore_traced_shapes, backend_legal_ops, verbose)
    356         mb.import_module(scripted._c, class_annotator, import_options)
    357     except Exception as e:
--> 358         raise Exception(f"""
    359 PyTorch TorchScript module -> torch-mlir Object Graph IR import failed with:
    360 ### Importer C++ Exception:

Exception: 
PyTorch TorchScript module -> torch-mlir Object Graph IR import failed with:
### Importer C++ Exception:
required keyword attribute 'weight_arr' is undefined
### Importer Diagnostics:

############################################################################################

Additional information

############################################################################################

Am I doing something wrong?

ramiro050 commented 1 year ago

This error is usually due to a mismatch in the PyTorch version torch-mlir expects and the one that is actually present. You can see the expected PyTorch version expected for each torch-mlir version in the releases page: https://github.com/llvm/torch-mlir/releases