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
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'
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)
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' '+-------+-------+-------+')
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
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
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