Пример #1
0
def test_graph_calc_quantized8_qnoq(mnist_unfused_8bit_state, mnist_images):
    G = load_state(mnist_unfused_8bit_state)
    input_tensor = import_data(mnist_images[0],
                               height=28,
                               width=28,
                               offset=0,
                               divisor=255)
    input_tensor = input_tensor.reshape((28, 28, 1))
    executer = GraphExecuter(G, qrecs=G.quantization)
    diffs = []
    for step_idx, pnode, output, details, qoutput, qdetails, fnode in\
        executer.execute_qnoq_iterator([input_tensor]):
        del step_idx, pnode, details, qdetails, fnode
        diffs.append(output[0] - qoutput[0])
    assert np.max(np.abs(diffs[7])) < 9
Пример #2
0
    def _collect_execution(self, G, tensors, qrecs):
        outputs = []
        fusion_outputs = []
        executer = GraphExecuter(G, qrecs)
        for step_idx, node, output, details, qoutput, qdetails, fusion_node in\
                executer.execute_qnoq_iterator(tensors):
            output = [np.copy(out) for out in output]
            qoutput = [np.copy(out) for out in qoutput]

            if fusion_node:
                fusion_outputs.append({
                    "name":
                    "",
                    "step_idx":
                    "{}_{}".format(step_idx, len(fusion_outputs)),
                    "node":
                    fusion_node,
                    "output":
                    output,
                    "details":
                    details,
                    "qoutput":
                    qoutput,
                    "qdetails":
                    qdetails
                })
            else:
                stat = {
                    "name": node.name,
                    "step_idx": str(step_idx),
                    "node": node,
                    "output": output,
                    "details": details,
                    "qoutput": qoutput,
                    "qdetails": qdetails,
                    "fusion_outputs": []
                }
                if len(fusion_outputs) > 0:
                    stat['fusion_outputs'] = fusion_outputs.copy()
                    fusion_outputs.clear()
                outputs.append(stat)
        return outputs