Base build instructions lead to import error in tests (_mlir_libs._torchMlir not found)
Hi folks,
When trying to build torch-mlir following the provided instructions , I ran into unit test failures, specifically
TORCH_MLIR :: python/fx_importer/basic_test.py
TORCH_MLIR :: python/fx_importer/custom_op_test.py
TORCH_MLIR :: python/fx_importer/symbolic_shape_expr_test.py
TORCH_MLIR :: python/fx_importer/v2.3/auto_functionalized.py
TORCH_MLIR :: python/fx_importer/v2.3/mutation_import.py
TORCH_MLIR :: python/fx_importer/v2.3/special_forms_test.py
TORCH_MLIR :: python/fx_importer/v2.3/types_test.py
TORCH_MLIR :: python/onnx_importer/BadName.runlit
TORCH_MLIR :: python/onnx_importer/command_line_test.py
TORCH_MLIR :: python/onnx_importer/constants.py
TORCH_MLIR :: python/onnx_importer/function_expansion/GreaterOrEqual.runlit
TORCH_MLIR :: python/onnx_importer/function_expansion/ReduceSumSquare_keepdims=0.runlit
TORCH_MLIR :: python/onnx_importer/function_expansion/ReduceSumSquare_no_attrs.runlit
TORCH_MLIR :: python/onnx_importer/import_onnx_tool.runlit
TORCH_MLIR :: python/onnx_importer/import_smoke_test.py
All of which stem from
ModuleNotFoundError: No module named 'torch_mlir._mlir_libs._torchMlir'
This occurs with both the base and base + optimization instructions. The issue is resolved by explicitly adding
-DPython_FIND_VIRTUALENV=ONLY
to the CMake invocation (in addition to the existing -DPython3_FIND_VIRTUALENV=ONLY).
If it's helpful, I used Python 3.11 for the virtual environment.
I just ran into this issue as well and can confirm it and the solution provided. Build process was generating _torchMlir.cpython-3xx-x86_64-linux-gnu.so using the 'global' available python instead of the virtual env python. Adding the -D does generate the correct lib. I am using 3.12 stock python and 3.10 in the venv.
This is added to the development instructions in #4024 by the way.