import numpy as np
import shutil
import tensorflow as tf
from tensorflow import keras
import tensorflow.keras.backend as K
from tensorflow.keras import layers
import inspect
import os
SAVE_AND_LOAD_MODEL = True
class MultilayerLinear(keras.Model):
def __init__(self, hidden_size, num_layers):
super().__init__()
self.lin_layers = []
for __ in range(num_layers):
self.lin_layers.append(layers.Dense(hidden_size, activation='relu'))
@tf.function
def call(self, x):
for l in self.lin_layers:
x = l(x)
return x
hidden_size = 64
input_size = 128
num_layers = 1
model = MultilayerLinear(hidden_size, num_layers)
x = tf.random.normal((8 , input_size))
y = model(x)
model.build((None, input_size))
if SAVE_AND_LOAD_MODEL:
export_dir = "./tflite_conversion_test"
tf.saved_model.save(model, export_dir)
model = tf.saved_model.load(export_dir)
x = K.placeholder(shape=(None, input_size))
concrete_function = model.call.get_concrete_function(x)
converter = tf.lite.TFLiteConverter([concrete_function])
tflite_model = converter.convert()
Hi,I posted this question on TFLite group but didn't get any response. So thought this might be a more appropriate group to ask this question. Thanks!I built tensorflow 2.1.0 from source. For the following model, I would like to dump the sequence of MLIR optimizations and transformations that happen during TensorFlow to TFLite conversion when tf.lite.TFLiteConverter is called .
I understand that mlir-opt is responsible for doing the MLIR optimizations but I don't know how mlir-opt gets invoked while we make tf.lite.TFLiteConverter call. Could you please provide me the steps to dump the MLIR passes for this program?
Hi Mehdi,Thanks a lot for letting me know how MLIR is integrated with TFLite. Really useful information.Just need one clarification. I understand that we cannot dump MLIR from Python source code.[Mehdi] You can add `--print-ir-after-all` and other options similar to what `mlir-opt` accepts to get the IR printed after each pass (you'll need to sync to a recent version of the repository to get these options though).Can I use `--print-ir-after-all` and other MLIR IR dump options in the bazel build command ? ( that MLIR could recognize while it is converting TF->TFLite when tf.lite.TFLiteConverter is called and dump the IR after every pass?)
--
You received this message because you are subscribed to the Google Groups "MLIR" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mlir+uns...@tensorflow.org.
To view this discussion on the web visit https://groups.google.com/a/tensorflow.org/d/msgid/mlir/0fb3f8a3-13a5-43b5-b732-85a8e1581e63%40tensorflow.org.