Redefine TorchMLIRPythonModules to avoid building empty libraries. (#3711)

Trying to build empty libraries causes weird failures based on clang/gcc
and doesn't work with certain versions of python as well. We should
avoid this wherever possible, and this specifically has been leading to
the following issues/failures:

https://github.com/llvm/torch-mlir/issues/3663

https://github.com/llvm/torch-mlir-release/actions/runs/10558518843/job/29248139823
pull/3712/head
saienduri 2024-09-13 10:41:34 -07:00 committed by GitHub
parent bc70c50373
commit d6cf718f10
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 5 deletions

View File

@ -51,6 +51,9 @@ option(TORCH_MLIR_OUT_OF_TREE_BUILD "Specifies an out of tree build" OFF)
# But it will be manually enabled in CI build to enable the jit_ir_importer.build_tools.torch_ods_gen # But it will be manually enabled in CI build to enable the jit_ir_importer.build_tools.torch_ods_gen
# and abstract_interp_lib_gen.py. Once pure python version of build_tools finished, no need to set it in CI. # and abstract_interp_lib_gen.py. Once pure python version of build_tools finished, no need to set it in CI.
option(TORCH_MLIR_ENABLE_PYTORCH_EXTENSIONS "Enables PyTorch native extension features" OFF) option(TORCH_MLIR_ENABLE_PYTORCH_EXTENSIONS "Enables PyTorch native extension features" OFF)
if(TORCH_MLIR_ENABLE_PYTORCH_EXTENSIONS)
add_definitions(-DTORCH_MLIR_ENABLE_PYTORCH_EXTENSIONS)
endif()
# NOTE: The JIT_IR_IMPORTER paths have become unsupportable due to age and lack of maintainers. # NOTE: The JIT_IR_IMPORTER paths have become unsupportable due to age and lack of maintainers.
# Turning this off disables the old TorchScript path, leaving FX based import as the current supported option. # Turning this off disables the old TorchScript path, leaving FX based import as the current supported option.
# The option will be retained for a time, and if a maintainer is interested in setting up testing for it, # The option will be retained for a time, and if a maintainer is interested in setting up testing for it,

View File

@ -96,16 +96,18 @@ set(_source_components
TorchMLIRPythonSources TorchMLIRPythonSources
TorchMLIRPythonExtensions TorchMLIRPythonExtensions
TorchMLIRSiteInitialize TorchMLIRSiteInitialize
# Sources related to optional Torch extension dependent features. Typically
# empty unless if project features are enabled.
TorchMLIRPythonTorchExtensionsSources
) )
if(TORCH_MLIR_ENABLE_STABLEHLO) if(TORCH_MLIR_ENABLE_STABLEHLO)
list(APPEND _source_components StablehloPythonExtensions) list(APPEND _source_components StablehloPythonExtensions)
endif() endif()
# Sources related to optional Torch extension dependent features. Typically
# empty unless if project features are enabled.
if(TORCH_MLIR_ENABLE_PYTORCH_EXTENSIONS)
list(APPEND _source_components TorchMLIRPythonTorchExtensionsSources)
endif()
add_mlir_python_common_capi_library(TorchMLIRAggregateCAPI add_mlir_python_common_capi_library(TorchMLIRAggregateCAPI
INSTALL_COMPONENT TorchMLIRPythonModules INSTALL_COMPONENT TorchMLIRPythonModules
INSTALL_DESTINATION python_packages/torch_mlir/torch_mlir/_mlir_libs INSTALL_DESTINATION python_packages/torch_mlir/torch_mlir/_mlir_libs

View File

@ -75,7 +75,7 @@ PACKAGE_VERSION = os.getenv("TORCH_MLIR_PYTHON_PACKAGE_VERSION", "0.0.1")
# If true, enable LTC build by default # If true, enable LTC build by default
TORCH_MLIR_ENABLE_LTC = _check_env_flag("TORCH_MLIR_ENABLE_LTC", True) TORCH_MLIR_ENABLE_LTC = _check_env_flag("TORCH_MLIR_ENABLE_LTC", True)
TORCH_MLIR_ENABLE_ONLY_MLIR_PYTHON_BINDINGS = _check_env_flag( TORCH_MLIR_ENABLE_ONLY_MLIR_PYTHON_BINDINGS = _check_env_flag(
"TORCH_MLIR_ENABLE_ONLY_MLIR_PYTHON_BINDINGS", False "TORCH_MLIR_ENABLE_ONLY_MLIR_PYTHON_BINDINGS", True
) )
LLVM_INSTALL_DIR = os.getenv("LLVM_INSTALL_DIR", None) LLVM_INSTALL_DIR = os.getenv("LLVM_INSTALL_DIR", None)
SRC_DIR = pathlib.Path(__file__).parent.absolute() SRC_DIR = pathlib.Path(__file__).parent.absolute()