openxla / iree

A retargetable MLIR-based machine learning compiler and runtime toolkit.

Home Page:http://iree.dev/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Upload `iree-dump-*` to PIP for easy & cross-platform inspection of `.mlir` code.

RechieKho opened this issue · comments

Request description

For now, there are only the compiler, the runtime and the importers are available in the cross-platform manner, the rest of the good stuff remains in iree-dist and it is linux-only. I come to realise that inspecting the .mlir functions signatures and parameter type is quite important for the user the run the byte codes. In the example given in the official website, you are only able to run the byte code by given the function name and argument with correct shape:

im = numpy.array(Image.open(jpgFile).resize((192, 192))).reshape((1, 192, 192, 3))
args = [im]

invoke = context.modules.module["main"]
iree_results = invoke(*args)
print(iree_results)

Unfortunately, it is very hard to inspect the function name and parameter's shape. If you are on linux, you are lucky because you have iree-dist, but if you are on other platform, you either got to compile IREE or start a virtual machine with linux installed. I guess we better off upload some inspection tool to PIP.

What component(s) does this issue relate to?

Python

Additional context

I see there are already some inspection tools written in tools/, e.g. iree-dump-parameter-main. It is a great place to start.

Out of curiosity, what tools do you use in the full distribution to do this? In general, we try to add everyone useful to the pip installs but maybe forgot something.

I also need to check but I think we have enough reflection metadata exposed to Python that a python script could do this just based on the public API. We should write such a script, verify and include it.

I've been meaning to add an optional human-friendly name to exported vm module functions (not full metadata or anything, for all the issues that entails) - was going to capture it during the ABI adjustment so it would include fences/other things we add. Then iree-dump-module and the status messages in the tools can at least show the original MLIR signature (tensor<whatever>).

That would help a lot.

FWIW, many of the tools in https://github.com/openxla/iree/blob/main/tools/CMakeLists.txt only depend on the runtime code, so they should be pretty fast to build from source with CMake (e.g. with -DIREE_BUILD_COMPILER=OFF). Agreed that having everything available in Python and/or iree-dist (for all platforms) is more convenient though.

These are the tools that I see in the latest (nightly) Python iree-runtime package:

D:\dev\scratch\python\iree
λ python -m venv .venv

D:\dev\scratch\python\iree
λ .venv\Scripts\activate.bat

D:\dev\scratch\python\iree
(.venv) λ python -m pip install --find-links https://iree.dev/pip-release-links.html --upgrade iree-runtime

D:\dev\scratch\python\iree
(.venv) λ which iree-run-module
/d/dev/scratch/python/iree/.venv/Scripts/iree-run-module

D:\dev\scratch\python\iree
(.venv) λ ls -A1 .\.venv\Scripts\ | grep iree-
iree-benchmark-module.exe*
iree-benchmark-trace.exe*
iree-convert-parameters.exe*
iree-cpuinfo.exe*
iree-create-parameters.exe*
iree-dump-module.exe*
iree-dump-parameters.exe*
iree-run-module.exe*
iree-run-trace.exe*

Compared to all tools from a source build (compiler included);

D:\dev\scratch\python\iree
(.venv) λ ls -A1 D:\dev\projects\iree-build\tools | grep iree-.*.exe
iree-benchmark-module.exe*
iree-benchmark-trace.exe*
iree-convert-parameters.exe*
+iree-check-module.exe*
iree-compile.exe*
iree-cpuinfo.exe*
+iree-dump-instruments.exe*
iree-dump-module.exe*
iree-dump-parameters.exe*
+iree-e2e-matmul-test.exe*
+iree-fatelf.exe*
+iree-mlir-lsp-server.exe*
+iree-opt.exe*
+iree-reduce.exe*
+iree-run-mlir.exe*
iree-run-module.exe*
iree-run-trace.exe*
+iree-tblgen.exe*
+test-iree-compiler-api-test-binary.exe*

Also installing the iree-compiler package makes more scripts available:

D:\dev\scratch\python\iree
(.venv) λ python -m pip install --find-links https://iree.dev/pip-release-links.html --upgrade iree-runtime iree-compiler

D:\dev\scratch\python\iree
(.venv) λ ls -A1 .\.venv\Scripts\ | grep iree-.*.exe
iree-benchmark-module.exe*
iree-benchmark-trace.exe*
+iree-compile.exe*
iree-convert-parameters.exe*
iree-cpuinfo.exe*
iree-create-parameters.exe*
iree-dump-module.exe*
iree-dump-parameters.exe*
+iree-ir-tool.exe*
iree-run-module.exe*
iree-run-trace.exe*

(docs on the Python "scripts": https://iree.dev/reference/bindings/python/#console-scripts)

I've been meaning to add an optional human-friendly name to exported vm module functions (not full metadata or anything, for all the issues that entails) - was going to capture it during the ABI adjustment so it would include fences/other things we add. Then iree-dump-module and the status messages in the tools can at least show the original MLIR signature (tensor<whatever>).

Signature would be nice. I know we had talked about having that in the reflection info (old PR related that half dusted off other day), would this instead be in the name?