heir icon indicating copy to clipboard operation
heir copied to clipboard

Tensorflow to TOSA Documentation

Open edwjchen opened this issue 1 year ago • 2 comments

How would one compile a Tensorflow program to HEIR's TOSA frontend?

edwjchen avatar Mar 07 '24 15:03 edwjchen

Hey! Good question. I will port over the docs from https://github.com/google/fully-homomorphic-encryption/tree/main/transpiler/tensorflow to HEIR, but here are the relevant lines

If you would like to transpile an existing TFLite model, you will also need to install the following tools:

  1. flatbuffer_translate.
git clone [email protected]:tensorflow/tensorflow.git && cd tensorflow
bazel build -c opt tensorflow/compiler/mlir/lite:flatbuffer_translate

See the instructions here to use a local LLVM build,

  1. tf-opt. For example, use
bazel build -c opt tensorflow/compiler/mlir:tf-opt
  1. Convert the TensorFlow Lite model to TOSA MLIR.
flatbuffer_translate --tflite-flatbuffer-to-mlir ${INPUT_TFLITE} | tf-opt --tf-tfl-to-tosa-pipeline --tosa-strip-quant-types -o ${OUTPUT_TOSA}

asraa avatar Mar 07 '24 15:03 asraa

I think there should be a way to avoid tf-lite, and maybe these docs could give a head start https://discuss.tensorflow.org/t/conversion-of-tensorflow-graphdef-to-only-tosa-mlir-using-python-apis/21866/3

j2kun avatar Mar 07 '24 17:03 j2kun