afe.ir.operation_functionsο
Classesο
Supported run modes. |
Functionsο
|
|
|
|
|
Execute a floating-point convolution using an algorithm from ml_kernels. |
|
Execute a quantized convolution using an algorithm from ml_kernels. |
|
Compute a floating-point convolution by calling Tensorflow's convolution operator. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Floating-point multiplication. |
|
Quantized multiplication. |
|
|
|
When in quantized set to True, using avg_pool2d to do mean along axis = |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Flattens all the dimensions except for the batch dimension |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AFE and MLA does not have a way to support nearest_neighbor with asymmetric. However, |
|
Upsample the input tensor along H and/or W dimension |
|
Image interpolation through GridSample |
|
|
|
|
|
|
|
|
|
|
|
Input tensor is 4D NHWC, int8 only |
|
Input tensor is 2D |
|
Helper function to get a tensor shape where channel is aligned based on the element size. |
|
|
|
Reshape tensor to MLA 2D buffer shape (batch_size, data_size (D * H * W * C)) where data size |
|
Reshape tensor from MLA 2D shape to 4D/5D shape. |
|
Multiple tensors are packed sequentially as a 2D array. |
|
A 2D array is unpacked to produce multiple 2D arrays |
|
Normalization performs the following three steps: |
|
Quantization transform. |
|
Dequantization transform. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
For the rounding type used for this operator (away from 0), refer to: |
|
|
|
|
|
|
|
|
|
|
|
Initialize the custom op. Compile the custom op and put it into the |
|
Execute the custom op |
|
Execute batch matmul operation. |
Module Contentsο
- class afe.ir.operation_functions.RunMode[source]ο
Supported run modes. MLA_MODE : use an implementation that exactly matches execution on the MLA. FAST_MODE : use a fast execution implementation
- afe.ir.operation_functions.float_convolution(attrs: afe.ir.attributes.ConvAddActivationAttrs, data: numpy.ndarray, mode: RunMode) numpy.ndarray [source]ο
Execute a floating-point convolution using an algorithm from ml_kernels.
- Parameters:
attrs β Attributes of the convolution operator
data β Input activation data in NHWC layout
mode β Mode of execution
- Returns:
Convolved result
- afe.ir.operation_functions.quantized_convolution(attrs: afe.ir.attributes.ConvQuantAttrs, data: numpy.ndarray, mode: RunMode) numpy.ndarray [source]ο
Execute a quantized convolution using an algorithm from ml_kernels.
- Parameters:
attrs β Attributes of the convolution operator
data β Input activation data in NHWC layout
mode β Mode of execution
- Returns:
Convolved result
- afe.ir.operation_functions.conv_tensorflow(attrs: afe.ir.attributes.ConvAttrs, data: numpy.ndarray, weight: numpy.ndarray) numpy.ndarray [source]ο
Compute a floating-point convolution by calling Tensorflowβs convolution operator.
This function may not exactly match MLA behavior.
- Parameters:
attrs β Attributes of the convolution
data β Input tensor
weight β Weight tensor
Returns: Convolved tensor
- afe.ir.operation_functions.add(lhs: numpy.ndarray, rhs: numpy.ndarray, axis: int | None = None) numpy.ndarray [source]ο
- afe.ir.operation_functions.clip(attrs: afe.ir.attributes.ClipAttrs | afe.ir.attributes.ClipQuantAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.prelu(data: numpy.ndarray, alpha: numpy.ndarray | float | int, axis: int | None = None, zp: int = 0) numpy.ndarray [source]ο
- afe.ir.operation_functions.leaky_relu(data: numpy.ndarray, alpha: float | int) numpy.ndarray [source]ο
- afe.ir.operation_functions.maxpool(attrs: afe.ir.attributes.PoolAttrs, data: numpy.ndarray, pad_value: float | int, mode: RunMode = RunMode.MLA_MODE) numpy.ndarray [source]ο
- afe.ir.operation_functions.avgpool(attrs: afe.ir.attributes.PoolAttrs, data: numpy.ndarray, pad_value: float | int, quantized: bool = False, rounding_type: ml_kernels.math_helpers.RoundType | None = None, requant: ml_kernels.requantization.BaseRequantization | None = None, mode: RunMode = RunMode.MLA_MODE) numpy.ndarray [source]ο
- afe.ir.operation_functions.variance(data: numpy.ndarray, mean: numpy.ndarray, requant: ml_kernels.requantization.BaseRequantization | None = None, requant_var: ml_kernels.requantization.BaseRequantization | None = None)[source]ο
- afe.ir.operation_functions.adaptive_avgpool2d(attrs: afe.ir.attributes.AdaptiveAvgPool2DAttrs, data: numpy.ndarray, quantized: bool = False, rounding_type: ml_kernels.math_helpers.RoundType | None = None, *args, **kwargs) numpy.ndarray [source]ο
- afe.ir.operation_functions.broadcast_to(attrs: afe.ir.attributes.BroadcastToAttrs | afe.ir.attributes.BroadcastToQuantAttrs, data: numpy.ndarray)[source]ο
- afe.ir.operation_functions.multiply(lhs: numpy.ndarray, rhs: numpy.ndarray) numpy.ndarray [source]ο
Floating-point multiplication.
- afe.ir.operation_functions.quantized_multiply(attrs: afe.ir.attributes.MultiplyQuantAttrs, lhs: numpy.ndarray, rhs: numpy.ndarray) numpy.ndarray [source]ο
Quantized multiplication.
- afe.ir.operation_functions.pad(attrs: afe.ir.attributes.PadAttrs, data: numpy.ndarray, pad_value: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.mean(attrs: afe.ir.attributes.MeanAttrs, data: numpy.ndarray, quantized=False) numpy.ndarray [source]ο
- When in quantized set to True, using avg_pool2d to do mean along axis =
(1, 2)
Parametersο
- param attrs:
MeanAttrs. Attributes needed to execute the mean operation.
- param data:
np.ndarray. Input data to the mean operation.
- param quantized:
bool. Default is False. Set to True if the mean operation is executed in a quantization domain.
Returnο
- return:
np.ndarray. Result of the mean operation.
- afe.ir.operation_functions.squeeze(attrs: afe.ir.attributes.SqueezeAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.argmax(attrs: afe.ir.attributes.ArgMaxAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.softmax(attrs: afe.ir.attributes.SoftmaxAttrs | afe.ir.attributes.SoftmaxQuantAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.lrn(attrs: afe.ir.attributes.LRNAttrs | afe.ir.attributes.LRNQuantAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.concatenate(attrs: afe.ir.attributes.ConcatenateAttrs, data_list: List[numpy.ndarray]) numpy.ndarray [source]ο
- afe.ir.operation_functions.transpose(attrs: afe.ir.attributes.TransposeAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.depth_to_space(attrs: afe.ir.attributes.DepthToSpaceAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.reshape(attrs: afe.ir.attributes.ReshapeAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.expand_dims(attrs: afe.ir.attributes.ExpandDimsAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.batch_flatten(data: numpy.ndarray) numpy.ndarray [source]ο
Flattens all the dimensions except for the batch dimension
- afe.ir.operation_functions.min_op(attrs: afe.ir.attributes.ExtmAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.max_op(attrs: afe.ir.attributes.ExtmAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.sum_op(attrs: afe.ir.attributes.SumAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.prod(attrs: afe.ir.attributes.ProdAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.tuple_get_item(attrs: afe.ir.attributes.TupleGetItemAttrs, t: tuple) numpy.ndarray [source]ο
- afe.ir.operation_functions.subtract(lhs: numpy.ndarray, rhs: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.maximum(lhs: numpy.ndarray, rhs: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.minimum(lhs: numpy.ndarray, rhs: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.full(attrs: afe.ir.attributes.FullAttrs, fill_value: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.tile(attrs: afe.ir.attributes.TileAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.split(attrs: afe.ir.attributes.SplitAttrs, data: numpy.ndarray) Tuple[numpy.ndarray, Ellipsis] [source]ο
- afe.ir.operation_functions.take(attrs: afe.ir.attributes.TakeAttrs, data: numpy.ndarray, indices: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.strided_slice(attrs: afe.ir.attributes.StridedSliceAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.image_resize2d(attrs: afe.ir.attributes.ImageResize2DAttrs, data: numpy.ndarray, rounding: str | None = None) numpy.ndarray [source]ο
AFE and MLA does not have a way to support nearest_neighbor with asymmetric. However, the error should be ignorable during inference.
- afe.ir.operation_functions.upsample(attrs: afe.ir.attributes.UpsamplingAttrs, data: numpy.ndarray, rounding: str | None = None) numpy.ndarray [source]ο
Upsample the input tensor along H and/or W dimension
- afe.ir.operation_functions.gridsample(attrs: afe.ir.attributes.GridSampleAttrs, data: numpy.ndarray, grid: numpy.ndarray) numpy.ndarray [source]ο
Image interpolation through GridSample
- afe.ir.operation_functions.layer_norm(attrs: afe.ir.attributes.LayerNormAttrs | afe.ir.attributes.LayerNormQuantAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.rms_norm(data: numpy.ndarray, attrs: afe.ir.attributes.RMSNormAttrs | afe.ir.attributes.RMSNormQuantAttrs) numpy.ndarray [source]ο
- afe.ir.operation_functions.instance_norm(data: numpy.ndarray, mean: numpy.ndarray, variance: numpy.ndarray, attrs: afe.ir.attributes.InstanceNormAttrs | afe.ir.attributes.InstanceNormQuantAttrs)[source]ο
- afe.ir.operation_functions.layout_transform(attrs: afe.ir.attributes.LayoutTransformAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.calculate_tessellated_tensor_shape(tensor_type: afe.ir.tensor_type.TensorType, slice_shape: Sequence[int], align_c16: bool) tuple[int, int] [source]ο
- afe.ir.operation_functions.tessellation(attrs: afe.ir.attributes.TessellationTransformAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
Input tensor is 4D NHWC, int8 only Output tensor is 2D array
- afe.ir.operation_functions.detessellation(attrs: afe.ir.attributes.DetessellationTransformAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
Input tensor is 2D Output tensor is 4D: NHWC
- afe.ir.operation_functions.get_channel_aligned_shape(tensor_shape: Sequence[int], elem_size: int) tuple[int, Ellipsis] [source]ο
Helper function to get a tensor shape where channel is aligned based on the element size.
- afe.ir.operation_functions.get_mla_padded_2d_shape(tensor_shape: Sequence[int], elem_size: int) tuple[int, int] [source]ο
- afe.ir.operation_functions.reshape_to_mla_padded_2d_shape(tensor: numpy.ndarray) numpy.ndarray [source]ο
Reshape tensor to MLA 2D buffer shape (batch_size, data_size (D * H * W * C)) where data size must be multiple of 16.
- afe.ir.operation_functions.reshape_from_mla_padded_2d_shape(tensor: numpy.ndarray, data_shape: Sequence[int], tensor_type: type) numpy.ndarray [source]ο
Reshape tensor from MLA 2D shape to 4D/5D shape.
- Parameters:
tensor β 2D tensor.
data_shape β 4D/5D tensor shape.
- Returns:
Reshaped 4D/5D tensor.
- afe.ir.operation_functions.pack(data: List[numpy.ndarray]) numpy.ndarray [source]ο
Multiple tensors are packed sequentially as a 2D array. Input data can be either a 2D tessellated tensor or
a 4D tensor that will be tessellated on the MLA.
If there is the 4D tensor reshape it to MLA 2D shape.
- afe.ir.operation_functions.unpack(attrs: afe.ir.attributes.UnpackTransformAttrs, data: numpy.ndarray) List[numpy.ndarray] [source]ο
A 2D array is unpacked to produce multiple 2D arrays
- afe.ir.operation_functions.normalization(attrs: afe.ir.attributes.NormalizationTransformAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
Normalization performs the following three steps: 1) Divide by a per-channel divisor 2) Subtract by per-channel mean values 3) Divide by per-channel standard deviation values
- afe.ir.operation_functions.ev_quantize(attrs: afe.ir.attributes.QuantizationTransformAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
Quantization transform.
- afe.ir.operation_functions.ev_dequantize(attrs: afe.ir.attributes.DequantizationTransformAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
Dequantization transform.
- afe.ir.operation_functions.ev_resize(attrs: afe.ir.attributes.ResizeTransformAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.chroma_upsample(attrs: afe.ir.attributes.ChromaUpsampleTransformAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.yuv_rgb_conversion(attrs: afe.ir.attributes.YuvRgbConversionTransformAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.bgr_rgb_conversion(attrs: afe.ir.attributes.BgrRgbConversionTransformAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.ev_sigmoid(attrs: afe.ir.attributes.SigmoidTransformAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.nms_maxpool(attrs: afe.ir.attributes.NmsMaxpoolTransformAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.cast(attrs: afe.ir.attributes.CastAttrs, data: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.qnn_quantize(attrs: afe.ir.attributes.QNNQuantizeAttrs, data: numpy.ndarray, output_scale: numpy.ndarray, output_zero_point: numpy.ndarray) numpy.ndarray [source]ο
For the rounding type used for this operator (away from 0), refer to: https://github.com/apache/tvm/pull/3512/commits/c089ebcdf4b13f98b776bb0213779f6783fa6743#diff-a47be721cf0f30d86d0f548a8cc5a1fe184d0827efd450c8446bfc05d962abf5R47
- afe.ir.operation_functions.qnn_dequantize(attrs: afe.ir.attributes.QNNDequantizeAttrs, data: numpy.ndarray, input_scale: numpy.ndarray, input_zero_point: numpy.ndarray) numpy.ndarray [source]ο
- afe.ir.operation_functions.qnn_add(attrs: afe.ir.attributes.AwesomeAttributes, lhs: numpy.ndarray, rhs: numpy.ndarray, lhs_scale: float, lhs_zero_point: int, rhs_scale: float, rhs_zero_point: int, output_scale: float, output_zero_point: int, op: str = 'add') numpy.ndarray [source]ο
- afe.ir.operation_functions.qnn_mul(attrs: afe.ir.attributes.AwesomeAttributes, lhs: numpy.ndarray, rhs: numpy.ndarray, lhs_scale: float, lhs_zero_point: int, rhs_scale: float, rhs_zero_point: int, output_scale: float, output_zero_point: int) numpy.ndarray [source]ο
- afe.ir.operation_functions.external(attrs: afe.ir.attributes.ExternalAttrs, input_dict: Dict[str, numpy.ndarray]) numpy.ndarray | Tuple[numpy.ndarray, Ellipsis] [source]ο
- afe.ir.operation_functions.init_custom_op(attrs: afe.ir.attributes.CustomOpAttrs, input_dict: Dict[afe.ir.defines.InputName, numpy.ndarray], output_shape: Tuple[int, Ellipsis], force_compile: bool = True) None [source]ο
Initialize the custom op. Compile the custom op and put it into the CustomOpLibraryManager. Update the CustomOpAttrs with generated arguments list and function so it can be used at the execution time. :param attrs: CustomOpAttrs :param input_dict: Dict[InputName, np.ndarray]. Input name to its tensor :param output_shape: Tuple[int, β¦]. Output shape :param force_compile: bool. Default is True. If True, the init_custom_op will
compile the custom op no matter the library is ready or not
- afe.ir.operation_functions.execute_custom_op(attrs: afe.ir.attributes.CustomOpAttrs, input_dict: Dict[afe.ir.defines.InputName, numpy.ndarray]) numpy.ndarray [source]ο
Execute the custom op :param attrs: CustomOpAttrs :param input_dict: Dict[InputName, np.ndarray]. Input name to its tensor :return: np.ndarray
- afe.ir.operation_functions.batch_matmul(lhs: numpy.ndarray, rhs: numpy.ndarray, attrs: afe.ir.attributes.BatchMatmulAttrs | afe.ir.attributes.BatchMatmulQuantAttrs) numpy.ndarray [source]ο
Execute batch matmul operation.
- Parameters:
lhs β Tensor representing lhs value of batch matmul operation.
rhs β Tensor representing rhs value of batch matmul operation.
attrs β BatchMatmul operatorβs attributes.
- Returns:
The result of batch matmul operation.