示例#1
0
    def report(self, G, stats):
        table = Tabular()
        header = [
            TabularColumn("name"),
            TabularColumn("creating node"),
            TabularColumn("type"),
            TabularColumn("dimensions", fmt="^"),
            TabularColumn("size", fmt=">d"),
            TabularColumn("count", fmt=">d"),
        ]
        is_quantized = stats and 'qtype' in stats[0]
        if is_quantized:
            header.append(TabularColumn("Q"))

        table.add_row(header)
        total = 0
        for stat in stats:
            row = [str(stat[k]) for k in ['name', 'creating_node', 'type']]
            row.append(str(stat['dims']))
            row.append(stat['dims'].size())
            row.append(stat['count'])
            if is_quantized:
                row.append(str(stat['qtype']))

            table.add_row(row)
            total += stat['dims'].size()
        if self._do_totals:
            row = ["Total", "", "", "", total, ""]
            if is_quantized:
                row.append("")
            table.add_row(row)
        return table
示例#2
0
def test_csv():
    tab = Tabular()
    tab.add_row([TabularColumn('test1'), TabularColumn('test2'), TabularColumn('test3', fmt="^d")])
    tab.add_row(["1", "2", 3])
    output = io.StringIO()
    tab.render(CSVRenderer(output))
    output = output.getvalue()
    assert output == 'test1,test2,test3\r\n1,2,3\r\n'
示例#3
0
    def report(self, G: NNGraph, stats) -> Tabular:
        del stats
        steps = G.graph_state.steps
        liveness = G.graph_state.liveness
        first_node = steps[0]['node']
        active_order = "x".join(first_node.out_dims[0].order)
        tab = Tabular()
        self.do_headers(active_order, tab)

        max_active = 0
        tot_params = 0
        tot_ops = 0

        for i, node, active, params_size, ops in graph_walk(steps, liveness):
            if self._step is not None and self._step != node.step_idx:
                continue
            tot_params += params_size
            if ops:
                tot_ops += ops
            if active > max_active:
                max_active = active

            self.do_operation(node, G, tab, i, active, params_size, ops)

        if self._step is None:
            self.check_do_totals(tab, max_active, tot_params, tot_ops)
        return tab
示例#4
0
def dump_stats_table(stats, do_totals=True, threshold=30):
    table = Tabular()
    do_header(table)
    total = do_rows(stats, table, threshold)
    if do_totals:
        do_total(table, total)
    return table
示例#5
0
 def report(self, G, stats):
     table = Tabular()
     self.do_header(table)
     total = self.do_rows(stats, table)
     if self._do_totals:
         self.do_total(table, total)
     return table
示例#6
0
def test_excel():
    tab = Tabular()
    tab.add_row([
        TabularColumn('test1 is very long'),
        TabularColumnGroup('group',
                           [TabularColumn('test2'),
                            TabularColumn('test3', fmt="^d")])
    ])
    tab.add_row(["1", "2", 3])
    renderer = ExcelRenderer("/tmp/test.xls")
    tab.render(renderer)
示例#7
0
def test_textable():
    tab = Tabular()
    tab.add_row([TabularColumn('test1'), TabularColumn('test2'), TabularColumn('test3', fmt="^d")])
    tab.add_row(["1", "2", 3])
    renderer = TextTableRenderer(maxwidth=80)
    tab.render(renderer)
    output = renderer.get_output()
    assert output == ('+-------+-------+-------+\n'
                      '| test1 | test2 | test3 |\n'
                      '+=======+=======+=======+\n'
                      '| 1     | 2     |   3   |\n'
                      '+-------+-------+-------+')
示例#8
0
    def report(self, G, stats):
        table = Tabular()
        table.add_row([
            TabularColumn("Step", fmt="^d"),
            TabularColumn("Name"),
            TabularColumn("In"),
            TabularColumn("Out"),
            TabularColumn("Weights"),
            TabularColumn("Bias"),
            TabularColumn("Calc"),
            TabularColumn("Acc"),
        ])

        for key, qrec in stats.items():
            if not isinstance(key, NodeId):
                continue
            node = G.node(key.node_name)
            if self._step is not None and self._step != node.step_idx:
                continue
            fnode = node.get_contained_node(
                key.fnode_name) if key.fnode_name else None
            step_idx = node.step_idx
            node = fnode or node
            row = [
                step_idx, node.name,
                emit_qs(qrec.in_qs),
                emit_qs(qrec.out_qs)
            ]
            if isinstance(node, FilterParameters):
                for i in ["weights", "biases", "calc", "acc"]:
                    row.append(emit_q(getattr(qrec, i + '_q')))
            else:
                row += ["", "", "", ""]
            table.add_row(row)
        return table
示例#9
0
    def report(self, G: NNGraph, stats) -> Tabular:
        del stats
        steps = G.graph_state.steps
        liveness = G.graph_state.liveness
        first_node = steps[0]['node']
        active_order = "x".join(first_node.in_dims[0].order)
        tab = Tabular()
        self.do_headers(active_order, tab)

        max_active = 0
        tot_params = 0

        for i, node, active, params_size in graph_walk(steps, liveness):
            tot_params += params_size
            if active > max_active:
                max_active = active

            self.do_operation(node, G, tab, i, active, params_size)

        self.check_do_totals(tab, max_active, tot_params)
        return tab
示例#10
0
    def report(self, G: NNGraph, nodes=None) -> Tabular:
        if nodes is None:
            nodes = G.nodes()

        nodes = sorted(nodes, key=lambda x: x.step_idx)
        start_step = nodes[0].step_idx
        end_step = nodes[-1].step_idx

        steps = G.graph_state.steps
        liveness = G.graph_state.liveness
        first_node = steps[start_step]['node']
        active_order = "x".join(first_node.out_dims[0].order)
        tab = Tabular()
        self.do_headers(active_order, tab)

        max_active = 0
        tot_params = 0
        tot_ops = 0

        for i, node, active, params_size, ops in graph_walk(steps, liveness):
            if node.step_idx < start_step or node.step_idx > end_step:
                continue

            tot_params += params_size
            if ops:
                tot_ops += ops
            if active > max_active:
                max_active = active

            if self._show_constants or not isinstance(node,
                                                      ConstantInputParameters):
                self.do_operation(node, G, tab, i, active, params_size, ops)

        if start_step != end_step:
            self.check_do_totals(tab, max_active, tot_params, tot_ops)
        return tab
示例#11
0
 def report(self, G: NNGraph, stats: Sequence) -> Tabular:
     table = Tabular()
     do_dheader(table, self._one_input)
     for stat in stats.values():
         do_drow(table, stat, self._one_input)
     return table
示例#12
0
    def report(self, G, stats):
        table = Tabular()
        table.add_row([
            TabularColumn("Step", fmt="^d"),
            TabularColumn("Name"),
            TabularColumn("Type"),
            TabularColumn("In"),
            TabularColumn("Out"),
            TabularColumn("Weights"),
            TabularColumn("Bias"),
            TabularColumn("Mulbias"),
            TabularColumn("Calc"),
            TabularColumn("Acc"),
        ])

        # TODO - Fix report for weights_q

        for key, qrec in stats.sorted_iterator(G):
            if not isinstance(key, NodeId):
                continue
            node = G.node(key.node_name)
            if self._step is not None and self._step != node.step_idx:
                continue
            fnode = node.get_contained_node(
                key.fnode_name) if key.fnode_name else None
            step_idx = node.step_idx
            node = fnode or node
            if qrec:
                if self._step is None or not isinstance(
                        qrec, MultScalableFilterQuantizationRecord) or len(
                            qrec.in_qs[1].scale) == 1:
                    if isinstance(node, ConstantInputParameters):
                        row = [
                            step_idx, node.name, qrec.TYPE, "",
                            self.emit_qs(qrec.out_qs,
                                         limit=self._step is None), "", "", "",
                            "", ""
                        ]
                    else:
                        row = [
                            step_idx, node.name, qrec.TYPE,
                            self.emit_qs(qrec.in_qs, limit=self._step is None),
                            self.emit_qs(qrec.out_qs, limit=self._step is None)
                        ]
                        if isinstance(
                                qrec,
                            (SymmetricScalableFilterQuantizationRecord,
                             MultScalableFilterQuantizationRecord)):
                            for i in [1, 2]:
                                row.append(self.emit_qs([qrec.in_qs[i]]))
                            for i in ["mul_biases", "calc", "acc"]:
                                row.append(
                                    self.emit_qs([getattr(qrec, i + '_q')]))
                        else:
                            row += ["", "", "", "", ""]
                else:
                    first = True
                    for chan in range(len(qrec.in_qs[1].scale)):
                        if first:
                            row = [
                                step_idx,
                                node.name,
                                qrec.TYPE,
                                self.emit_qs(qrec.in_qs,
                                             limit=self._step is None),
                                self.emit_qs(qrec.out_qs,
                                             limit=self._step is None),
                                self.emit_q_chan(qrec.in_qs[1], chan),
                                self.emit_q_chan(qrec.in_qs[2], chan),
                                self.emit_q_chan(qrec.mul_biases_q, chan),
                                str(qrec.calc_q),
                                str(qrec.acc_q),
                            ]
                            first = False
                        else:
                            row = [
                                chan, "", "", "", "",
                                self.emit_q_chan(qrec.in_qs[1], chan),
                                self.emit_q_chan(qrec.in_qs[2], chan),
                                self.emit_q_chan(qrec.mul_biases_q, chan), "",
                                ""
                            ]
                        table.add_row(row)
                    continue
            else:
                row = [
                    step_idx, node.name, "IEEE32", "None", "None", "", "", "",
                    "", ""
                ]
            table.add_row(row)
        return table
示例#13
0
    def report(self, G, stats, nodes=None):
        if nodes is None:
            nodes = G.nodes()
        nodes = sorted(nodes, key=lambda x: x.step_idx)
        table = Tabular()
        table.add_row([
            TabularColumn("Step", fmt="^d"),
            TabularColumn("Name"),
            TabularColumn("Type"),
            TabularColumn("In"),
            TabularColumn("Out"),
            TabularColumn("Weights"),
            TabularColumn("Bias"),
            TabularColumn("Mulbias"),
            TabularColumn("Calc"),
            TabularColumn("Acc"),
        ])

        # TODO - Fix report for weights_q
        single = nodes[0].step_idx == nodes[-1].step_idx
        for key, qrec in stats.sorted_iterator(G):
            if not isinstance(key, NodeId):
                continue
            node = G.node(key.node_name)
            if node.step_idx < nodes[0].step_idx or node.step_idx > nodes[
                    -1].step_idx:
                continue
            fnode = node.get_contained_node(
                key.fnode_name) if key.fnode_name else None
            step_idx = node.step_idx
            node = fnode or node
            if qrec:
                if (not single or not qrec.ktype == 'scaled'
                        or not isinstance(node, FilterParameters)
                        or len(qrec.in_qs[1].scale) == 1):
                    if isinstance(node, ConstantInputParameters):
                        row = [
                            step_idx, node.name, qrec.ktype, "",
                            self.emit_qs(qrec.out_qs,
                                         limit=self._step is None), "", "", "",
                            "", ""
                        ]
                    else:
                        row = [
                            step_idx, node.name, qrec.ktype +
                            (" NE16" if qrec.cache.get('ne16') else ""),
                            self.emit_qs(qrec.in_qs, limit=self._step is None),
                            self.emit_qs(qrec.out_qs, limit=self._step is None)
                        ]
                        if isinstance(node, FilterParameters):
                            for i in [1, 2]:
                                row.append(self.emit_qs([qrec.in_qs[i]]))
                            for i in ["mul_biases", "calc", "acc"]:
                                key = f'{i}_q'
                                if key in qrec.cache:
                                    row.append(self.emit_qs([qrec.cache[key]]))
                                else:
                                    row.append("")
                        else:
                            row += ["", "", "", "", ""]
                else:
                    first = True
                    for chan in range(len(qrec.in_qs[1].scale)):
                        if first:
                            row = [
                                step_idx,
                                node.name,
                                qrec.ktype,
                                self.emit_qs(qrec.in_qs,
                                             limit=self._step is None),
                                self.emit_qs(qrec.out_qs,
                                             limit=self._step is None),
                                self.emit_q_chan(qrec.in_qs[1], chan),
                                self.emit_q_chan(qrec.in_qs[2], chan),
                                self.emit_q_chan(qrec.cache['mul_biases_q'],
                                                 chan),
                                str(qrec.cache['calc_q']),
                                str(qrec.cache['acc_q']),
                            ]
                            first = False
                        else:
                            row = [
                                chan, "", "", "", "",
                                self.emit_q_chan(qrec.in_qs[1], chan),
                                self.emit_q_chan(qrec.in_qs[2], chan),
                                self.emit_q_chan(qrec.cache['mul_biases_q'],
                                                 chan), "", ""
                            ]
                        table.add_row(row)
                    continue
            else:
                row = [
                    step_idx, node.name, "IEEE32", "None", "None", "", "", "",
                    "", ""
                ]
            table.add_row(row)
        return table
示例#14
0
 def report(self, G, stats):
     table = Tabular()
     self.do_dheader(table)
     for stat in stats.values():
         self.do_drow(table, stat)
     return table