google / heir

A compiler for homomorphic encryption
https://heir.dev/
Apache License 2.0
289 stars 42 forks source link

Tensorflow to TOSA Documentation #493

Open edwjchen opened 6 months ago

edwjchen commented 6 months ago

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

asraa commented 6 months ago

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 git@github.com: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
  2. 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}
j2kun commented 6 months ago

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