afe.backends.checker_utils

This file contains utility functions that are used in deciding if an IR can be supported or not supported in certain backends

Attributes

unsupported_code_codebook

Functions

find_matching_attr(→ attrdict.AttrDict)

Find and return the first matching attribute dictionary in the list.

unsupported_op_code_to_message(→ Union[str, List[str]])

padding_is_present_and_included(...)

Return True if the average pooling operator includes all padding

exclude_of_reduce_expression_is_true(→ bool)

Return True if the exclude attribute exists and is True.

supported_mean_operator_axes_and_input_size(...)

Return True if reduce axes do not contain batch and channel axis,

keepdims_of_reduce_expression_is_true(...)

Return True is the keepdims attribute exists and is True

axes_of_reduce_expression_are_nonzero(...)

Note: If exclude is True, reduction will be performed on the axes that are NOT in axis instead.

zero_axis_of_input_has_shape_of_1(...)

Return True if all input tensors' 0 axis (batch dimension) shape is 1

dilations_of_pooling_expression_are_greater_than_1(...)

Return True if all dilations are 1

check_resize_is_supported(...)

Checks if scaling values for h_axis and w_axis are supported for the resize method. If not

pytorch_half_pixel_is_half_pixel(...)

Check if pytorch_half_pixel coordinate transformation mode is same as half_pixel.

corners_not_aligned(...)

Return True if align_corners is False

pooling_expression_ceil_mode_is_false(...)

Return True if ceil_mode is False

supported_pool_size(...)

pool_explicit_padding_incorrect_dimension(...)

Reject if padding is given for the wrong number of dimensions.

axis_is_none_or_contains_0(...)

reduce_axis_is_3(→ afe.backends.backend_checker.Decision)

Accept if the reduce operator performs reduction over axis 3 (the channel axis).

prelu_axis_is_3(→ afe.backends.backend_checker.Decision)

Return True if the first attribute's axis is 3. This should be used

softmax_axis_is_3(→ afe.backends.backend_checker.Decision)

Return True if the first attribute's axis is 3 or -1. This should be used

output_size_shape_is_1(...)

Return True if the output_size attribute is not None and output_size along

pad_mode_is_constant_and_pad_width_is_0(...)

Return True if the padding's pad_mode is 'constant' and the pad_width along all

check_transformation_mode_is_other_than_tf_crop_resize(...)

Does not support when coordinate_transformation_mode in image.resize is 'tf_crop_and_resize'

tuple_concat_axis_is_not_0(...)

Return True if the axis of tuple_concat is not 0 (not batch dimension)

axes_are_nonzero_or_zero_axis_of_input_has_shape_of_1(...)

dilations_of_conv_transpose_expression_are_1(...)

Return True if dilations of 2d/3d transpose convolution are all equal to 1

depthwise_or_number_of_groups_is_1(...)

number_of_groups_is_1(...)

Return True if the groups attribute is 1

stride_is_power_of_2_upto_16(...)

MLA HW only support stride in the given range: [1, 2, 4, 8, 16] for transposed convolution.

stride_is_1_or_2(→ afe.backends.backend_checker.Decision)

MLA HW only support stride as 1 or 2 for depthwise transposed convolution.

number_of_groups_equals_number_of_input_channels(...)

Special case for depthwise conv2d_transpose.

strided_slice_stride_is_1(...)

Return True if strided slice strides are all equal to 1

input_is_4d(→ afe.backends.backend_checker.Decision)

Return True if all inputs are 4D tensors.

input_is_4d_or_5d(→ afe.backends.backend_checker.Decision)

Return True if all inputs are either 4D or 5D tensors.

all_tensors_are_float32(...)

Return True if all output types specified in the "output_types" attribute are float32.

all_tensors_are_int8(...)

Return True if all output types specified in the "output_types" attribute are int8.

all_tensors_are_int32(...)

Return True if all output types specified in the "output_types" attribute are int32.

strided_slice_on_chanel_axis_is_mul_of_16(...)

Return True if slice begin or end on channel axis is multiple of 16.

binary_operator_have_same_input_shapes_or_one_scalar_input(...)

Returns True if both inputs are 4D with the same shape or exactly one input is a scalar

binary_operator_inputs_are_broadcastable(...)

Returns True if both inputs are broadcastable.

check_number_of_einsum_inputs(...)

einsum_equation_is_supported(...)

Accept if einsum equation is representing a batch matmul operation.

check_strides_in_conv(...)

Accept if the value of strides is in range [1, 31].

broadcast_to_output_is_4d_and_broadcastable(args)

Accept if broadcast shapes are broadcastable.

check_transpose_affecting_batch_axis(args)

Accept if transpose is not affecting the batch_axis (axes[0] == 0).

supported_variance_axis(args)

Accept if axis is all spatial dimensions.

supported_gridsample(→ bool)

Accept if interpolation is 2D

Module Contents

afe.backends.checker_utils.find_matching_attr(match: Callable[[attrdict.AttrDict], bool], attrs: List[attrdict.AttrDict], *, description: str | None = None) attrdict.AttrDict[source]

Find and return the first matching attribute dictionary in the list. Raise a ValueError if there is no matching dictionary.

Parameters:
  • match – Function that checks whether an attribute dictionary matches.

  • attrs – Attributes to search

  • description – Description of what it attempts to match. Used when raising an error.

Returns:

First matching attribute in the list

afe.backends.checker_utils.unsupported_code_codebook[source]
afe.backends.checker_utils.unsupported_op_code_to_message(code: int | List[int]) str | List[str][source]
afe.backends.checker_utils.padding_is_present_and_included(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Return True if the average pooling operator includes all padding values in the averaging operation. This includes the situation when there is no padding.

afe.backends.checker_utils.exclude_of_reduce_expression_is_true(args: afe.backends.ExprCheckInfo) bool[source]

Return True if the exclude attribute exists and is True.

afe.backends.checker_utils.supported_mean_operator_axes_and_input_size(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]
Return True if reduce axes do not contain batch and channel axis,

and input size on a reduce axis is less than 128.

afe.backends.checker_utils.keepdims_of_reduce_expression_is_true(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Return True is the keepdims attribute exists and is True

afe.backends.checker_utils.axes_of_reduce_expression_are_nonzero(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

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

afe.backends.checker_utils.zero_axis_of_input_has_shape_of_1(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Return True if all input tensors’ 0 axis (batch dimension) shape is 1 or all inputs are scalar.

afe.backends.checker_utils.dilations_of_pooling_expression_are_greater_than_1(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Return True if all dilations are 1

afe.backends.checker_utils.check_resize_is_supported(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

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.

  1. If the method is ‘nearest neighbor’ a power of two scaling factor is supported.

  2. Any other method or scaling factor is not supported.

afe.backends.checker_utils.pytorch_half_pixel_is_half_pixel(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

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.

afe.backends.checker_utils.corners_not_aligned(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Return True if align_corners is False

afe.backends.checker_utils.pooling_expression_ceil_mode_is_false(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Return True if ceil_mode is False

afe.backends.checker_utils.supported_pool_size(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]
afe.backends.checker_utils.pool_explicit_padding_incorrect_dimension(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Reject if padding is given for the wrong number of dimensions.

afe.backends.checker_utils.axis_is_none_or_contains_0(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]
afe.backends.checker_utils.reduce_axis_is_3(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

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’.

afe.backends.checker_utils.prelu_axis_is_3(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

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.

afe.backends.checker_utils.softmax_axis_is_3(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

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.

afe.backends.checker_utils.output_size_shape_is_1(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Return True if the output_size attribute is not None and output_size along all dimension are 1

afe.backends.checker_utils.pad_mode_is_constant_and_pad_width_is_0(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Return True if the padding’s pad_mode is ‘constant’ and the pad_width along all dimensions are 0

afe.backends.checker_utils.check_transformation_mode_is_other_than_tf_crop_resize(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Does not support when coordinate_transformation_mode in image.resize is ‘tf_crop_and_resize’

afe.backends.checker_utils.tuple_concat_axis_is_not_0(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Return True if the axis of tuple_concat is not 0 (not batch dimension)

afe.backends.checker_utils.axes_are_nonzero_or_zero_axis_of_input_has_shape_of_1(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]
afe.backends.checker_utils.dilations_of_conv_transpose_expression_are_1(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Return True if dilations of 2d/3d transpose convolution are all equal to 1

afe.backends.checker_utils.depthwise_or_number_of_groups_is_1(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]
afe.backends.checker_utils.number_of_groups_is_1(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Return True if the groups attribute is 1

afe.backends.checker_utils.stride_is_power_of_2_upto_16(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

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.

afe.backends.checker_utils.stride_is_1_or_2(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

MLA HW only support stride as 1 or 2 for depthwise transposed convolution. Return True if stride value is 1 or 2.

afe.backends.checker_utils.number_of_groups_equals_number_of_input_channels(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

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

afe.backends.checker_utils.strided_slice_stride_is_1(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Return True if strided slice strides are all equal to 1

afe.backends.checker_utils.input_is_4d(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Return True if all inputs are 4D tensors.

afe.backends.checker_utils.input_is_4d_or_5d(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Return True if all inputs are either 4D or 5D tensors.

afe.backends.checker_utils.all_tensors_are_float32(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Return True if all output types specified in the “output_types” attribute are float32.

afe.backends.checker_utils.all_tensors_are_int8(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Return True if all output types specified in the “output_types” attribute are int8.

afe.backends.checker_utils.all_tensors_are_int32(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Return True if all output types specified in the “output_types” attribute are int32.

afe.backends.checker_utils.strided_slice_on_chanel_axis_is_mul_of_16(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Return True if slice begin or end on channel axis is multiple of 16. End of last part must not be multiple of 16.

afe.backends.checker_utils.binary_operator_have_same_input_shapes_or_one_scalar_input(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Returns True if both inputs are 4D with the same shape or exactly one input is a scalar

afe.backends.checker_utils.binary_operator_inputs_are_broadcastable(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Returns True if both inputs are broadcastable.

afe.backends.checker_utils.check_number_of_einsum_inputs(num_inputs: int) Callable[[afe.backends.ExprCheckInfo], afe.backends.backend_checker.Decision][source]
afe.backends.checker_utils.einsum_equation_is_supported(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Accept if einsum equation is representing a batch matmul operation.

afe.backends.checker_utils.check_strides_in_conv(args: afe.backends.ExprCheckInfo) afe.backends.backend_checker.Decision[source]

Accept if the value of strides is in range [1, 31].

afe.backends.checker_utils.broadcast_to_output_is_4d_and_broadcastable(args: afe.backends.ExprCheckInfo)[source]

Accept if broadcast shapes are broadcastable.

afe.backends.checker_utils.check_transpose_affecting_batch_axis(args: afe.backends.ExprCheckInfo)[source]

Accept if transpose is not affecting the batch_axis (axes[0] == 0).

afe.backends.checker_utils.supported_variance_axis(args: afe.backends.ExprCheckInfo)[source]

Accept if axis is all spatial dimensions.

afe.backends.checker_utils.supported_gridsample(args: afe.backends.ExprCheckInfo) bool[source]
Accept if interpolation is 2D

and mode is ‘linear’ and padding_mode is not ‘reflection’.