From 4f9f82da83d5d2e3bd4499efe9f870c66120b484 Mon Sep 17 00:00:00 2001 From: Sagar Shelke Date: Tue, 14 Jan 2025 11:37:04 -0800 Subject: [PATCH 1/2] [cmake] Enable accepting external stablehlo project (#3927) This MR enables `torch_mlir` project to accept path to external stablehlo and include those directories. This in turn enables `torch_mlir` to be part of bigger compiler project when `stablehlo` is already a dependency. --- CMakeLists.txt | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 822afa0af17e..d65bf3d9ba59 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -43,6 +43,12 @@ option(TORCH_MLIR_ENABLE_STABLEHLO "Add stablehlo dialect" ON) 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 want to use stablehlo that is part of top level compiler project. +# With TORCH_MLIR_USE_EXTERNAL_STABLEHLO enables, it is assumed that top level compiler project makes +# stablehlo targets AND includes available (for example with `add_subdirectory` and `include_directories`). +option(TORCH_MLIR_USE_EXTERNAL_STABLEHLO "Use stablehlo from top level project" OFF) option(TORCH_MLIR_OUT_OF_TREE_BUILD "Specifies an out of tree build" OFF) @@ -142,7 +148,8 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}/include) function(torch_mlir_target_includes target) set(_dirs - $ + $ + $ $ $ ) @@ -232,7 +239,8 @@ endif() # Getting this wrong results in building large parts of the stablehlo # 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) +# Only configure StableHLO if it isn't provided from a top-level project +if (TORCH_MLIR_ENABLE_STABLEHLO AND NOT TORCH_MLIR_USE_EXTERNAL_STABLEHLO) set(STABLEHLO_BUILD_EMBEDDED ON) set(STABLEHLO_ENABLE_BINDINGS_PYTHON ON) add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/externals/stablehlo From 09af3b6030d8d0c0ee8a80840734224d5c4b82a3 Mon Sep 17 00:00:00 2001 From: Sambhav Jain Date: Tue, 14 Jan 2025 13:04:27 -0800 Subject: [PATCH 2/2] Clarify `min_val` semantics for `torch.symbolic_int` op (#3959) Addresses #3938 . --- include/torch-mlir/Dialect/Torch/IR/TorchOps.td | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/include/torch-mlir/Dialect/Torch/IR/TorchOps.td b/include/torch-mlir/Dialect/Torch/IR/TorchOps.td index 03563287883c..4a83b97e6269 100644 --- a/include/torch-mlir/Dialect/Torch/IR/TorchOps.td +++ b/include/torch-mlir/Dialect/Torch/IR/TorchOps.td @@ -1361,6 +1361,15 @@ def Torch_SymbolicIntOp : Torch_Op<"symbolic_int", [Pure]> { %0 = torch.symbolic_int "s0" {min_val = 5, max_val = 10} : !torch.int %1 = torch.symbolic_int "s1" {min_val = 2, max_val = 20} : !torch.int ``` + + In this case, we see that `s0` has the range [5, 10] and `s1` has the + range [2, 20]. When unspecified, the range constraints feeding in from + TorchDynamo default to [0, INT_MAX] (or [2, INT_MAX] in older PyTorch + releases). In either case, the interpretation (as specified by TorchDynamo) + is that the dynamic dimension is assumed to be not 0 or 1. This is not a + bug, and does not necessarily mean that the exported program will not work + for dimensions 0 or 1. For an in-depth discussion of this topic, see + [The 0/1 Specialization Problem](https://docs.google.com/document/d/16VPOa3d-Liikf48teAOmxLc92rgvJdfosIy-yoT38Io/edit?fbclid=IwAR3HNwmmexcitV0pbZm_x1a4ykdXZ9th_eJWK-3hBtVgKnrkmemz6Pm5jRQ#heading=h.ez923tomjvyk). }]; let arguments = (ins StrAttr:$symbol_name,