How can I tell mlir-opt to interpret it using tf_executor and tf dialects ?
I am trying to write a simple pass by extending a module pass to walk over all functions and Operations to process each Operation. I use mlir-opt --<my_registered_pass> to test my code. But I am hitting a parse error
error: custom op 'tf_executor.graph' is unknown
tf_executor.graph {
^
The TensorFlow dialect does not come with MLIR, it lives in the TensorFlow directory. There you can use tf-opt (just the same way you got tf-mlir-translate) that provides a superset of mlir-opt and includes the TensorFlow specific bits needed to process TensorFlow MLIR files.
# pb model to mlir tf dialect
bazel run //tensorflow/compiler/mlir:tf-mlir-translate -- \
--graphdef-to-mlir --tf-input-arrays=input0,input1 \
--tf-input-data-types=DT_INT32,DT_INT32 \
--tf-input-shapes=10:10 --tf-output-arrays=Add \
${PWD}/add.pbtxt \
-o ${PWD}/add.mlir
# Convert to mhlo
bazel run //tensorflow/compiler/mlir:tf-opt -- \
--tf-executor-to-functional-conversion \
--tf-region-control-flow-to-functional \
--xla-legalize-tf \
${PWD}/add.mlir \
-o ${PWD}/add-mhlo.mlir
# Convert to lhlo
bazel run //tensorflow/compiler/mlir:tf-opt -- \
--xla-hlo-to-lhlo-with-xla \
${PWD}/add-mhlo.mlir \
-o ${PWD}/add-lhlo.mlir
# Convert from lhlo to mlir.llvm.
# There may be a need for other passes depending on the model
bazel run //tensorflow/compiler/mlir/hlo:mlir-hlo-opt -- \
-mhlo-test-chlo-legalize-to-hlo \
-hlo-legalize-to-lhlo=results-escape-function=true \
-buffer-placement \
-copy-removal \
-canonicalize \
-cse \
-lhlo-legalize-to-linalg \
-lhlo-fuse-linalg \
-convert-linalg-to-loops \
-convert-scf-to-std \
-canonicalize \
-cse \
-test-lhlo-legalize-to-llvm \
${PWD}/add-lhlo.mlir \
-o ${PWD}/add-llvm.mlir
Newbie here, I am having difficulty lowering Constants using this pipeline.
If I have a frozen model with the weights encoded as constants, the constants are not lowered below lmhlo.const instructions. It feels like I am missing a pass, can anyone provide any hints to where I should direct my search queries.
Hi there, did you manage to parse tf/tf_executor dialect to HLO? I found the same issues as yours and even though I used tf-opt, the output file remained unchanged.