-
Notifications
You must be signed in to change notification settings - Fork 157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DRAFT][compiler] Introduce FuseGRUPass #13602
base: master
Are you sure you want to change the base?
[DRAFT][compiler] Introduce FuseGRUPass #13602
Conversation
This pr introduces FuseGRUPass for fusing gru pattern into single CircleGRU op. ONE-DCO-1.0-Signed-off-by: Artem Balyshev <[email protected]>
import tensorflow as tf
from tensorflow import keras
from tensorflow.keras import regularizers
import numpy as np
normalization_layer = tf.keras.layers.Normalization()
adapt_data = np.array([[0., 7., 4. , 0.5],
[2., 9., 6. , -0.5],
[0., 7., 4. , -0.5],
[2., 9., 6. , 0.5]], dtype='float32')
#normalization_layer.adapt(adapt_data)
classes = 4
activation = 'tanh'
model = tf.keras.models.Sequential([
tf.keras.Input(shape=(10,4)),
normalization_layer,
tf.keras.layers.GRU(units=20, activation=activation),
tf.keras.layers.Dense(classes, activation='softmax')
])
model.compile(optimizer=tf.keras.optimizers.Adam(learning_rate=0.001))
model.summary()
run_model = tf.function(lambda x: model(x))
# This is important, let's fix the input size.
BATCH_SIZE = 1
X = 10
Y = 4
concrete_func = run_model.get_concrete_function(
tf.TensorSpec([BATCH_SIZE, X,Y], model.inputs[0].dtype))
# model directory.
MODEL_DIR = "keras_model"
model.save(MODEL_DIR, save_format="tf", signatures=concrete_func)
converter = tf.lite.TFLiteConverter.from_saved_model(MODEL_DIR)
converter.experimental_new_converter = True
converter.target_spec.supported_ops = [tf.lite.OpsSet.TFLITE_BUILTINS,
]
#converter.optimizations = [tf.lite.Optimize.DEFAULT]
converted_model = converter.convert()
save_to = "GRU.tflite"
if save_to is not None:
with open(save_to, 'wb') as tf_lite_file:
tf_lite_file.write(converted_model) @BalyshevArtem After applying this pass to gru model, while_cond / while_body subgraph are still alive in resulting graph. |
Hmmm |
@chunseoklee, I checked your models from GRU_fusegru.zip. |
@chunseoklee, I have added the part that is responsible for removing dead graphs, please check :) |
a0d6933
to
5d77de3
Compare
if (m->size() == 0) | ||
throw std::invalid_argument("No any graphs"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is logically invalid case but we don't need to throw to stop the program.
just return false would be OK.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
circle_gru->input(_p->_ifm); | ||
circle_gru->hidden_hidden(weight_hh_cloned); | ||
circle_gru->hidden_input(weight_ih_cloned); | ||
circle_gru->hidden_hidden_bias(bias_hh_cloned); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those two bias tensor are not well generated in the fused GRU.
-> since original model's FC does not have bias.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
-> since original model's FC does not have bias.
Yes, that is the reason, they are empty is FC doesn't have bias
This pr introduces EliminateDeadSubgraphPass for removing dead subgraph. ONE-DCO-1.0-Signed-off-by: Artem Balyshev <[email protected]>
5d77de3
to
9538317
Compare
To check pass(es) is(are) working correctly,
|
This pr adds recipe for decomposed GRU. ONE-DCO-1.0-Signed-off-by: Artem Balyshev <[email protected]>
This commit adds fuse_gru test to circle2circle-dredd-recipe-test. ONE-DCO-1.0-Signed-off-by: Artem Balyshev <[email protected]>
I added tflite decomposed GRU recipe and circle2circle-dredd-recipe-test. |
Yes.
How can you be certain without value check that the conversion pass is working correctly? @chunseoklee , I'd like to hear your opinion. |
I checked manually the result for onert-micro. After finishing with onert-micro supporting we will ad it into luci-interpreter :) |
AFAIU, GRU kernel will be added into luci-interpreter after a while. Am I right ? |
OK, adding a issue for this task will do for now. |
This pr introduces FuseGRUPass for fusing gru pattern into single CircleGRU op.
for issues: #12263 and for #13365
ONE-DCO-1.0-Signed-off-by: Artem Balyshev [email protected]