-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR moves the following internal changes to OSS, **[tensorrt/test] Remove/modify incorrect INT4 test** This MR removes INT4 unit test from `TensorRT/TRT10/convolution.mlir` test. It worked before but doesn't work with TensorRT 10.7 anymore. Even though it worked before, INT4 Q/DQ (which is block quantization) is supported for 2D weights only. This MR also modifies matmul INT4 test from `TensorRT/TRT10/matrix-multiply.mlir` by making scale 2D to strictly follow block quantization specs. **Don't use `executor.opaque<...>` in TensorRTRuntime-to-Executor lowering** Eliminates the final uses of the `!executor.opaque<...>` type, which can be dropped from the Executor dialect in a future commit. **NFC: run isort and formatter on all python files** **[runtime] Improve Lua runtime organization** This change: - Removes 'sol' objects and header inclusions from Lua runtime interface headers. - Creates registration mechanism for all the Lua runtime "modules/extensions". This simplifies the interface for adding and maintaining the runtime extensions. In the future, it also allows for selectively loading extensions during session creation (not implemented in this change). - Removes misc dead code. **[compiler] Add support to compile PyTorch models** This MR enables compiling PyTorch models via Torch-MLIR. - Add `torch_bridge` module to the `mlir_tensorrt.compiler` package which takes in torch module along with necessary arguments and return MLIR IR (Stablehlo OR Linalg on tensors). - Add an example to e2e test Torch integration. **[compiler] update compiler python type stub, remove dead APIs** Updates the Python type stubs for PyBind11 modules. Corrects the naming of the "PyPassManagerReference" object and removes some APIs which are no longer needed. **NFC: [runtime] Create runtime C implementation 'CoreModule'** Creates an initial C implementation for functions under 'CoreModule' which will be needed for exposure to other (non-Lua) backend implementations, e.g. the LLVM JIT runtime. Marked 'NFC' since it is pure code movement. **[compiler] Improve pipeline setup and handling of printing/debug options** This commit makes the following changes in order to simplify the debugging experience when working through python vs. CLI: - Each compilation task options set now includes a full mirror of the debugging options available through MLIR CLI tools (e.g. `--mlir-print-ir-after-all`, --mlir-print-ir-tree-dir`, etc). This also includes options for display pass statistics and timing information (`--mlir-pass-statistics` and `--mlir-timing`). - Introduce a pass in the StablehloToExecutable pipeline to set the default 'plan.cluster_kinds' attribute on the module if it is not set by the frontend. This eliminates the special step present in 'stablehlo-to-executable' and allows us to remove the APIs specific to StablehloToExecutable at the frontend and replace them with use of `client.get_compilation_task`. **[compiler] Enable omitting options from MLIR CLI options when converting an OptionsContext** Allows tagging options of a derived `OptionsContext` in order to omit those options when converting to an `mlir::PassPipelineOptions` using the template adaptor. **[compiler] Improve organization of compiler tasks, reduce redundant options objects** This change: - Improves organization of compiler tasks by moving 'StablehloToExecutable' related files under its own sub directory. Adds a dedicated Tablegen file for the auxiliary passes needed by the StablehloToExecutable pipeline. - Adds an adaptor that allows using classes derived from 'OptionsContext' as `mlir::PassPipelineOptions`. This eliminates the need to keep redundant options definitions for MLIR pipelines registered for CLI tools. --------- Co-authored-by: Copybara Bot <[email protected]>
- Loading branch information
1 parent
b0d43f3
commit d341395
Showing
89 changed files
with
1,611 additions
and
863 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
mlir-tensorrt/build_tools/patches/torch_mlir/torch_mlir.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index 822afa0a..987c8bd2 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -44,6 +44,14 @@ if(TORCH_MLIR_ENABLE_STABLEHLO) | ||
add_definitions(-DTORCH_MLIR_ENABLE_STABLEHLO) | ||
endif() | ||
|
||
+# It is possible that both stablehlo and torch_mlir projects are used in some compiler project. | ||
+# In this case, we don't want to use stablehlo that is downloaded by torch_mlir (in external/stablehlo) | ||
+# folder but instead stablehlo that is part of top level compiler project. | ||
+# TORCH_MLIR_EXTERNAL_STABLEHLO_DIR represents stablehlo directory (<some_path>/stablehlo) | ||
+# that is included in torch_mlir. It is assumed that top level compiler project makes | ||
+# stablehlo targets available (for example with `add_subdirectory`) and thus they are not added. | ||
+set(TORCH_MLIR_EXTERNAL_STABLEHLO_DIR "" CACHE STRING "Path to stablehlo dir from super project") | ||
+ | ||
option(TORCH_MLIR_OUT_OF_TREE_BUILD "Specifies an out of tree build" OFF) | ||
|
||
# PyTorch native extension gate. If OFF, then no features which depend on | ||
@@ -142,7 +150,8 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) | ||
|
||
function(torch_mlir_target_includes target) | ||
set(_dirs | ||
- $<BUILD_INTERFACE:${MLIR_INCLUDE_DIRS}> | ||
+ $<BUILD_INTERFACE:${MLIR_INCLUDE_DIR}> | ||
+ $<BUILD_INTERFACE:${MLIR_GENERATED_INCLUDE_DIR}> | ||
$<BUILD_INTERFACE:${TORCH_MLIR_SOURCE_DIR}/include> | ||
$<BUILD_INTERFACE:${TORCH_MLIR_BINARY_DIR}/include> | ||
) | ||
@@ -233,12 +242,16 @@ endif() | ||
# project that we don't actually depend on. Further some of those parts | ||
# do not even compile on all platforms. | ||
if (TORCH_MLIR_ENABLE_STABLEHLO) | ||
- set(STABLEHLO_BUILD_EMBEDDED ON) | ||
- set(STABLEHLO_ENABLE_BINDINGS_PYTHON ON) | ||
- add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/externals/stablehlo | ||
- ${CMAKE_CURRENT_BINARY_DIR}/stablehlo | ||
- EXCLUDE_FROM_ALL) | ||
- include_directories(${CMAKE_CURRENT_SOURCE_DIR}/externals/stablehlo) | ||
+ if (NOT "${TORCH_MLIR_EXTERNAL_STABLEHLO_DIR}" STREQUAL "") | ||
+ include_directories(${TORCH_MLIR_EXTERNAL_STABLEHLO_DIR}) | ||
+ else() | ||
+ set(STABLEHLO_BUILD_EMBEDDED ON) | ||
+ set(STABLEHLO_ENABLE_BINDINGS_PYTHON ON) | ||
+ add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/externals/stablehlo | ||
+ ${CMAKE_CURRENT_BINARY_DIR}/stablehlo | ||
+ EXCLUDE_FROM_ALL) | ||
+ include_directories(${CMAKE_CURRENT_SOURCE_DIR}/externals/stablehlo) | ||
+ endif() | ||
endif() | ||
|
||
#------------------------------------------------------------------------------- | ||
diff --git a/lib/Conversion/TorchConversionToMLProgram/TorchConversionToMLProgram.cpp b/lib/Conversion/TorchConversionToMLProgram/TorchConversionToMLProgram.cpp | ||
index ddb6e5a5..22b95c8a 100644 | ||
--- a/lib/Conversion/TorchConversionToMLProgram/TorchConversionToMLProgram.cpp | ||
+++ b/lib/Conversion/TorchConversionToMLProgram/TorchConversionToMLProgram.cpp | ||
@@ -59,6 +59,12 @@ public: | ||
matchAndRewrite(GetNextSeedOp op, OpAdaptor adaptor, | ||
ConversionPatternRewriter &rewriter) const override { | ||
Location loc = op.getLoc(); | ||
+ // Find parent module to add global seed, if not present already. | ||
+ auto module = op->getParentOfType<ModuleOp>(); | ||
+ OpBuilder b(module.getBodyRegion()); | ||
+ if (failed(getOrCreateGlobalVariableForSeed(b, module))) | ||
+ return failure(); | ||
+ | ||
// Generate sequence for getting the next seed with LCG step: | ||
// nextSeed = (multiplier * currentSeed + incrementStep) mod 2^64. | ||
// Refer to https://en.wikipedia.org/wiki/Linear_congruential_generator. | ||
@@ -115,11 +121,6 @@ public: | ||
typeConverter.addConversion([](Type type) { return type; }); | ||
TorchConversion::setupBackendTypeConversion(target, typeConverter); | ||
|
||
- auto module = getOperation(); | ||
- OpBuilder b(module.getBodyRegion()); | ||
- if (failed(getOrCreateGlobalVariableForSeed(b, module))) | ||
- signalPassFailure(); | ||
- | ||
RewritePatternSet patterns(context); | ||
target.addIllegalOp<GetNextSeedOp>(); | ||
patterns.add<ConvertGetNextSeedOp>(typeConverter, context); | ||
diff --git a/python/torch_mlir/compiler_utils.py b/python/torch_mlir/compiler_utils.py | ||
index ecf129d7..cf07526e 100644 | ||
--- a/python/torch_mlir/compiler_utils.py | ||
+++ b/python/torch_mlir/compiler_utils.py | ||
@@ -10,8 +10,8 @@ import tempfile | ||
from typing import Union, List | ||
|
||
import torch | ||
-from torch_mlir.passmanager import PassManager | ||
-from torch_mlir.ir import StringAttr | ||
+from .passmanager import PassManager | ||
+from .ir import StringAttr | ||
|
||
|
||
class TensorPlaceholder: | ||
diff --git a/python/torch_mlir/fx.py b/python/torch_mlir/fx.py | ||
index cfe87348..5309f573 100644 | ||
--- a/python/torch_mlir/fx.py | ||
+++ b/python/torch_mlir/fx.py | ||
@@ -13,11 +13,11 @@ import torch.export | ||
import torch.nn as nn | ||
from torch.export import ExportedProgram | ||
|
||
-from torch_mlir.extras.fx_importer import FxImporter, FxImporterHooks | ||
-from torch_mlir import ir | ||
-from torch_mlir.dialects import torch as torch_d | ||
-from torch_mlir.extras.fx_decomp_util import get_decomposition_table | ||
-from torch_mlir.compiler_utils import ( | ||
+from .extras.fx_importer import FxImporter, FxImporterHooks | ||
+from . import ir | ||
+from .dialects import torch as torch_d | ||
+from .extras.fx_decomp_util import get_decomposition_table | ||
+from .compiler_utils import ( | ||
OutputType, | ||
run_pipeline_with_repro_report, | ||
lower_mlir_module, | ||
diff --git a/test/Conversion/TorchConversionToMLProgram/multiple_functions.mlir b/test/Conversion/TorchConversionToMLProgram/multiple_functions.mlir | ||
index 8ef04d95..da2424fc 100644 | ||
--- a/test/Conversion/TorchConversionToMLProgram/multiple_functions.mlir | ||
+++ b/test/Conversion/TorchConversionToMLProgram/multiple_functions.mlir | ||
@@ -11,5 +11,5 @@ module { | ||
func.func private @f7() -> i64 | ||
} | ||
|
||
-// CHECK: ml_program.global private mutable @global_seed(dense<0> : tensor<i64>) : tensor<i64> | ||
+// CHECK-NOT: ml_program.global private mutable @global_seed(dense<0> : tensor<i64>) : tensor<i64> | ||
// CHECK-NOT: @global_seed |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
add_subdirectory(Compiler) | ||
add_subdirectory(Dialect) | ||
add_subdirectory(Conversion) | ||
add_subdirectory(Transforms) |
1 change: 1 addition & 0 deletions
1
mlir-tensorrt/compiler/include/mlir-tensorrt/Compiler/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
add_subdirectory(StablehloToExecutable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
mlir-tensorrt/compiler/include/mlir-tensorrt/Compiler/StablehloToExecutable/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
set(_TABLEGEN_ARGS ) | ||
set(LLVM_TARGET_DEFINITIONS Passes.td) | ||
mlir_tablegen(Passes.h.inc -gen-pass-decls -name StablehloToExecutable ${_TABLEGEN_ARGS}) | ||
add_public_tablegen_target(MLIRTensorRTStablehloToExecutableIncGen) |
Oops, something went wrong.