nncf/experimental/torch/search_building_blocks/search_blocks.py
def check_graph_has_no_act_layer_duplication_after_block_removal(sgraph: SearchGraph,
                                                                 start_node: SearchGraphNode,
                                                                 end_node: SearchGraphNode) -> bool:
    """
    This rule ensures that after the block is deleted there will be no duplication of activation layers.
    """
    #         A             A
    #         |             |
    #        relu          relu
    #         |      =>     |
    #        block         relu
    #         |
    #        relu        forbidden

    pred_start_node = sgraph.get_prev_nodes(start_node.node_key)
    next_end_node = sgraph.get_next_nodes(end_node.node_key)
    if len(next_end_node) == 0 or len(pred_start_node) == 0:
        return True
    if pred_start_node[0].is_dummy:
        pred_start_node = sgraph.get_prev_nodes(pred_start_node[0].node_key)

    if pred_start_node[0].node_type[-1] in PTRELUMetatype.get_all_aliases() \
        and next_end_node[0].node_type[0] in PTRELUMetatype.get_all_aliases():
        return False
    return True

    This rule ensures that after the block is deleted there will be no duplication of activation layers.
    
This rule ensures that after the block is deleted there will be no duplication of activation layers.
This rule ensures that after the block is deleted there will be no duplication of activation layers .
def check_graph_has_no_act_layer_duplication_after_block_removal(sgraph: SearchGraph,
                                                                 start_node: SearchGraphNode,
                                                                 end_node: SearchGraphNode) -> bool:
    pred_start_node = sgraph.get_prev_nodes(start_node.node_key)
    next_end_node = sgraph.get_next_nodes(end_node.node_key)
    if len(next_end_node) == 0 or len(pred_start_node) == 0:
        return True
    if pred_start_node[0].is_dummy:
        pred_start_node = sgraph.get_prev_nodes(pred_start_node[0].node_key)
    if pred_start_node[0].node_type[-1] in PTRELUMetatype.get_all_aliases() \
        and next_end_node[0].node_type[0] in PTRELUMetatype.get_all_aliases():
        return False
    return True
def check_graph_has_no_act_layer_duplication_after_block_removal ( sgraph : SearchGraph , start_node : SearchGraphNode , end_node : SearchGraphNode ) -> bool : pred_start_node = sgraph . get_prev_nodes ( start_node . node_key ) next_end_node = sgraph . get_next_nodes ( end_node . node_key ) if len ( next_end_node ) == 0 or len ( pred_start_node ) == 0 : return True if pred_start_node [ 0 ] . is_dummy : pred_start_node = sgraph . get_prev_nodes ( pred_start_node [ 0 ] . node_key ) if pred_start_node [ 0 ] . node_type [ - 1 ] in PTRELUMetatype . get_all_aliases ( ) and next_end_node [ 0 ] . node_type [ 0 ] in PTRELUMetatype . get_all_aliases ( ) : return False return True
This rule ensures that after the block is deleted there will be no duplication of activation layers.
This rule ensures that after the block is deleted there will be no duplication of activation layers .
"""
    This rule ensures that after the block is deleted there will be no duplication of activation layers.
    """ #         A             A #         |             | #        relu          relu #         |      =>     | #        block         relu #         | #        relu        forbidden
sgraph
SearchGraph
start_node
SearchGraphNode
end_node
SearchGraphNode