예제 #1
0
파일: qnn.py 프로젝트: chisuhua/tvm-ppflow
def concatenate(data,
                input_scales,
                input_zero_points,
                output_scale,
                output_zero_point,
                axis):
    """Concatenate the quantized input tensors along the given axis.

    Parameters
    ----------
    data : Union(List[relay.Expr], Tuple[relay.Expr], TupleWrapper[relay.Expr])
        The list of quantized tensors.

    input_scales : List[relay.Expr]
        The list of scales of input quantized tensors.

    input_zero_points : List[relay.Expr]
        The list of zero points of input quantized tensors.

    output_scale : relay.Expr
        The scale of the output quantized tensor.

    output_zero_point : relay.Expr
        The zero point of the output quantized tensor.

    axis : int
        The axis along which the tensors are concatenated.

    Returns
    -------
    result: relay.Expr
        The concatenated quantized tensor.
    """

    if isinstance(data, (list, tuple)):
        data = Tuple(data)
    elif isinstance(data, TupleWrapper):
        data = data.tuple_value
    if not isinstance(axis, int):
        raise ValueError("For now, we only support integer axis")
    input_scales = list(input_scales)
    input_zero_points = list(input_zero_points)

    return _make.concatenate(data,
                             Tuple(input_scales),
                             Tuple(input_zero_points),
                             output_scale,
                             output_zero_point,
                             axis)
예제 #2
0
파일: vitis_ai.py 프로젝트: jiajuns/tvm
 def visit_tuple(self, tup):
     """Add compiler_begin and compiler_end annotations to Tuple"""
     field_list = []
     cond = int(hash(tup))
     for field in tup.fields:
         if cond in annotator.relay_ids:
             field_list.append(
                 compiler_begin(super().visit(field),
                                annotator.compiler))
         else:
             field_list.append(super().visit(field))
     if cond in annotator.relay_ids:
         return compiler_end(Tuple(field_list), annotator.compiler)
     else:
         return Tuple(field_list)
예제 #3
0
def concatenate(data,
                input_scales,
                input_zero_points,
                output_scale,
                output_zero_point,
                axis):
    """Concatenate the quantized input tensors along the given axis.

    Parameters
    ----------
    data : Union(List[relay.Expr], Tuple[relay.Expr])
        The list of quantized tensors.

    input_scales : List[float32]
        The list of scales of input quantized tensors.

    input_zero_points : List[int32]
        The list of zero points of input quantized tensors.

    output_scale : float32
        The scale of the output quantized tensor.

    output_zero_point : int32
        The zero point of the output quantized tensor.

    axis : int
        The axis along which the tensors are concatenated.

    Returns
    -------
    result: relay.Expr
        The concatenated quantized tensor.
    """

    data = list(data)
    if not data:
        raise ValueError("relay.concatenate requires data to be non-empty.")
    if not isinstance(axis, int):
        raise ValueError("For now, we only support integer axis")

    return _make.concatenate(Tuple(data),
                             [FloatImm("float64", x) for x in input_scales],
                             [IntImm("int32", x) for x in input_zero_points],
                             output_scale,
                             output_zero_point,
                             axis)