afe.backends.checker_utils ========================== .. py:module:: afe.backends.checker_utils .. autoapi-nested-parse:: This file contains utility functions that are used in deciding if an IR can be supported or not supported in certain backends Attributes ---------- .. autoapisummary:: afe.backends.checker_utils.unsupported_code_codebook Functions --------- .. autoapisummary:: afe.backends.checker_utils.find_matching_attr afe.backends.checker_utils.unsupported_op_code_to_message afe.backends.checker_utils.padding_is_present_and_included afe.backends.checker_utils.exclude_of_reduce_expression_is_true afe.backends.checker_utils.supported_mean_operator_axes_and_input_size afe.backends.checker_utils.keepdims_of_reduce_expression_is_true afe.backends.checker_utils.axes_of_reduce_expression_are_nonzero afe.backends.checker_utils.zero_axis_of_input_has_shape_of_1 afe.backends.checker_utils.dilations_of_pooling_expression_are_greater_than_1 afe.backends.checker_utils.check_resize_is_supported afe.backends.checker_utils.pytorch_half_pixel_is_half_pixel afe.backends.checker_utils.corners_not_aligned afe.backends.checker_utils.pooling_expression_ceil_mode_is_false afe.backends.checker_utils.supported_pool_size afe.backends.checker_utils.pool_explicit_padding_incorrect_dimension afe.backends.checker_utils.axis_is_none_or_contains_0 afe.backends.checker_utils.reduce_axis_is_3 afe.backends.checker_utils.prelu_axis_is_3 afe.backends.checker_utils.softmax_axis_is_3 afe.backends.checker_utils.output_size_shape_is_1 afe.backends.checker_utils.pad_mode_is_constant_and_pad_width_is_0 afe.backends.checker_utils.check_transformation_mode_is_other_than_tf_crop_resize afe.backends.checker_utils.tuple_concat_axis_is_not_0 afe.backends.checker_utils.axes_are_nonzero_or_zero_axis_of_input_has_shape_of_1 afe.backends.checker_utils.dilations_of_conv_transpose_expression_are_1 afe.backends.checker_utils.depthwise_or_number_of_groups_is_1 afe.backends.checker_utils.number_of_groups_is_1 afe.backends.checker_utils.stride_is_power_of_2_upto_16 afe.backends.checker_utils.stride_is_1_or_2 afe.backends.checker_utils.number_of_groups_equals_number_of_input_channels afe.backends.checker_utils.strided_slice_stride_is_1 afe.backends.checker_utils.input_is_4d afe.backends.checker_utils.input_is_4d_or_5d afe.backends.checker_utils.all_tensors_are_float32 afe.backends.checker_utils.all_tensors_are_int8 afe.backends.checker_utils.all_tensors_are_int32 afe.backends.checker_utils.strided_slice_on_chanel_axis_is_mul_of_16 afe.backends.checker_utils.binary_operator_have_same_input_shapes_or_one_scalar_input afe.backends.checker_utils.binary_operator_inputs_are_broadcastable afe.backends.checker_utils.check_number_of_einsum_inputs afe.backends.checker_utils.einsum_equation_is_supported afe.backends.checker_utils.check_strides_in_conv afe.backends.checker_utils.broadcast_to_output_is_4d_and_broadcastable afe.backends.checker_utils.check_transpose_affecting_batch_axis afe.backends.checker_utils.supported_variance_axis afe.backends.checker_utils.supported_gridsample Module Contents --------------- .. py:function:: find_matching_attr(match: Callable[[attrdict.AttrDict], bool], attrs: List[attrdict.AttrDict], *, description: Optional[str] = None) -> attrdict.AttrDict Find and return the first matching attribute dictionary in the list. Raise a ValueError if there is no matching dictionary. :param match: Function that checks whether an attribute dictionary matches. :param attrs: Attributes to search :param description: Description of what it attempts to match. Used when raising an error. :return: First matching attribute in the list .. py:data:: unsupported_code_codebook .. py:function:: unsupported_op_code_to_message(code: Union[int, List[int]]) -> Union[str, List[str]] .. py:function:: padding_is_present_and_included(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if the average pooling operator includes all padding values in the averaging operation. This includes the situation when there is no padding. .. py:function:: exclude_of_reduce_expression_is_true(args: afe.backends.ExprCheckInfo) -> bool Return True if the exclude attribute exists and is True. .. py:function:: supported_mean_operator_axes_and_input_size(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if reduce axes do not contain batch and channel axis, and input size on a reduce axis is less than 128. .. py:function:: keepdims_of_reduce_expression_is_true(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True is the keepdims attribute exists and is True .. py:function:: axes_of_reduce_expression_are_nonzero(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Note: If `exclude` is True, reduction will be performed on the axes that are NOT in axis instead. So if exclude is true we want axes to include zero instead. Note: If `axes` is None the operation is performed across all axes and thus we return false since we reduce along the 0th axis .. py:function:: zero_axis_of_input_has_shape_of_1(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if all input tensors' 0 axis (batch dimension) shape is 1 or all inputs are scalar. .. py:function:: dilations_of_pooling_expression_are_greater_than_1(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if all dilations are 1 .. py:function:: check_resize_is_supported(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Checks if scaling values for h_axis and w_axis are supported for the resize method. If not returns False. The following are supported. 1. Only positive scaling factors are supported. 2. If method is 'linear' or 'bilinear', any scaling factor is supported. However, for 8-bit integers any scaling more than 63 may lead to loss in accuracy. 3. If the method is 'nearest neighbor' a power of two scaling factor is supported. 4. Any other method or scaling factor is not supported. .. py:function:: pytorch_half_pixel_is_half_pixel(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Check if pytorch_half_pixel coordinate transformation mode is same as half_pixel. It will be same if the size of the resized tensor is greater than 1. .. py:function:: corners_not_aligned(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if align_corners is False .. py:function:: pooling_expression_ceil_mode_is_false(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if ceil_mode is False .. py:function:: supported_pool_size(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision .. py:function:: pool_explicit_padding_incorrect_dimension(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Reject if padding is given for the wrong number of dimensions. .. py:function:: axis_is_none_or_contains_0(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision .. py:function:: reduce_axis_is_3(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Accept if the reduce operator performs reduction over axis 3 (the channel axis). The reduction axis is determined from the input shape and the attributes 'axis' and 'exclude'. .. py:function:: prelu_axis_is_3(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if the first attribute's axis is 3. This should be used for checking the composite prelu_const operator. It checks that the PRelu's alpha axis is the channel axis, as required by the MLA. .. py:function:: softmax_axis_is_3(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if the first attribute's axis is 3 or -1. This should be used for checking the composite softmax_const operator. It checks that the Softmax axis is the channel axis, as required by the MLA. .. py:function:: output_size_shape_is_1(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if the output_size attribute is not None and output_size along all dimension are 1 .. py:function:: pad_mode_is_constant_and_pad_width_is_0(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if the padding's pad_mode is 'constant' and the pad_width along all dimensions are 0 .. py:function:: check_transformation_mode_is_other_than_tf_crop_resize(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Does not support when coordinate_transformation_mode in image.resize is 'tf_crop_and_resize' .. py:function:: tuple_concat_axis_is_not_0(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if the axis of tuple_concat is not 0 (not batch dimension) .. py:function:: axes_are_nonzero_or_zero_axis_of_input_has_shape_of_1(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision .. py:function:: dilations_of_conv_transpose_expression_are_1(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if dilations of 2d/3d transpose convolution are all equal to 1 .. py:function:: depthwise_or_number_of_groups_is_1(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision .. py:function:: number_of_groups_is_1(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if the groups attribute is 1 .. py:function:: stride_is_power_of_2_upto_16(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision MLA HW only support stride in the given range: [1, 2, 4, 8, 16] for transposed convolution. Return True if stride value is in that range. .. py:function:: stride_is_1_or_2(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision MLA HW only support stride as 1 or 2 for depthwise transposed convolution. Return True if stride value is 1 or 2. .. py:function:: number_of_groups_equals_number_of_input_channels(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Special case for depthwise conv2d_transpose. Return True if the total groups number in a decomposed conv2d_transpose is same as input channel number. This means the operator is a depthwise operator .. py:function:: strided_slice_stride_is_1(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if strided slice strides are all equal to 1 .. py:function:: input_is_4d(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if all inputs are 4D tensors. .. py:function:: input_is_4d_or_5d(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if all inputs are either 4D or 5D tensors. .. py:function:: all_tensors_are_float32(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if all output types specified in the "output_types" attribute are float32. .. py:function:: all_tensors_are_int8(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if all output types specified in the "output_types" attribute are int8. .. py:function:: all_tensors_are_int32(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if all output types specified in the "output_types" attribute are int32. .. py:function:: strided_slice_on_chanel_axis_is_mul_of_16(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Return True if slice begin or end on channel axis is multiple of 16. End of last part must not be multiple of 16. .. py:function:: binary_operator_have_same_input_shapes_or_one_scalar_input(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Returns True if both inputs are 4D with the same shape or exactly one input is a scalar .. py:function:: binary_operator_inputs_are_broadcastable(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Returns True if both inputs are broadcastable. .. py:function:: check_number_of_einsum_inputs(num_inputs: int) -> Callable[[afe.backends.ExprCheckInfo], afe.backends.backend_checker.Decision] .. py:function:: einsum_equation_is_supported(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Accept if einsum equation is representing a batch matmul operation. .. py:function:: check_strides_in_conv(args: afe.backends.ExprCheckInfo) -> afe.backends.backend_checker.Decision Accept if the value of strides is in range [1, 31]. .. py:function:: broadcast_to_output_is_4d_and_broadcastable(args: afe.backends.ExprCheckInfo) Accept if broadcast shapes are broadcastable. .. py:function:: check_transpose_affecting_batch_axis(args: afe.backends.ExprCheckInfo) Accept if transpose is not affecting the batch_axis (axes[0] == 0). .. py:function:: supported_variance_axis(args: afe.backends.ExprCheckInfo) Accept if axis is all spatial dimensions. .. py:function:: supported_gridsample(args: afe.backends.ExprCheckInfo) -> bool Accept if interpolation is 2D and mode is 'linear' and padding_mode is not 'reflection'.