torch-mlir icon indicating copy to clipboard operation
torch-mlir copied to clipboard

No module named 'torch_mlir._mlir_libs._jit_ir_importer'

Open MIONkb opened this issue 1 year ago • 3 comments

I installed torch-mlir with following script in my own conda env, where 20240825.194 is the newest torch-mlir in the url https://github.com/llvm/torch-mlir-release/releases/expanded_assets/dev-wheels

pip3 install --pre torch-mlir==20240825.194 torchvision \ -f https://github.com/llvm/torch-mlir-release/releases/expanded_assets/dev-wheels \ --extra-index-url https://download.pytorch.org/whl/nightly/cpu

Then I run the torchscript_resnet18_all_output_types.py in /projects/pt1/examples, then error happens:

File "/home/jhlou/Torchmlir/test/simple/torchscript_resnet18_all_output_types.py", line 9, in <module> from torch_mlir import torchscript File "/home/jhlou/anaconda3/lib/python3.11/site-packages/torch_mlir/torchscript.py", line 25, in <module> from torch_mlir.jit_ir_importer import ClassAnnotator, ImportOptions, ModuleBuilder File "/home/jhlou/anaconda3/lib/python3.11/site-packages/torch_mlir/jit_ir_importer/__init__.py", line 14, in <module> from .._mlir_libs._jit_ir_importer import * ModuleNotFoundError: No module named 'torch_mlir._mlir_libs._jit_ir_importer'

Acctually, when I check the anaconda3/lib/python3.11/site-packages/torch_mlir dir, the jit_ir_importer is not in 'torch_mlir._mlir_libs..

How could I install torch-mlir python package correctly? Or did I run it in a wrong way?

This is the "torchscript_resnet18_all_output_types.py"

`

import torch import torchvision

from torch_mlir import torchscript

resnet18 = torchvision.models.resnet18(pretrained=True) resnet18.eval()

module = torchscript.compile(resnet18, torch.ones(1, 3, 224, 224), output_type="torch") print("TORCH OutputType\n", module.operation.get_asm(large_elements_limit=10)) module = torchscript.compile( resnet18, torch.ones(1, 3, 224, 224), output_type="linalg-on-tensors" ) print( "LINALG_ON_TENSORS OutputType\n", module.operation.get_asm(large_elements_limit=10) )

module = torchscript.compile(resnet18, torch.ones(1, 3, 224, 224), output_type="tosa") print("TOSA OutputType\n", module.operation.get_asm(large_elements_limit=10))

`

MIONkb avatar Sep 09 '24 15:09 MIONkb

will be fixed by https://github.com/llvm/torch-mlir/pull/3693

AmosLewis avatar Sep 09 '24 23:09 AmosLewis

will be fixed by #3693

Thanks a lot!

MIONkb avatar Sep 10 '24 02:09 MIONkb

will be fixed by #3693

i got the same error for main branch.

my build command is "TORCH_MLIR_ENABLE_JIT_IR_IMPORTER=ON TORCH_MLIR_CMAKE_BUILD_DIR=build CMAKE_GENERATOR=Ninja python3 setup.py build_py",

and then run "python3 ./projects/pt1/examples/torchscript_resnet18.py".

will get the following error:

Traceback (most recent call last): File "/workspace/torch-env/torch-mlir/./projects/pt1/examples/torchscript_resnet18.py", line 11, in from torch_mlir import torchscript File "/workspace/torch-env/torch-mlir/build/tools/torch-mlir/python_packages/torch_mlir/torch_mlir/torchscript.py", line 24, in from torch_mlir.jit_ir_importer import ClassAnnotator, ImportOptions, ModuleBuilder File "/workspace/torch-env/torch-mlir/build/tools/torch-mlir/python_packages/torch_mlir/torch_mlir/jit_ir_importer/init.py", line 14, in from .._mlir_libs._jit_ir_importer import *

shangdehao1 avatar Jul 15 '25 10:07 shangdehao1