Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
0
    def test_pass_compute_thresholds_for_huge_threshold_values(self) -> None:
        """Test pass."""
        data1 = np.float32(np.random.rand(1, 2, 2, 3))
        data2 = np.float32(np.random.uniform(10 ** (-30), 10 ** (-40), size=(1, 2, 2, 3)))
        graph1 = self.create_sample_graph(data1, data2)

        pass_compute_thresholds(graph1)

        self.assertEqual(graph1.get_op('conv2').has_thresholds, True,
                         '[Failed] Found threshold of Conv not calculated')

        print("Test pass #8-1 compute_thresholds of enormous values passed!")
Esempio n. 4
0
    def test_pass_compute_thresholds(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_compute_thresholds(graph1)

        self.assertEqual(graph1.get_op('conv2').has_thresholds, True,
                         '[Failed] Found threshold of Conv not calculated')

        print("Test pass #8 compute_thresholds passed!")