Mentioned helpful tooling to convert Onnx models to Torch MLIR (#2683)

- Going through the `#torch-mlir` channel on the `llvm` discord, I
realize that there are some useful commands that would be extremely
helpful in creating Onnx lowers to Torch MLIR. Seems a lot of people are
contributing to this. So, I thought it would be good to add this
information to the docs.

These tools helped streamlined the development of this PR:
https://github.com/llvm/torch-mlir/pull/2682
pull/2706/head
John Wu 2023-12-21 07:26:20 -08:00 committed by GitHub
parent 3226241521
commit 779a141f8d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 14 additions and 2 deletions

View File

@ -28,13 +28,25 @@ are relatively straight-forward to map, following this general procedure:
`tools/torch-mlir/test/python/onnx_importer/Output`. The `.mlir` files `tools/torch-mlir/test/python/onnx_importer/Output`. The `.mlir` files
under there should provide good variants to drive lit test coverage of under there should provide good variants to drive lit test coverage of
conversion. conversion.
* (Optionally) If there is an Onnx file that uses the op of interest,
convert that file to Onnx MLIR form using the following Python command,
`python -m torch_mlir.tools.import_onnx my_model.onnx`.
* There are often many variants of tests for checking conformance of * There are often many variants of tests for checking conformance of
different historic ONNX encodings, but these are often not load bearing different historic ONNX encodings, but these are often not load bearing
at the MLIR level. at the MLIR level.
* Pick a handful of test cases and add them to * Pick a handful of test cases and add them to
`test/Conversion/TorchOnnxToTorch/simple_ops_x_to_y.mlir` corresponding to an `test/Conversion/TorchOnnxToTorch/simple_ops_x_to_y.mlir` corresponding to
alphabetic breakdown. At this time, ignore tests that are not exercising an alphabetic breakdown. At this time, ignore tests that are not exercising
useful differences in the pattern implementations. useful differences in the pattern implementations.
* (Optionally) Use `torch-mlir-opt` to validate the outputs of the new op.
First, build the project using
`cmake --build build --target tools/torch-mlir/all`. This will generate
the conversion binary, `torch-mlir-opt`. Then call `torch-mlir-opt` with
the MLIR pass `convert-torch-onnx-to-torch`:
```
build/bin/torch-mlir-opt -convert-torch-onnx-to-torch \
-split-input-file [DESIRED_ONNX_FILE].mlir
```
* Generate failure test cases: * Generate failure test cases:
* Some ops have forms that do not (easily) map to torch-mlir. If you leave * Some ops have forms that do not (easily) map to torch-mlir. If you leave
an op under-implemented, add a failing test case to an op under-implemented, add a failing test case to