Skip to content

Commit 5eae0ad

Browse files
Breakup python pytorch deps (#2582)
This lifts the core of the jit_ir_importer and ltc out of the pt1 project, making them peers to it. As a side-effect of this layering, now the "MLIR bits" (dialects, etc) are not commingled with the various parts of the pt1 project, allowing pt1 and ltc to overlay cleanly onto a more fundamental "just MLIR" Python core. Prior to this, the Python namespace was polluted to the point that this could not happen. That "just MLIR" Python core will be introduced in a followup, which will create the space to upstream the FX and ONNX pure Python importers. This primary non-NFC change to the API is: * `torch_mlir.dialects.torch.importer.jit_ir` -> `torch_mlir.jit_ir_importer`. The rest is source code layering so that we can make the pt1 project optional without losing the other features. Progress on #2546.
1 parent facbe5d commit 5eae0ad

File tree

143 files changed

+455
-483
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

143 files changed

+455
-483
lines changed

.github/workflows/buildAndTest.yml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,12 @@ jobs:
2727
matrix:
2828
os-arch: [ubuntu-x86_64, macos-arm64, windows-x86_64]
2929
llvm-build: [in-tree, out-of-tree]
30-
torch-binary: [ON, OFF]
30+
torch-binary: [ON]
3131
torch-version: [nightly, stable]
3232
exclude:
33-
# Exclude llvm in-tree and pytorch source
34-
- llvm-build: in-tree
35-
torch-binary: OFF
36-
# Exclude llvm out-of-tree and pytorch binary
33+
# Exclude llvm out-of-tree and pytorch stable (to save resources)
3734
- llvm-build: out-of-tree
38-
torch-binary: ON
35+
torch-version: stable
3936
# Exclude macos-arm64 and llvm out-of-tree altogether
4037
- os-arch: macos-arm64
4138
llvm-build: out-of-tree
@@ -45,9 +42,6 @@ jobs:
4542
llvm-build: out-of-tree
4643
- os-arch: windows-x86_64
4744
torch-version: stable
48-
# For PyTorch stable builds, we don't build PyTorch from source
49-
- torch-version: stable
50-
torch-binary: OFF
5145
include:
5246
# Specify OS versions
5347
- os-arch: ubuntu-x86_64

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ __pycache__
2626
bazel-*
2727

2828
# Autogenerated files
29-
/projects/pt1/python/torch_mlir/csrc/base_lazy_backend/generated
29+
/projects/ltc/csrc/base_lazy_backend/generated
3030

3131
#Docker builds
3232
build_oot/

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,12 @@ endfunction()
149149
# Configure CMake.
150150
list(APPEND CMAKE_MODULE_PATH ${MLIR_MAIN_SRC_DIR}/cmake/modules)
151151
list(APPEND CMAKE_MODULE_PATH ${LLVM_MAIN_SRC_DIR}/cmake)
152+
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/build_tools/cmake)
152153

153154
include(TableGen)
154155
include(AddLLVM)
155156
include(AddMLIR)
157+
include(AddMLIRPython)
156158

157159
################################################################################
158160
# Setup python.
@@ -231,6 +233,4 @@ endif()
231233
# Sub-projects
232234
#-------------------------------------------------------------------------------
233235

234-
if(TORCH_MLIR_ENABLE_PROJECT_PT1)
235-
add_subdirectory(projects/pt1)
236-
endif()
236+
add_subdirectory(projects)

build_tools/autogen_ltc_backend.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
TORCH_INCLUDE_DIR = TORCH_DIR
3030
TORCHGEN_DIR = Path(torchgen.__path__[0]).resolve()
3131
TORCH_MLIR_DIR = Path(__file__).resolve().parent.parent
32-
TORCH_MLIR_PT1_DIR = TORCH_MLIR_DIR / "projects" / "pt1"
3332

3433
def reindent(text, prefix=""):
3534
return indent(dedent(text), prefix)
@@ -114,12 +113,12 @@ def __init__(self, binary_dir):
114113
self.binary_dir = Path(binary_dir)
115114
assert self.binary_dir.is_dir(), f"Binary directory not found: {self.binary_dir}"
116115
self.source_yaml = self.binary_dir.joinpath("generated_native_functions.yaml")
117-
self.backend_path = TORCH_MLIR_PT1_DIR.joinpath(
118-
"python", "torch_mlir", "csrc", "base_lazy_backend"
116+
self.backend_path = TORCH_MLIR_DIR.joinpath(
117+
"projects", "ltc", "csrc", "base_lazy_backend"
119118
)
120119
assert self.backend_path.is_dir(), f"Backend path not found: {self.backend_path}"
121120
self.generated_path = self.binary_dir.joinpath(
122-
"projects", "pt1", "python", "torch_mlir", "csrc", "base_lazy_backend", "generated"
121+
"projects", "ltc", "csrc", "base_lazy_backend", "generated"
123122
)
124123
self.generated_path.mkdir(parents=True, exist_ok=True)
125124

@@ -415,7 +414,7 @@ def extract_signatures(text):
415414
// for ops that dont have a corresponding structured kernel or shape definition
416415
417416
#include "shape_inference.h"
418-
#include "torch_mlir/csrc/base_lazy_backend/utils/exception.h"
417+
#include "base_lazy_backend/utils/exception.h"
419418
namespace torch {{
420419
namespace lazy {{
421420
{}
@@ -467,7 +466,7 @@ def gen_fallback_code(*args, **kwargs):
467466
node_base="torch::lazy::TorchMlirNode",
468467
node_base_hdr=str(self.backend_path.joinpath("mlir_node.h")),
469468
tensor_class=self.tensor_class,
470-
tensor_class_hdr="torch_mlir/csrc/base_lazy_backend/tensor.h",
469+
tensor_class_hdr="base_lazy_backend/tensor.h",
471470
create_aten_from_ltc_tensor="CreateFunctionalizedAtenFromLtcTensor",
472471
shape_inference_hdr=str(self.generated_path.joinpath("shape_inference.h")),
473472
lazy_ir_generator=GenMlirLazyIr,

build_tools/python_deploy/build_linux_packages.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,9 +364,9 @@ function setup_venv() {
364364
function build_out_of_tree() {
365365
local torch_from_bin="$1"
366366
local python_version="$2"
367-
echo ":::: Build out-of-tree Torch from binary: $torch_from_bin with Python: $python_version"
368-
369367
local torch_version="$3"
368+
echo ":::: Build out-of-tree Torch from binary: $torch_from_bin with Python: $python_version ($torch_version)"
369+
370370
local enable_ltc="ON"
371371
if [[ "${torch_version}" == "stable" ]]
372372
then

build_tools/update_abstract_interp_lib.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ if [ ! -z ${TORCH_MLIR_EXT_MODULES} ]; then
4242
fi
4343

4444
PYTHONPATH="${pypath}" python \
45-
-m torch_mlir.dialects.torch.importer.jit_ir.build_tools.abstract_interp_lib_gen \
45+
-m torch_mlir.jit_ir_importer.build_tools.abstract_interp_lib_gen \
4646
--pytorch_op_extensions=${ext_module:-""} \
4747
--torch_transforms_cpp_dir="${torch_transforms_cpp_dir}"

build_tools/update_torch_ods.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fi
4343

4444
set +u
4545
PYTHONPATH="${PYTHONPATH}:${pypath}" python \
46-
-m torch_mlir.dialects.torch.importer.jit_ir.build_tools.torch_ods_gen \
46+
-m torch_mlir.jit_ir_importer.build_tools.torch_ods_gen \
4747
--torch_ir_include_dir="${torch_ir_include_dir}" \
4848
--pytorch_op_extensions="${ext_module}" \
4949
--debug_registry_dump="${torch_ir_include_dir}/JITOperatorRegistryDump.txt"

docs/Torch-ops-E2E-implementation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The end-to-end test is important to check the correctness of the other steps.
1717

1818
### Step 2. Update ods
1919

20-
Update [torch_ods_gen.py](https://github.com/llvm/torch-mlir/blob/main/projects/pt1/python/torch_mlir/dialects/torch/importer/jit_ir/build_tools/torch_ods_gen.py) with the new op and run [update_torch_ods.sh](https://github.com/llvm/torch-mlir/blob/main/build_tools/update_torch_ods.sh) to generate the ods. Running `update_torch_ods.sh` would dump all the operators with schema into `JITOperatorRegistryDump.txt`. It’s convenient to look for ops signatures and operands names in this file.
20+
Update [torch_ods_gen.py](https://github.com/llvm/torch-mlir/blob/main/projects/pt1/python/torch_mlir/jit_ir_importer/build_tools/torch_ods_gen.py) with the new op and run [update_torch_ods.sh](https://github.com/llvm/torch-mlir/blob/main/build_tools/update_torch_ods.sh) to generate the ods. Running `update_torch_ods.sh` would dump all the operators with schema into `JITOperatorRegistryDump.txt`. It’s convenient to look for ops signatures and operands names in this file.
2121

2222
### Step 3. Propagate types
2323
It’s essential to make sure the new op implements shape and dtype inference. See [abstract_interp_lib](https://github.com/llvm/torch-mlir/blob/main/docs/abstract_interp_lib.md) for information on adding shape and dtype inference.

docs/abstract_interp_lib.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ The two main use cases are:
2626
## Architecture
2727

2828
Functions are defined as TorchScript-able Python functions in
29-
`python/torch_mlir/dialects/torch/importer/jit_ir/build_tools/abstract_interp_lib_gen.py`.
29+
`python/torch_mlir/jit_ir_importer/build_tools/abstract_interp_lib_gen.py`.
3030
The signatures of the functions are systematically derived from Torch JIT
3131
operator registry. Most shape functions are expected to reuse the upstream
3232
helper functions

0 commit comments

Comments
 (0)