Skip to content
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

BatchNorm Folding Bug fix #2587

Merged
merged 3 commits into from
Dec 2, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ def _delete_bn_from_functional(model: tf.keras.Model,
def wrapped_bn_layer_in_bns_to_remove(layer: tf.keras.layers.Layer) -> bool:
return isinstance(layer, QcQuantizeWrapper) and layer._layer_to_wrap in bn_layers_to_remove

tf.keras.backend.clear_session() # clear session to not have tensor name conflicts

# Step 1: Get the inbound and outbound connections for each layer in the model
model_layer_connections = ModelLayerConnections.get_model_layers_connection_properties(model)

Expand Down Expand Up @@ -492,7 +494,8 @@ def wrapped_bn_layer_in_bns_to_remove(layer: tf.keras.layers.Layer) -> bool:

KERAS_SYMBOLIC_TENSORS_INDEX = 0
# Check if we need to change layer_input order. If there is just one input, there is no order.
if isinstance(layer_input, List):
# Special case when there is a Lambda layer with multiple inputs is handled seperately
if isinstance(layer_input, List) and not isinstance(current_layer, TFOpLambda):
# Original models keras symbolic tensor order
original_keras_symbolic_tensors_order = model_layer_connections[ModelLayerConnectionsProperties.CALL_ARGS][
current_layer.name][KERAS_SYMBOLIC_TENSORS_INDEX]
Expand Down Expand Up @@ -550,7 +553,6 @@ def wrapped_bn_layer_in_bns_to_remove(layer: tf.keras.layers.Layer) -> bool:
if current_layer.name in model.output_names:
model_outputs.append(x)

tf.keras.backend.clear_session() # clear session to not have tensor name conflicts
return tf.keras.Model(inputs=model.inputs, outputs=model_outputs)


Expand Down
Loading