llvm / llvm/torch-mlir

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

Open
#1,973 1 comment 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

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

  • PyTorch version: 2.0.0+cu117
  • Torch-MLIR version: 20230324.787

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

Am I doing something wrong?

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 reproducing the provided MWE with torch_mlir.compile and the shown nn.Conv2d configuration. Trace the importer path identified in the traceback, including torch_mlir/init.py, to find why the required weight_arr attribute is missing. Done means the MWE compiles successfully and emits the expected MLIR without the importer exception.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
compilers, machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.