How to use the onnxruntime.core.providers.nuphar.scripts.model_quantizer.QuantizeConfig.from_dict function in onnxruntime

To help you get started, we’ve selected a few onnxruntime examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github microsoft / onnxruntime / onnxruntime / core / providers / nuphar / scripts / model_quantizer.py View on Github external
other_nodes = [n for n in in_graph.node if n != in_node and fparam_name in n.input and n.op_type != 'MatMul']
    if other_nodes:
        return False

    if in_node.output[0] in qcfg_dict:
        node_qcfg = qcfg_dict[in_node.output[0]]
    else:
        node_qcfg = parse_node_description(in_node)
        if not node_qcfg:
            if not update_qcfg_dict and qcfg_dict:
                # when qcfg_dict is readonly, raise warning if qcfg is not found for this node
                print("Warning: qcfg is not found for node with output: " + in_node.output[0] + ", fall back to default qcfg.")
            node_qcfg = default_qcfg

    w_qcfg = QuantizeConfig.from_dict(node_qcfg['W'])
    x_qcfg = QuantizeConfig.from_dict(node_qcfg['X'])
    symmetric = node_qcfg['Symmetric']

    # for symmetric quantization, both weight and input should be quantized to signed
    assert not symmetric or (w_qcfg.signed() and x_qcfg.signed())
    # quantize_type should match between weight and input
    assert w_qcfg.q_type_bits() == x_qcfg.q_type_bits()

    if fparam_name in converted_weights:
        step, base, qparam_rowsum, qparam, w_qcfg1, symmetric1 = converted_weights[fparam_name]
        # for shared weights, node should use the same kind of quantization
        assert dict(w_qcfg1) == dict(w_qcfg)
        assert symmetric1 == symmetric
    else:
        fparam = nf.get_initializer(fparam_name)
        if fparam is None or len(fparam.shape) != 2:
            return False
github microsoft / onnxruntime / onnxruntime / core / providers / nuphar / scripts / model_quantizer.py View on Github external
# TODO: support GEMM op if needed
    other_nodes = [n for n in in_graph.node if n != in_node and fparam_name in n.input and n.op_type != 'MatMul']
    if other_nodes:
        return False

    if in_node.output[0] in qcfg_dict:
        node_qcfg = qcfg_dict[in_node.output[0]]
    else:
        node_qcfg = parse_node_description(in_node)
        if not node_qcfg:
            if not update_qcfg_dict and qcfg_dict:
                # when qcfg_dict is readonly, raise warning if qcfg is not found for this node
                print("Warning: qcfg is not found for node with output: " + in_node.output[0] + ", fall back to default qcfg.")
            node_qcfg = default_qcfg

    w_qcfg = QuantizeConfig.from_dict(node_qcfg['W'])
    x_qcfg = QuantizeConfig.from_dict(node_qcfg['X'])
    symmetric = node_qcfg['Symmetric']

    # for symmetric quantization, both weight and input should be quantized to signed
    assert not symmetric or (w_qcfg.signed() and x_qcfg.signed())
    # quantize_type should match between weight and input
    assert w_qcfg.q_type_bits() == x_qcfg.q_type_bits()

    if fparam_name in converted_weights:
        step, base, qparam_rowsum, qparam, w_qcfg1, symmetric1 = converted_weights[fparam_name]
        # for shared weights, node should use the same kind of quantization
        assert dict(w_qcfg1) == dict(w_qcfg)
        assert symmetric1 == symmetric
    else:
        fparam = nf.get_initializer(fparam_name)
        if fparam is None or len(fparam.shape) != 2: