Пример #1
0
    def do_qshow(self, args):
        """
Show current quantization settings."""
        self._check_graph()
        self._check_quantized()
        tab = QuantizationReporter(step=args.step).report(
            self.G, self.G.quantization)
        output_table(tab, args)
Пример #2
0
def test_simple_quantization(mnist_graph, mnist_images):
    G = create_graph(mnist_graph, opts={"load_tensors": True})
    G.add_dimensions()
    input_tensor = import_data(mnist_images[0],
                               height=28,
                               width=28,
                               offset=0,
                               divisor=255)
    input_tensor = input_tensor.reshape((28, 28, 1))
    stats_collector = ActivationStatsCollector()
    stats_collector.collect_stats(G, [input_tensor])
    astats = stats_collector.reduce_stats()
    stats_collector = FilterStatsCollector()
    fstats = stats_collector.collect_stats(G)
    quantizer = SymmetricQuantizer(astats, fstats, force_width=8)
    qrecs = quantizer.quantize(G)
    assert len(qrecs) == 11  # One more for saved quantizer
    report = QuantizationReporter().report(G, qrecs)
    renderer = TextTableRenderer(maxwidth=200)
    print(report.render(renderer))
Пример #3
0
    def do_qshow(self, args):
        """
Show current quantization settings."""
        self._check_graph()
        self._check_quantized()
        if args.step:
            nodes, _ = self.get_node_step_or_name(args.step)
            if not nodes:
                return
        else:
            nodes = None
        tab = QuantizationReporter().report(self.G, self.G.quantization, nodes)
        output_table(tab, args)
Пример #4
0
    def do_fquant(self, args: argparse.Namespace):
        """
Attempt to calculate a fake quantization for graph using random tensors and parameters.
This is intended to allow code generation for performance testing even if no real
weights and input data are avalaible."""
        self._check_graph()
        self.G.constant_store.fake = True
        stats_collector = ActivationStatsCollector()
        input_tensors = [
            np.random.normal(0, 0.2, input.dims.shape)
            for input in self.G.input_nodes()
        ]
        stats_collector.collect_stats(self.G, input_tensors)
        astats = stats_collector.reduce_stats()
        stats_collector = FakeFilterStatsCollector()
        fstats = stats_collector.collect_stats(self.G)
        quantizer = SymmetricQuantizer(astats,
                                       fstats,
                                       force_width=args.force_width)
        qrecs = quantizer.quantize(self.G)
        self.G.quantization = qrecs
        tab = QuantizationReporter().report(self.G, qrecs)
        output_table(tab, args)
        self.G.constant_store.fake = False