Skip to content

Commit fbb0db1

Browse files
authored
Disable TORCH_MLIR_ENABLE_JIT_IR_IMPORTER and TORCH_MLIR_ENABLE_PYTORCH_EXTENSIONS by default (#3693)
Only enable it in CI and debug for update_abstract_interp_lib.sh and update_torch_ods.sh usage.
1 parent e86f56b commit fbb0db1

File tree

7 files changed

+28
-67
lines changed

7 files changed

+28
-67
lines changed

CMakeLists.txt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,14 @@ endif()
4747
option(TORCH_MLIR_OUT_OF_TREE_BUILD "Specifies an out of tree build" OFF)
4848

4949
# PyTorch native extension gate. If OFF, then no features which depend on
50-
# native extensions will be built.
51-
option(TORCH_MLIR_ENABLE_PYTORCH_EXTENSIONS "Enables PyTorch native extension features" ON)
50+
# native extensions will be built.TORCH_MLIR_ENABLE_PYTORCH_EXTENSIONS is disabled by default.
51+
# But it will be manually enabled in CI build to enable the jit_ir_importer.build_tools.torch_ods_gen
52+
# and abstract_interp_lib_gen.py. Once pure python version of build_tools finished, no need to set it in CI.
53+
option(TORCH_MLIR_ENABLE_PYTORCH_EXTENSIONS "Enables PyTorch native extension features" OFF)
54+
# NOTE: The JIT_IR_IMPORTER paths have become unsupportable due to age and lack of maintainers.
55+
# Turning this off disables the old TorchScript path, leaving FX based import as the current supported option.
56+
# The option will be retained for a time, and if a maintainer is interested in setting up testing for it,
57+
# please reach out on the list and speak up for it. It will only be enabled in CI for test usage.
5258
cmake_dependent_option(TORCH_MLIR_ENABLE_JIT_IR_IMPORTER "Enables JIT IR Importer" ON TORCH_MLIR_ENABLE_PYTORCH_EXTENSIONS OFF)
5359
cmake_dependent_option(TORCH_MLIR_ENABLE_LTC "Enables LTC backend" OFF TORCH_MLIR_ENABLE_PYTORCH_EXTENSIONS OFF)
5460

README.md

Lines changed: 10 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -21,35 +21,15 @@ Several vendors have adopted MLIR as the middle layer in their systems, enabling
2121
## All the roads from PyTorch to Torch MLIR Dialect
2222

2323
We have few paths to lower down to the Torch MLIR Dialect.
24-
25-
![Simplified Architecture Diagram for README](docs/images/readme_architecture_diagram.png)
26-
27-
- TorchScript
28-
This is the most tested path down to Torch MLIR Dialect.
29-
- LazyTensorCore
30-
Read more details [here](docs/ltc_backend.md).
31-
- We also have basic TorchDynamo/PyTorch 2.0 support, see our
32-
[long-term roadmap](docs/roadmap.md) and
33-
[Thoughts on PyTorch 2.0](https://discourse.llvm.org/t/thoughts-on-pytorch-2-0/67000/3)
34-
for more details.
24+
- ONNX as the entry points.
25+
- Fx as the entry points
3526

3627
## Project Communication
3728

3829
- `#torch-mlir` channel on the LLVM [Discord](https://discord.gg/xS7Z362) - this is the most active communication channel
3930
- Github issues [here](https://github.com/llvm/torch-mlir/issues)
4031
- [`torch-mlir` section](https://llvm.discourse.group/c/projects-that-want-to-become-official-llvm-projects/torch-mlir/41) of LLVM Discourse
4132

42-
### Meetings
43-
44-
Community Meeting / Developer Hour:
45-
- 1st and 3rd Monday of the month at 9 am PST
46-
- 2nd and 4th Monday of the month at 5 pm PST
47-
48-
Office Hours:
49-
- Every Thursday at 8:30 am PST
50-
51-
Meeting links can be found [here](https://discourse.llvm.org/t/new-community-meeting-developer-hour-schedule/73868).
52-
5333
## Install torch-mlir snapshot
5434

5535
At the time of writing, we release [pre-built snapshots of torch-mlir](https://github.com/llvm/torch-mlir-release) for Python 3.11 and Python 3.10.
@@ -74,7 +54,14 @@ pip install --pre torch-mlir torchvision \
7454
-f https://github.com/llvm/torch-mlir-release/releases/expanded_assets/dev-wheels
7555
```
7656

77-
## Demos
57+
## Using torch-mlir
58+
59+
Torch-MLIR is primarily a project that is integrated into compilers to bridge them to PyTorch and ONNX. If contemplating a new integration, it may be helpful to refer to existing downstreams:
60+
61+
* [IREE](https://github.com/iree-org/iree.git)
62+
* [Blade](https://github.com/alibaba/BladeDISC)
63+
64+
While most of the project is exercised via testing paths, there are some ways that an end user can directly use the APIs without further integration:
7865

7966
### FxImporter ResNet18
8067
```shell
@@ -93,30 +80,6 @@ torch-mlir prediction
9380
[('Labrador retriever', 70.6567153930664), ('golden retriever', 4.988325119018555), ('Saluki, gazelle hound', 4.477458477020264)]
9481
```
9582

96-
### TorchScript ResNet18
97-
98-
Standalone script to Convert a PyTorch ResNet18 model to MLIR and run it on the CPU Backend:
99-
100-
```shell
101-
# Get the latest example if you haven't checked out the code
102-
wget https://raw.githubusercontent.com/llvm/torch-mlir/main/projects/pt1/examples/torchscript_resnet18.py
103-
104-
# Run ResNet18 as a standalone script.
105-
python projects/pt1/examples/torchscript_resnet18.py
106-
107-
load image from https://upload.wikimedia.org/wikipedia/commons/2/26/YellowLabradorLooking_new.jpg
108-
Downloading: "https://download.pytorch.org/models/resnet18-f37072fd.pth" to /home/mlir/.cache/torch/hub/checkpoints/resnet18-f37072fd.pth
109-
100.0%
110-
PyTorch prediction
111-
[('Labrador retriever', 70.66319274902344), ('golden retriever', 4.956596374511719), ('Chesapeake Bay retriever', 4.195662975311279)]
112-
torch-mlir prediction
113-
[('Labrador retriever', 70.66320037841797), ('golden retriever', 4.956601619720459), ('Chesapeake Bay retriever', 4.195651531219482)]
114-
```
115-
116-
### Lazy Tensor Core
117-
118-
View examples [here](docs/ltc_examples.md).
119-
12083
## Repository Layout
12184

12285
The project follows the conventions of typical MLIR-based projects:

build_tools/ci/build_posix.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ cmake -S "$repo_root/externals/llvm-project/llvm" -B "$build_dir" \
5050
-DLLVM_EXTERNAL_TORCH_MLIR_SOURCE_DIR="$repo_root" \
5151
-DLLVM_TARGETS_TO_BUILD=host \
5252
-DMLIR_ENABLE_BINDINGS_PYTHON=ON \
53-
-DTORCH_MLIR_ENABLE_LTC=ON
53+
-DTORCH_MLIR_ENABLE_LTC=ON \
54+
-DTORCH_MLIR_ENABLE_PYTORCH_EXTENSIONS=ON
5455
echo "::endgroup::"
5556

5657
echo "::group::Build"

build_tools/ci/test_posix.sh

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,6 @@ torch_version="${1:-unknown}"
88

99
export PYTHONPATH="$repo_root/build/tools/torch-mlir/python_packages/torch_mlir:$repo_root/projects/pt1"
1010

11-
echo "::group::Run Linalg e2e integration tests"
12-
python -m e2e_testing.main --config=linalg -v
13-
echo "::endgroup::"
14-
15-
echo "::group::Run make_fx + TOSA e2e integration tests"
16-
python -m e2e_testing.main --config=make_fx_tosa -v
17-
echo "::endgroup::"
18-
19-
echo "::group::Run TOSA e2e integration tests"
20-
python -m e2e_testing.main --config=tosa -v
21-
echo "::endgroup::"
22-
23-
echo "::group::Run Stablehlo e2e integration tests"
24-
python -m e2e_testing.main --config=stablehlo -v
25-
echo "::endgroup::"
26-
2711
echo "::group::Run ONNX e2e integration tests"
2812
python -m e2e_testing.main --config=onnx -v
2913
echo "::endgroup::"

build_tools/update_abstract_interp_lib.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ if [ ! -z ${TORCH_MLIR_EXT_MODULES} ]; then
4141
ext_module="${TORCH_MLIR_EXT_MODULES} "
4242
fi
4343

44+
# To enable this python package, manually build torch_mlir with:
45+
# -DTORCH_MLIR_ENABLE_JIT_IR_IMPORTER=ON
46+
# TODO: move this package out of JIT_IR_IMPORTER.
4447
PYTHONPATH="${pypath}" python \
4548
-m torch_mlir.jit_ir_importer.build_tools.abstract_interp_lib_gen \
4649
--pytorch_op_extensions=${ext_module:-""} \

build_tools/update_torch_ods.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ if [ ! -z ${TORCH_MLIR_EXT_MODULES} ]; then
4242
fi
4343

4444
set +u
45+
# To enable this python package, manually build torch_mlir with:
46+
# -DTORCH_MLIR_ENABLE_PYTORCH_EXTENSIONS=ON
47+
# TODO: move this package out of JIT_IR_IMPORTER.
4548
PYTHONPATH="${PYTHONPATH}:${pypath}" python \
4649
-m torch_mlir.jit_ir_importer.build_tools.torch_ods_gen \
4750
--torch_ir_include_dir="${torch_ir_include_dir}" \

docs/add_ops.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ PS: IREE is pronounced Eerie, and hence the ghost icon.
3838

3939
### How to TorchToLinalg
4040

41-
You will need to do 4 things:
41+
You will need to do 5 things:
42+
- make sure -DTORCH_MLIR_ENABLE_JIT_IR_IMPORTER=ON is added during build. This is to enable the python file used in `build_tools/update_torch_ods.sh` and `build_tools/update_abstract_interp_lib.sh`
4243
- make sure the op exists in `torch_ods_gen.py`, and then run `build_tools/update_torch_ods.sh`, and then build. This generates `GeneratedTorchOps.td`, which is used to generate the cpp and h files where ops function signatures are defined.
4344
- Reference [torch op registry](https://github.com/pytorch/pytorch/blob/7451dd058564b5398af79bfc1e2669d75f9ecfa2/torch/csrc/jit/passes/utils/op_registry.cpp#L21)
4445
- make sure the op exists in `abstract_interp_lib_gen.py`, and then run `build_tools/update_abstract_interp_lib.sh`, and then build. This generates `AbstractInterpLib.cpp`, which is used to generate the cpp and h files where ops function signatures are defined.

0 commit comments

Comments
 (0)