Exemplo n.º 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)
Exemplo n.º 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)
Exemplo n.º 3
0
    def test_pass_pack_weights(self) -> None:
        """Test pass."""
        data1 = np.float32(np.random.rand(1, 2, 2, 3))
        data2 = np.float32(np.random.rand(1, 2, 2, 3))

        graph1 = self.create_sample_graph(data1, data2)
        pass_pack_weights(graph1)
        self.assertEqual(graph1.get_op('conv2').input_ops['W'].op_type, 'Constant',
                         '[Failed] Found input kernel weights not a constant')

        graph_2_1 = self.create_sample_graph_2(data1)
        graph_2_2 = self.create_sample_graph_2(data1)
        pass_pack_weights(graph_2_2)
        self.assertEqual(graph_2_1, graph_2_2,
                         '[Failed] Found optimized graph not the same')

        print("Test pass #4 pack_weights passed!")