コード例 #1
0
ファイル: qnn_torch.py プロジェクト: juierror/incubator-tvm
    def _calculate_qparam(inp):
        # reference ATen/native/quantized/cpu/qlinear_dynamic.cpp
        # ChooseQuantizationParams function
        mn = _op.min(inp)
        mx = _op.max(inp)

        # Ensure that the interval contains 0
        mn = _op.minimum(mn, _op.const(0.0, dtype="float32"))
        mx = _op.maximum(mx, _op.const(0.0, dtype="float32"))

        qmax = 255

        # reduce_range became True in v1.6
        if is_version_greater_than("1.5.1"):
            qmax = 127

        scale = (mx - mn) / _expr.const(qmax, dtype="float32")

        zero_point_from_min = -(mn / scale)
        zero_point = _op.cast(_op.round(_op.clip(zero_point_from_min, 0.0, qmax)), "int32")

        return scale, zero_point
コード例 #2
0
ファイル: to_relay.py プロジェクト: zheng-xq/tvm
def _clip(children, attrs, odtype='float32'):
    a_min = attrs.get_float('a_min')
    a_max = attrs.get_float('a_max')
    return op.clip(children[0], a_min, a_max)