Script to split stablehlo module into sub modules [#2317] #2323
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add a script that splits stablehlo module into sub modules representing each op individually. Need to pip install -r tools/stablehlo_splitter/requirements.txt to install dependencies.
Ticket
#2317
Problem description
Front-ends (tt-xla, tt-torch) want to run stablehlo graphs op-by-op. We need a mechanism to break down stablehlo modules into standalone sub-modules corresponding to each op individually.
What's changed
Added
tools/stablehlo_splitter/shlo_split.py
andtools/stablehlo_splitter/requirements.txt
How to use the script?
From each front-end, we need to run
pip install -r third_party/tt-mlir/src/tt-mlir/tools/stablehlo_splitter/requirements.txt
I have tested in both tt-xla and tt-mlir that the script works.
tt-xla test branch
tt-torch test branch
The test script is as follows:
This file reads the stablehlo module coming from autoencoder model in tt-torch, which is saved as
Autoencoder.mlir
If you runpython temp.py
you can see the sub-ops printed as attached to this PR.Autoencoder_sub_ops.txt
I am creating this as a draft PR to start a discussion on:
op_id is the id of the op in the original mlir string
op is how it was referenced in the original mlir string
module is the new standalone module that can be compiled/ executed standalone
i.e. {'op_id': '%33', 'op': '%33 = stablehlo.dot_general %32, %arg7, contracting_dims = [1] x [0] : (tensor<1x12xf32>, tensor<12x3xf32>) -> tensor<1x3xf32>', 'module': 'module {\n func.func @main(%32: tensor<1x12xf32>, %arg7: tensor<12x3xf32>) -> tensor<1x3xf32> {\n %33 = stablehlo.dot_general %32, %arg7, contracting_dims = [1] x [0] : (tensor<1x12xf32>, tensor<12x3xf32>) -> tensor<1x3xf32>\n return %33 : tensor<1x3xf32>\n }\n }'}