def compute_scale_zp_pof2s(rmin, rmax, qmin, qmax, symmetric=False):
    """Calculate the scale s and zero point z for the quantization relation
    r = s(q-z), where r are the original values and q are the corresponding
    quantized values.

    r and z are calculated such that every value within [rmin,rmax] has an
    approximate representation within [qmin,qmax]. In addition, qmin <= z <=
    qmax is enforced. If the symmetric flag is set to True, the interval
    [rmin,rmax] is symmetrized to [-absmax, +absmax], where
    absmax = max(abs(rmin), abs(rmax)).

    :parameter rmin: minimum value of r
    :parameter rmax: maximum value of r
    :parameter qmin: minimum value representable by the target quantization data type
    :parameter qmax: maximum value representable by the target quantization data type
    :return: zero and scale [z, s]

    """

    if qmin > 0 or qmax < 0:
        raise ValueError(f"qmin and qmax must meet requirement: qmin <= 0 <= qmax while qmin:{qmin}, qmmax:{qmax}")

    # Adjust rmin and rmax such that 0 is included in the range. This is
    # required to make sure zero can be represented by the quantization data
    # type (i.e. to make sure qmin <= zero_point <= qmax)
    if is_ort_version_below_1_17():
        rmin = min(rmin, 0)
        rmax = max(rmax, 0)

        if rmin == float("-inf"):
            rmin = -sys.float_info.max / 2
        if rmax == float("inf"):
            rmax = sys.float_info.max / 2

        if symmetric:
            absmax = max(abs(rmin), abs(rmax))
            rmin = -absmax
            rmax = +absmax

        scale = (rmax - rmin) / float(qmax - qmin)

        pos = scale2pos(scale)
        pof2_scale = pos2scale(pos)

        if pof2_scale < np.finfo(np.float32).tiny:
            pof2_scale = 1.0
            zero_point = 0
        else:
            zero_point = round(qmin - rmin / pof2_scale)
        if symmetric:
            zero_point = 0
    else:
        # hasattr(rmin, "dtype") is True for onnxruntime>=1.17
        rmin_dtype = rmin.dtype if hasattr(rmin, "dtype") else np.float32

        rmin = np.minimum(rmin, np.array(0, dtype=rmin_dtype))
        rmax = np.maximum(rmax, np.array(0, dtype=rmin_dtype))

        # Ensure that rmax-rmin is less than or equal to sys.float_info.max
        if rmin == float("-inf"):
            rmin = -np.finfo(rmin_dtype).max / 2
        if rmax == float("inf"):
            rmax = np.finfo(rmin_dtype).max / 2

        if symmetric:
            absmax = np.maximum(np.abs(rmin), np.abs(rmax))
            rmin = -absmax
            rmax = +absmax

        assert qmin <= qmax, f"qmin={rmin} > qmax={rmax}"
        dr = np.array(rmax - rmin, dtype=np.float64)
        dq = np.array(qmax, dtype=np.float64) - np.array(qmin, dtype=np.float64)
        scale = np.array(dr / dq)

        pos = scale2pos(scale)
        pof2_scale = pos2scale(pos)

        has_dtype = hasattr(qmin, "dtype")  # True for onnxruntime>=1.17

        if pof2_scale < np.finfo(rmax.dtype).tiny:
            pof2_scale = np.array(1.0, dtype=rmax.dtype)
            zero_point = np.array(0, dtype=qmin.dtype) if has_dtype else 0
        else:
            pof2_scale = np.array(pof2_scale, dtype=rmin_dtype)
            zero_point = (
                np.array(np.round(qmin - rmin / pof2_scale), dtype=qmin.dtype)
                if has_dtype
                else int(round(qmin - rmin / pof2_scale))
            )
        if symmetric:
            zero_point = np.array(0, dtype=qmin.dtype) if has_dtype else 0
    return [zero_point, pof2_scale]
Calculate the scale s and zero point z for the quantization relation
    r = s(q-z), where r are the original values and q are the corresponding
    quantized values.

    r and z are calculated such that every value within [rmin,rmax] has an
    approximate representation within [qmin,qmax]. In addition, qmin <= z <=
    qmax is enforced. If the symmetric flag is set to True, the interval
    [rmin,rmax] is symmetrized to [-absmax, +absmax], where
    absmax = max(abs(rmin), abs(rmax)).

    :parameter rmin: minimum value of r
    :parameter rmax: maximum value of r
    :parameter qmin: minimum value representable by the target quantization data type
    :parameter qmax: maximum value representable by the target quantization data type
    :return: zero and scale [z, s]

    
olive/passes/onnx/vitis_ai/quant_utils.py