TrainingExtensions/tensorflow/src/python/aimet_tensorflow/keras/utils/common.py
def _clear_inbound_and_outbound_nodes(layer_of_interest: tf.keras.layers.Layer,
                                      parent_layers: typing.List[tf.keras.layers.Layer],
                                      following_layers_and_inputs_dict: typing.Dict[tf.keras.layers.Layer,
                                                                                    typing.List[tf.Tensor]]):
    """
    Clear certain outbound nodes of parent layers, inbound node of layer_of_interest, outbound nodes of
    layer_of_interest, and inbound nodes of following layers.
    :param layer_of_interest: Layer to remove inbound and outbound nodes of
    :param parent_layers: Parent layers to remove outbound nodes of
    :param following_layers_and_inputs_dict: Dictionary containing following layers to remove inbound nodes of
    """
    # pylint: disable=protected-access
    # Clear out inbound node of layer_of_interest
    old_inbound_node = layer_of_interest.inbound_nodes[0]
    layer_of_interest._inbound_nodes.remove(old_inbound_node)

    # Clear out the inbound node from the outbound nodes lists of parent layers
    for parent_layer in parent_layers:
        parent_layer._outbound_nodes.remove(old_inbound_node)

    # Clear out old outbound node of old layer and corresponding inbound node of following layers.
    # Following layers may have other inputs as well; for those inputs, the correct outbound node must be removed too.
    # pylint: disable=too-many-nested-blocks
    if layer_of_interest.outbound_nodes:
        for outbound_node in layer_of_interest.outbound_nodes:
            # For all following layers of old layer, clear out inbound nodes corresponding to the old layer
            for following_layer in following_layers_and_inputs_dict.keys():
                if outbound_node in following_layer._inbound_nodes:
                    following_layer._inbound_nodes.remove(outbound_node)

                    # The following layer may have multiple inputs. In this case, since we are recreating the inbound
                    # node using all inputs, we need to clear out the corresponding outbound_node from the other input
                    # layers' outbound_nodes as well.
                    for keras_input in following_layers_and_inputs_dict[following_layer]:
                        # Don't modify outbound node of old_layer yet
                        if keras_input._keras_history.layer != layer_of_interest:
                            keras_input._keras_history.layer._outbound_nodes.remove(outbound_node)

        layer_of_interest._outbound_nodes = []

    Clear certain outbound nodes of parent layers, inbound node of layer_of_interest, outbound nodes of
    layer_of_interest, and inbound nodes of following layers.
    :param layer_of_interest: Layer to remove inbound and outbound nodes of
    :param parent_layers: Parent layers to remove outbound nodes of
    :param following_layers_and_inputs_dict: Dictionary containing following layers to remove inbound nodes of
    
Clear certain outbound nodes of parent layers, inbound node of layer_of_interest, outbound nodes of
layer_of_interest, and inbound nodes of following layers.
Clear certain outbound nodes of parent layers inbound node of layer_of_interest outbound nodes of layer_of_interest and inbound nodes of following layers .
def _clear_inbound_and_outbound_nodes(layer_of_interest: tf.keras.layers.Layer,
                                      parent_layers: typing.List[tf.keras.layers.Layer],
                                      following_layers_and_inputs_dict: typing.Dict[tf.keras.layers.Layer,
                                                                                    typing.List[tf.Tensor]]):
    old_inbound_node = layer_of_interest.inbound_nodes[0]
    layer_of_interest._inbound_nodes.remove(old_inbound_node)
    for parent_layer in parent_layers:
        parent_layer._outbound_nodes.remove(old_inbound_node)
    if layer_of_interest.outbound_nodes:
        for outbound_node in layer_of_interest.outbound_nodes:
            for following_layer in following_layers_and_inputs_dict.keys():
                if outbound_node in following_layer._inbound_nodes:
                    following_layer._inbound_nodes.remove(outbound_node)
                    for keras_input in following_layers_and_inputs_dict[following_layer]:
                        if keras_input._keras_history.layer != layer_of_interest:
                            keras_input._keras_history.layer._outbound_nodes.remove(outbound_node)
        layer_of_interest._outbound_nodes = []
def _clear_inbound_and_outbound_nodes ( layer_of_interest : tf . keras . layers . Layer , parent_layers : typing . List [ tf . keras . layers . Layer ] , following_layers_and_inputs_dict : typing . Dict [ tf . keras . layers . Layer , typing . List [ tf . Tensor ] ] ) : old_inbound_node = layer_of_interest . inbound_nodes [ 0 ] layer_of_interest . _inbound_nodes . remove ( old_inbound_node ) for parent_layer in parent_layers : parent_layer . _outbound_nodes . remove ( old_inbound_node ) if layer_of_interest . outbound_nodes : for outbound_node in layer_of_interest . outbound_nodes : for following_layer in following_layers_and_inputs_dict . keys ( ) : if outbound_node in following_layer . _inbound_nodes : following_layer . _inbound_nodes . remove ( outbound_node ) for keras_input in following_layers_and_inputs_dict [ following_layer ] : if keras_input . _keras_history . layer != layer_of_interest : keras_input . _keras_history . layer . _outbound_nodes . remove ( outbound_node ) layer_of_interest . _outbound_nodes = [ ]
Clear certain outbound nodes of parent layers, inbound node of layer_of_interest, outbound nodes of
layer_of_interest, and inbound nodes of following layers.
Clear certain outbound nodes of parent layers inbound node of layer_of_interest outbound nodes of layer_of_interest and inbound nodes of following layers .
"""
    Clear certain outbound nodes of parent layers, inbound node of layer_of_interest, outbound nodes of
    layer_of_interest, and inbound nodes of following layers.
    :param layer_of_interest: Layer to remove inbound and outbound nodes of
    :param parent_layers: Parent layers to remove outbound nodes of
    :param following_layers_and_inputs_dict: Dictionary containing following layers to remove inbound nodes of
    """ # pylint: disable=protected-access # Clear out inbound node of layer_of_interest # Clear out the inbound node from the outbound nodes lists of parent layers # Clear out old outbound node of old layer and corresponding inbound node of following layers. # Following layers may have other inputs as well; for those inputs, the correct outbound node must be removed too. # pylint: disable=too-many-nested-blocks # For all following layers of old layer, clear out inbound nodes corresponding to the old layer # The following layer may have multiple inputs. In this case, since we are recreating the inbound # node using all inputs, we need to clear out the corresponding outbound_node from the other input # layers' outbound_nodes as well. # Don't modify outbound node of old_layer yet
layer_of_interest
tf.keras.layers.Layer
Layer to remove inbound and outbound nodes of
Layer to remove inbound and outbound nodes of
parent_layers
typing.List[tf.keras.layers.Layer]
Parent layers to remove outbound nodes of
Parent layers to remove outbound nodes of
following_layers_and_inputs_dict
typing.Dict[tf.keras.layers.Layer,
                                                                                    typing.List[tf.Tensor]]
Dictionary containing following layers to remove inbound nodes of
Dictionary containing following layers to remove inbound nodes of