clip

Description

Rounds data towards the range of [min_value, max_value] by comparing data's elements with min_value and max_value element-wise. If an element value is within the range, the element is retained. If an element value is not within the range, the element is round to the nearest extreme value.

Restrictions

Atlas training products: supports float16, float32, int8, uint8, and int32. However, int8, uint8, and int32 will be cast to float16.

Atlas inference products: supports float16 and float32.

Atlas 200I/500 A2 inference products: supports float16, float32, int8, uint8, and int32. However, int8, uint8, and int32 will be cast to float16.

Atlas A2 training products/Atlas A2 inference products: supports float16, float32, int8, uint8, and int32. However, int8, uint8, and int32 will be cast to float16.

Atlas A3 training products/Atlas A3 inference products: supports float16, float32, int8, uint8, and int32. However, int8, uint8, and int32 will be converted to float16.

In case of data type inconsistency, the data type of max_value and min_value will be cast into the same data type as data during computation.

Prototype

clip(data, max_value, min_value)

Parameters

  • data: a tvm.tensor for the input tensor.
  • max_value: a scalar for the maximum value of the target range.
  • min_value: a scalar for the minimum value of the target range.

Returns

res_tensor: a tvm.tensor for the result tensor

Applicable Models

Atlas training products

Atlas inference products

Atlas 200I/500 A2 inference products

Atlas A2 training products/Atlas A2 inference products

Atlas A3 training products/Atlas A3 inference products

Example

from tbe import tvm
from tbe import dsl
shape = (1024,1024)
input_dtype = "float16"
data = tvm.placeholder(shape, name="data", dtype=input_dtype)
max_value = tvm.const(2, dtype =input_dtype)
min_value = tvm.const(3, dtype =input_dtype)
res = dsl.clip(data, max_value, min_value)