TrainingExtensions/torch/src/python/aimet_torch/cross_layer_equalization.py
def find_downstream_layer_groups_to_scale(op, layer_groups, current_group=None, visited_nodes=None):
        """
        Recursive function to find cls layer groups downstream from a given op
        :param op: Starting op to search from
        :param layer_groups: Running list of layer groups
        :param current_group: Running current layer group
        :param visited_nodes: Running list of visited nodes (to short-circuit recursion)
        :return: None
        """

        if not visited_nodes:
            visited_nodes = []
        if not current_group:
            current_group = []

        if op in visited_nodes:
            return
        visited_nodes.append(op)
        # print("Visiting node: {}".format(op.dotted_name))

        # If current node is Conv2D, add to the current group
        if op.model_module and isinstance(op.model_module.get_module(), (torch.nn.Conv2d, torch.nn.ConvTranspose2d)):
            current_group.append(op.model_module.get_module())

        # Terminating condition for current group
        if not op.model_module or not isinstance(op.model_module.get_module(), (torch.nn.Conv2d, torch.nn.ReLU,
                                                                                torch.nn.PReLU,
                                                                                torch.nn.ConvTranspose2d)):
            if (len(current_group) > 1) and (current_group not in layer_groups):
                layer_groups.append(current_group)
            current_group = []

        if op.output:
            for consumer in op.output.consumers:
                GraphSearchUtils.find_downstream_layer_groups_to_scale(consumer, layer_groups,
                                                                       current_group, visited_nodes)

        # Reached a leaf.. See if the current group has something to grab
        if (len(current_group) > 1) and (current_group not in layer_groups):
            layer_groups.append(current_group)

        Recursive function to find cls layer groups downstream from a given op
        :param op: Starting op to search from
        :param layer_groups: Running list of layer groups
        :param current_group: Running current layer group
        :param visited_nodes: Running list of visited nodes (to short-circuit recursion)
        :return: None
        
Recursive function to find cls layer groups downstream from a given op
Recursive function to find cls layer groups downstream from a given op
def find_downstream_layer_groups_to_scale(op, layer_groups, current_group=None, visited_nodes=None):
        if not visited_nodes:
            visited_nodes = []
        if not current_group:
            current_group = []
        if op in visited_nodes:
            return
        visited_nodes.append(op)
        if op.model_module and isinstance(op.model_module.get_module(), (torch.nn.Conv2d, torch.nn.ConvTranspose2d)):
            current_group.append(op.model_module.get_module())
        if not op.model_module or not isinstance(op.model_module.get_module(), (torch.nn.Conv2d, torch.nn.ReLU,
                                                                                torch.nn.PReLU,
                                                                                torch.nn.ConvTranspose2d)):
            if (len(current_group) > 1) and (current_group not in layer_groups):
                layer_groups.append(current_group)
            current_group = []
        if op.output:
            for consumer in op.output.consumers:
                GraphSearchUtils.find_downstream_layer_groups_to_scale(consumer, layer_groups,
                                                                       current_group, visited_nodes)
        if (len(current_group) > 1) and (current_group not in layer_groups):
            layer_groups.append(current_group)
def find_downstream_layer_groups_to_scale ( op , layer_groups , current_group = None , visited_nodes = None ) : if not visited_nodes : visited_nodes = [ ] if not current_group : current_group = [ ] if op in visited_nodes : return visited_nodes . append ( op ) if op . model_module and isinstance ( op . model_module . get_module ( ) , ( torch . nn . Conv2d , torch . nn . ConvTranspose2d ) ) : current_group . append ( op . model_module . get_module ( ) ) if not op . model_module or not isinstance ( op . model_module . get_module ( ) , ( torch . nn . Conv2d , torch . nn . ReLU , torch . nn . PReLU , torch . nn . ConvTranspose2d ) ) : if ( len ( current_group ) > 1 ) and ( current_group not in layer_groups ) : layer_groups . append ( current_group ) current_group = [ ] if op . output : for consumer in op . output . consumers : GraphSearchUtils . find_downstream_layer_groups_to_scale ( consumer , layer_groups , current_group , visited_nodes ) if ( len ( current_group ) > 1 ) and ( current_group not in layer_groups ) : layer_groups . append ( current_group )
Recursive function to find cls layer groups downstream from a given op
Recursive function to find cls layer groups downstream from a given op
"""
        Recursive function to find cls layer groups downstream from a given op
        :param op: Starting op to search from
        :param layer_groups: Running list of layer groups
        :param current_group: Running current layer group
        :param visited_nodes: Running list of visited nodes (to short-circuit recursion)
        :return: None
        """ # print("Visiting node: {}".format(op.dotted_name)) # If current node is Conv2D, add to the current group # Terminating condition for current group # Reached a leaf.. See if the current group has something to grab
None
op
Starting op to search from
Starting op to search from
layer_groups
Running list of layer groups
Running list of layer groups
current_group
Running current layer group
Running current layer group
visited_nodes
Running list of visited nodes (to short-circuit recursion)
Running list of visited nodes ( to short - circuit recursion )