예제 #1
0
def optimize_graph_step(graph: Graph, config: Config) -> None:
    """Optimizing graph that imported from tensorflow pb.

    Args:
        graph (Graph): Graph that optimization passes are applying to
        config (Config): Collection of configurations

    Returns:

    
    """

    pass_remove_identities(graph)
    pass_transpose(graph)

    if config.activate_hard_quantization:
        pass_lookup(graph)
        pass_propagate_quantization_details_into_conv(graph)
        if config.threshold_skipping:
            pass_compute_thresholds(graph)
        pass_pack_weights(graph)
        pass_quantize_convolutions(graph)

    if config.threshold_skipping:
        pass_propagate_output_type_backward(graph)
    pass_propagate_datatypes(graph)
    pass_propagate_format(graph)

    pass_constant_folding(graph)
    pass_simplify_batchnorm(graph)
예제 #2
0
def optimize_graph_step(model: Model, config: Config) -> None:
    """Optimize graph in the model.

    Parameters
    ----------
    model : Model
        Model that contains the graph

    config : Config
        Collection of configurations

    """
    graph: Graph = model.graph
    pass_remove_identities(graph)
    pass_transpose(graph)

    if config.activate_hard_quantization:
        pass_lookup(graph)
        pass_propagate_quantization_details_into_conv(graph)
        if config.threshold_skipping:
            pass_compute_thresholds(graph)
        pass_pack_weights(graph)
        pass_quantize_convolutions(graph)
        pass_fix_qtz_types_and_format(graph)

    pass_propagate_output_type_backward(graph)
    pass_propagate_datatypes(graph)
    pass_propagate_format(graph)

    pass_constant_folding(graph)
예제 #3
0
    def test_pass_constant_folding(self) -> None:
        """Test pass."""
        graph1 = self.create_sample_graph()

        pass_constant_folding(graph1)

        self.assertEqual(set(graph1.get_op('potatoes_new').data), set(np.array([2, 5])),
                         '[Failed] Found folded constant not correct')

        print("Test pass #9 constant folding passed!")