TrainingExtensions/tensorflow/src/python/aimet_tensorflow/keras/batch_norm_fold.py
def _add_children_layer_before_parent_layer(cur_layer: tf.keras.layers.Layer, node_layer_map: Dict,
                                            layer_out_node_map: Dict,
                                            visited_layers: Set[tf.keras.layers.Layer],
                                            reversed_ordered_layers: List[tf.keras.layers.Layer]):
    """
    Function to use topological sorting for finding all the layers which are accessible
    from the specific input_layer in the opposite order of occurrence.

    :param cur_layer:layer that we want to find path from
    :param node_layer_map: dictionary includes node_ref as a key, in_layers and out_layer as value
    :param layer_out_node_map: dictionary includes layer_ref as a key, outbound nodes as value
    :param visited_layers: Set of all layers that have been visited
    :param reversed_ordered_layers: List of layers in the opposite order of occurrence
        for the layers that we have visited so far
    """

    # Mark the current layer as visited.
    visited_layers.add(cur_layer)

    if cur_layer in layer_out_node_map:
        # Recur for all the layers adjacent to this layer
        for next_node in layer_out_node_map[cur_layer]:
            next_layer = node_layer_map[next_node][1]
            if next_layer not in visited_layers:
                _add_children_layer_before_parent_layer(next_layer, node_layer_map,
                                                        layer_out_node_map, visited_layers,
                                                        reversed_ordered_layers)
            reversed_ordered_layers.append(cur_layer)
    else:
        reversed_ordered_layers.append(cur_layer)

    Function to use topological sorting for finding all the layers which are accessible
    from the specific input_layer in the opposite order of occurrence.

    :param cur_layer:layer that we want to find path from
    :param node_layer_map: dictionary includes node_ref as a key, in_layers and out_layer as value
    :param layer_out_node_map: dictionary includes layer_ref as a key, outbound nodes as value
    :param visited_layers: Set of all layers that have been visited
    :param reversed_ordered_layers: List of layers in the opposite order of occurrence
        for the layers that we have visited so far
    
Function to use topological sorting for finding all the layers which are accessible
from the specific input_layer in the opposite order of occurrence.
Function to use topological sorting for finding all the layers which are accessible from the specific input_layer in the opposite order of occurrence .
def _add_children_layer_before_parent_layer(cur_layer: tf.keras.layers.Layer, node_layer_map: Dict,
                                            layer_out_node_map: Dict,
                                            visited_layers: Set[tf.keras.layers.Layer],
                                            reversed_ordered_layers: List[tf.keras.layers.Layer]):
    visited_layers.add(cur_layer)
    if cur_layer in layer_out_node_map:
        for next_node in layer_out_node_map[cur_layer]:
            next_layer = node_layer_map[next_node][1]
            if next_layer not in visited_layers:
                _add_children_layer_before_parent_layer(next_layer, node_layer_map,
                                                        layer_out_node_map, visited_layers,
                                                        reversed_ordered_layers)
            reversed_ordered_layers.append(cur_layer)
    else:
        reversed_ordered_layers.append(cur_layer)
def _add_children_layer_before_parent_layer ( cur_layer : tf . keras . layers . Layer , node_layer_map : Dict , layer_out_node_map : Dict , visited_layers : Set [ tf . keras . layers . Layer ] , reversed_ordered_layers : List [ tf . keras . layers . Layer ] ) : visited_layers . add ( cur_layer ) if cur_layer in layer_out_node_map : for next_node in layer_out_node_map [ cur_layer ] : next_layer = node_layer_map [ next_node ] [ 1 ] if next_layer not in visited_layers : _add_children_layer_before_parent_layer ( next_layer , node_layer_map , layer_out_node_map , visited_layers , reversed_ordered_layers ) reversed_ordered_layers . append ( cur_layer ) else : reversed_ordered_layers . append ( cur_layer )
Function to use topological sorting for finding all the layers which are accessible
from the specific input_layer in the opposite order of occurrence.
Function to use topological sorting for finding all the layers which are accessible from the specific input_layer in the opposite order of occurrence .
"""
    Function to use topological sorting for finding all the layers which are accessible
    from the specific input_layer in the opposite order of occurrence.

    :param cur_layer:layer that we want to find path from
    :param node_layer_map: dictionary includes node_ref as a key, in_layers and out_layer as value
    :param layer_out_node_map: dictionary includes layer_ref as a key, outbound nodes as value
    :param visited_layers: Set of all layers that have been visited
    :param reversed_ordered_layers: List of layers in the opposite order of occurrence
        for the layers that we have visited so far
    """ # Mark the current layer as visited. # Recur for all the layers adjacent to this layer
cur_layer
tf.keras.layers.Layer
layer that we want to find path from
layer that we want to find path from
node_layer_map
Dict
dictionary includes node_ref as a key, in_layers and out_layer as value
dictionary includes node_ref as a key in_layers and out_layer as value
layer_out_node_map
Dict
dictionary includes layer_ref as a key, outbound nodes as value
dictionary includes layer_ref as a key outbound nodes as value
visited_layers
Set[tf.keras.layers.Layer]
Set of all layers that have been visited
Set of all layers that have been visited
reversed_ordered_layers
List[tf.keras.layers.Layer]
List of layers in the opposite order of occurrence
for the layers that we have visited so far
List of layers in the opposite order of occurrence for the layers that we have visited so far