afe.ir.attributes
Attributes
Classes
A value distribution that was observed during calibration. This value |
|
The result of running the quantization transformation on a tensor. |
|
Calibration attributes |
|
Base class of quantized operator attributes. This class is used for instance |
|
Properties of a quantized placeholder. |
|
Contains quantization attributes for concatenate quantization. |
|
param lhs_input_shape: Lhs input shape |
|
The slope for quantized_intput < zero_point is (alpha >> right_shift) |
|
A class that stores attributes necessary for the execution of its associated AwesomeOperation. |
|
Properties of a placeholder. |
|
Attributes of a multiply operator. |
|
Attributes of a convolution operation. |
|
Attributes of an add operator. |
|
Attributes of a subtract operator. |
|
Attributes representing the computation (a*c + b*d) for scalar constants c and d. |
|
Contains quantization attributes for mean quantization. |
|
Instance Normalization operator attributes. |
|
Attributes for Clip operation. Clip operation is always merged into a composite operator. |
|
Attributes for extremum op, can be min or max op depending on the max boolean. |
|
Attributes of GridSample operator. |
|
A class that stores attributes necessary for the execution of its associated AwesomeOperation. |
|
A class that stores attributes necessary for the execution of its associated AwesomeOperation. |
|
Do nothing. Used for better structuring data structure |
|
A class that stores attributes necessary for the execution of its associated AwesomeOperation. |
|
Attributes of DepthToSpace operator |
|
Do nothing. Used for better structuring data structure |
|
Do nothing. Used for better structuring data structure |
|
Common attributes for UDF functions: |
|
Common attributes for UDF functions: |
|
Attributes for Clip operation. Clip operation is always merged into a composite operator. |
|
Base class of quantized operator attributes. This class is used for instance |
|
A class that stores attributes necessary for the execution of its associated AwesomeOperation. |
|
Attributes of a fused convolution operator consisting of convolution, optional bias-add, |
|
A class that stores attributes necessary for the execution of its associated AwesomeOperation. |
|
Further reference: tvm/src/relay/qnn/op/quantize.cc |
|
Further reference: tvm/src/relay/qnn/op/dequantize.cc |
|
Further reference: tvm/src/relay/qnn/op/requantize.cc |
|
Custom Op AwesomeAttributes |
|
Attributes for quantized AddActivationOp. |
|
param attrs: SubtractAttrs class holding SubtractOp parameters |
|
Used for all variants of convolution. |
|
Quantized Instance Normalization operator attributes. |
|
Base class of quantized operator attributes. This class is used for instance |
|
Contains quantization attributes for concatenate quantization. |
|
Contains quantization attributes for custom operation quantization. |
|
Contains quantization attributes for pool quantization. |
|
Base class of quantized operator attributes. This class is used for instance |
|
A class that stores attributes necessary for the execution of its associated AwesomeOperation. |
|
Base class of quantized operator attributes. This class is used for instance |
|
Contains quantization attributes for both UDF and breakdown LeakyRelu quantization. |
|
The slope for quantized_intput < zero_point is (alpha >> right_shift) |
|
A class that stores attributes necessary for the execution of its associated AwesomeOperation. |
|
Base class of quantized operator attributes. This class is used for instance |
|
A class that stores attributes necessary for the execution of its associated AwesomeOperation. |
|
Base class of quantized operator attributes. This class is used for instance |
|
A class that stores attributes necessary for the execution of its associated AwesomeOperation. |
|
Base class of quantized operator attributes. This class is used for instance |
|
Base class of quantized operator attributes. This class is used for instance |
Functions
Get the quantization scale; if there is none, return a dummy value. |
|
Run get_quant_result_scale_with_dummy on the contents of a DataValue. |
|
Run get_quant_result_scale_with_dummy on the contents of a dict of DataValue. |
|
Insert the given quantization into t, replacing existing quantization values in t. |
|
Ensure that t's type matches new_type by replacing dummy types with data from t and |
|
Modifies DataValue of QuantResultTensorType with given batch size. |
|
|
|
|
Get the shape of a convolution's output tensor based on its attributes. |
Module Contents
- class afe.ir.attributes.ObservedDistribution(observer: afe.ir.node_observer.NodeObserver)[source]
A value distribution that was observed during calibration. This value distribution can be used to decide how to quantize a tensor.
- calculate_quantization(qrange: Tuple[int, int]) afe.ir.defines.DataValue[afe.ir.defines.Quantization] [source]
Choose a quantization to use for representing the observed value distribution using the given integer range.
- Parameters:
qrange – Integer range to quantize for. The range must be representable by an 8-bit or 16-bit signed integer.
- Returns:
Selected quantizations.
- class afe.ir.attributes.QuantResultTensorType[source]
The result of running the quantization transformation on a tensor. It has the tensor’s type and quantization, as they are after the transformation. Only tensors that are quantized by the transformation have a quantization.
- Parameters:
type – The tensor’s type after transformation. It has the same shape as before the transformation. Its scalar type may be different.
quant – The tensor’s quantization, if it was quantized by the quantization transformation. None otherwise. Floating-point tensors do not have a quantization. Integer tensors do not have a quantization if they were already integer before the quantization transformation.
requant_method – The method that should be used for requantizing this tensor’s value when requantization is needed. This field must be None iff quant is None.
- quant: afe.ir.defines.Quantization | None[source]
- requant_method: afe.ir.defines.RequantMethod | None[source]
- static from_type(type: afe.ir.tensor_type.TensorType) QuantResultTensorType [source]
Make a QuantResultTensorType that only has type information.
- static from_quant(quant: afe.ir.defines.Quantization | None) QuantResultTensorType [source]
Make a QuantResultTensorType from a Quantization using dummy type information. This is a temporary method that should be removed when support for QuantResultTensorType is finished.
- afe.ir.attributes.get_quant_result_scale_with_dummy(t: QuantResultTensorType) afe.ir.defines.Quantization [source]
Get the quantization scale; if there is none, return a dummy value.
The dummy value is a temporary solution that should be removed when support for QuantResultTensorType is finished.
- afe.ir.attributes.get_data_value_quant_result_scale_with_dummy(t: afe.ir.defines.DataValue[QuantResultTensorType]) afe.ir.defines.DataValue[afe.ir.defines.Quantization] [source]
Run get_quant_result_scale_with_dummy on the contents of a DataValue.
- afe.ir.attributes.get_dict_quant_result_scale_with_dummy(t: Dict[afe.ir.defines.InputName, afe.ir.defines.DataValue[QuantResultTensorType]]) Dict[afe.ir.defines.InputName, afe.ir.defines.DataValue[afe.ir.defines.Quantization]] [source]
Run get_quant_result_scale_with_dummy on the contents of a dict of DataValue.
- afe.ir.attributes.update_quant_result_quantization(t: afe.ir.defines.DataValue[QuantResultTensorType], new_quant: afe.ir.defines.DataValue[afe.ir.defines.Quantization]) afe.ir.defines.DataValue[QuantResultTensorType] [source]
Insert the given quantization into t, replacing existing quantization values in t.
- Parameters:
t – Quantization result type to modify
new_quant – Quantization values
- Returns:
A copy of t with values from new_type inserted
- afe.ir.attributes.update_quant_result_type(t: afe.ir.defines.DataValue[QuantResultTensorType], new_type: afe.ir.defines.DataValue[afe.ir.tensor_type.TensorType]) afe.ir.defines.DataValue[QuantResultTensorType] [source]
Ensure that t’s type matches new_type by replacing dummy types with data from t and checking non-dummy types.
This function’s purpose is to save the type into t while developing QuantResultTensorType, then to check consistency after it is developed.
- Parameters:
t – Quantization result type, which may contain dummy types
new_type – Type that should be the same as the type in t
- Returns:
A copy of t with values from new_type inserted to replace any dummy types
- afe.ir.attributes.set_quant_result_type_batch_size(t: afe.ir.defines.DataValue[QuantResultTensorType], batch_size: int) afe.ir.defines.DataValue[QuantResultTensorType] [source]
Modifies DataValue of QuantResultTensorType with given batch size.
- Parameters:
t – DataValue[QuantResultTensorType]. Value to be modified.
batch_size – int. Batch size value to be used in constructing new QuantResultTensorType DataValue.
- Returns:
DataValue[QuantResultTensorType]. QuantResultTensorType with its type’s shape field modified to use batch_size.
- afe.ir.attributes.is_dummy_type(t: afe.ir.tensor_type.TensorType) bool [source]
- class afe.ir.attributes.AwesomeCalibAttrs[source]
Calibration attributes :param observer: Observer used during calibration of the node. If the node does not use
calibration data for calculation of quantization parameters, observer will not be created and its value will be None.
- Parameters:
intermediate_observers – Observers used for quantization of intermediate results.
quant – Quantization scale of the output. It is assigned during quantization.
input_quant – Quantization scale of each input. During quantization, it is first assigned the type and quantization scale that were determined at the nodes that compute the inputs. Then, when the node is quantized, it is assigned the types and quantization scales of inputs that the node accepts.
- observer: afe.ir.node_observer.NodeObserver | None = None[source]
- intermediate_observers: Dict[str, afe.ir.node_observer.NodeObserver] | None = None[source]
- input_quant: Dict[afe.ir.defines.InputName, afe.ir.defines.DataValue[QuantResultTensorType]][source]
- precomputed_quant: afe.ir.defines.Quantization | None = None[source]
- class afe.ir.attributes.AwesomeQuantAttrBase[source]
Base class of quantized operator attributes. This class is used for instance checking only.
- class afe.ir.attributes.PlaceholderQuantAttrs[source]
Properties of a quantized placeholder.
- Parameters:
type – Type of the placeholder’s output.
quantization – Quantization of the placeholder, if it was quantized by the Quantize compiler pass.
- quantization: afe.ir.defines.Quantization | None[source]
- class afe.ir.attributes.ConcatQuantAttrs[source]
Contains quantization attributes for concatenate quantization.
- Parameters:
input_scale_corrections – Quantized scale correction for each inputs.
input_zp_corrections – Quantized zero point correction for each inputs.
right_shift – Number of bits in right shift during requantize at inference time.
layer_bits – Number of bits used for quantizing the tensor.
axis – The axis along which the tensors are concatenated.
node_zps – Zero points(s) of the quantized output tensors(s)
input_scales – Quantized scale for eash inputs.
node_scales – Using the max input_scales as the concatenate output scale of the quantized output tensors(s).
- class afe.ir.attributes.MultiplyQuantAttrs[source]
param lhs_input_shape: Lhs input shape param rhs_input_shape: Rhs input shape :param input_int16: If True, the inputs have int16 type. If false, the inputs have int8 type. :param intrinsic_shift: Right-shift to apply before requantization. param requant Requantization parameters param lhs_zero_point: Zero point of the left-hand side input. param rhs_zero_point: Zero point of the right-hand side input. param layer_bits: Number of bits used to quantize output tensor.
- class afe.ir.attributes.LeakyReluQuantAttrs[source]
The slope for quantized_intput < zero_point is (alpha >> right_shift)
- class afe.ir.attributes.AwesomeAttributes[source]
A class that stores attributes necessary for the execution of its associated AwesomeOperation. Subclasses should include all additional attributes in their __init__ functions and call back to the AwesomeAttributes __init__ function to include the default attributes
- class afe.ir.attributes.MultiplyAttrs[source]
Attributes of a multiply operator.
- Parameters:
scalar_type – Type of input and output. Must be a floating-point type.
lhs_input_shape – Shape of first input.
rhs_input_shape – Shape of second input.
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- afe.ir.attributes.convolution_output_shape(conv_attrs: ConvAttrs) tuple[int, Ellipsis] [source]
Get the shape of a convolution’s output tensor based on its attributes.
- class afe.ir.attributes.ConvAttrs[source]
Attributes of a convolution operation.
The attributes describe a convolution with input and output activations in NWC, NHWC, or NDHWC layout and weights in WIGO, HWIGO, or DHWIGO layout.
The dimension order for 1, 2, or 3 spatial dimensions respectively is W, HW, or DHW.
- Parameters:
stride – Stride in each spatial dimension
dilation – Dilation in each spatial dimension
padding – Padding in each spatial dimension. The padding in each dimension is a tuple holding the padding width at the beginning and end of the dimension.
output_padding – Padding of the output tensor in each spatial dimension for transposed convolution. If it is not a transposed convolution, all padding values must be zero. If it is a transposed convolution, the first element of the padding must be zero.
is_transposed – Whether it is a transposed convolution.
weight_shape – Shape of the weight tensor in spatial dimensions ++ IGO layout, for example HWIGO. IGO is an abbreviation for “input channels, groups, output channels”.
input_spatial_shape – Shape of the input tensor in spatial dimensions.
batch_size – Batch size.
input_type – Scalar type of the convolution’s input tensor. This type is ignored for quantized convolutions.
- input_type: afe.ir.tensor_type.ScalarType[source]
- property kernel_size: tuple[int, Ellipsis][source]
Get the shape of the convolution kernel in the spatial dimensions.
- property num_spatial_dimensions: int[source]
Get the number of spatial dimensions for this convolution.
- property input_shape: tuple[int, Ellipsis][source]
Get the shape of the convolution’s input tensor in NWC, NHWC, or NDHWC layout.
- class afe.ir.attributes.PoolAttrs[source]
- Parameters:
ceil_mode – Used to take ceil or floor when computing the output shape
out_layout – Layout of the output. This can be an empty str if layout is the same as data_layout.
layout – Uses the letters NHWC for BatchNumber, Height, Width, Channels
padding – ((pad_top, pad_bot), …) along the dimensions of NHWC according to layout
pool_size – Size of pooling
strides – Strides
dilation – Dilation along the dimensions of NHWC according to data_layout
scalar_type – Data type of the input and output.
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.MaxPoolAttrs[source]
- Parameters:
ceil_mode – Used to take ceil or floor when computing the output shape
out_layout – Layout of the output. This can be an empty str if layout is the same as data_layout.
layout – Uses the letters NHWC for BatchNumber, Height, Width, Channels
padding – ((pad_top, pad_bot), …) along the dimensions of NHWC according to layout
pool_size – Size of pooling
strides – Strides
dilation – Dilation along the dimensions of NHWC according to data_layout
scalar_type – Data type of the input and output.
- class afe.ir.attributes.AvgPoolAttrs[source]
- Parameters:
count_include_pad – If true, include padding to compute the average.
- class afe.ir.attributes.VarianceAttrs[source]
-
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.AdaptiveAvgPool2DAttrs[source]
- Parameters:
output_size – tuple of int. optional Output height and width.
out_layout – Layout of the output. This can be an empty str if layout is the same as data_layout.
layout – Layout of the input.
- class afe.ir.attributes.ReluAttrs[source]
- Parameters:
scalar_type – Type of input and output.
input_shape – Shape of input.
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.AddAttrs[source]
Attributes of an add operator.
- Parameters:
scalar_type – Type of input and output. Must be a floating-point type.
lhs_input_shape – Shape of first input.
rhs_input_shape – Shape of second input.
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.SubtractAttrs[source]
Attributes of a subtract operator.
- Parameters:
scalar_type – Type of input and output. Must be a floating-point type.
lhs_input_shape – Shape of first input.
rhs_input_shape – Shape of second input.
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.BiasAddAttrs[source]
- Parameters:
input_shape – The shape of the input activation tensor
axis – The axis to add the bias
- class afe.ir.attributes.ConstantMultiplyAddAttrs(scalar_type: afe.ir.tensor_type.ScalarType, lhs_input_shape: Tuple[int, Ellipsis], rhs_input_shape: Tuple[int, Ellipsis], in1_const_attrs: ConstantAttrs, in2_const_attrs: ConstantAttrs | None = None)[source]
Attributes representing the computation (a*c + b*d) for scalar constants c and d.
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- in1_const_attrs: ConstantAttrs[source]
- in2_const_attrs: ConstantAttrs | None[source]
- class afe.ir.attributes.MeanAttrs[source]
- Parameters:
axis – Axis or axes along which a mean operation is performed.
exclude – If exclude is true, we use the axes that are NOT in the axis field
keepdims – If set to true the axes reduces are left with a size of 1
- class afe.ir.attributes.MeanQuantAttrs[source]
Contains quantization attributes for mean quantization.
- Parameters:
attrs – MeanAttrs used in mean operator.
node_scales – Scales(s) of the quantized output tensors(s).
node_zps – Zero points(s) of the quantized output tensors(s).
- class afe.ir.attributes.ArgMaxAttrs[source]
- Parameters:
axis – Axis or axes along which a mean operation is performed.
exclude – If exclude is true, we use the axes that are NOT in the axis field
keepdims – If set to true the axes reduces are left with a size of 1
select_last_index – Whether to select the last index or the first index if the max element appears in multiple indices.
shape – Shape of input tensor
result_scalar_type – Type of numbers in result tensor. It must be either ScalarType.int32 or the same as the input tensor’s type.
input_scalar_type – Type of input values. It must be either ScalarType.float32 or ScalarType.int8.
- result_scalar_type: afe.ir.tensor_type.ScalarType[source]
- input_scalar_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.LayerNormAttrs[source]
- Parameters:
axis – The axis to sum over when computing mean.
input_shape – Shape of input tensor.
epsilon – The epsilon value to use to avoid division by zero.
scalar_type – Type of input and output.
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.RMSNormAttrs[source]
- Parameters:
input_shape – Shape of input tensor.
epsilon – The epsilon value to use to avoid division by zero.
scalar_type – Type of input and output.
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.InstanceNormAttrs[source]
Instance Normalization operator attributes.
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.SoftmaxAttrs[source]
- Parameters:
axis – The axis to sum over when computing softmax
input_shape – Shape of input tensor
scalar_type – Type of input and output
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.PadAttrs[source]
- Parameters:
pad_mode – ‘constant’, ‘edge’, ‘reflect’
pad_width – padding along each input dimension N in the format of (before_N, after_N)
- class afe.ir.attributes.LRNAttrs[source]
- Parameters:
alpha – The scaling parameter.
axis – Input data layout channel axis. Default value is 1 for NCHW format
beta – The exponent parameter.
bias – The offset parameter to avoid dividing by 0.
size – The size of the local region to be considered for normalization.
shape – Shape of input tensor
# NOTES FOR TENSORFLOW # TVM defines size as size_tvm = (depth_radius_tf * 2) + 1 # TVM defines alpha as alpha_tvm = alpha_tf * size_tf
- class afe.ir.attributes.ClipAttrs[source]
Attributes for Clip operation. Clip operation is always merged into a composite operator. Same class is used in floating-point and quantized version.
- Parameters:
a_min – min value of clip
a_max – max calue of clip
shape – Shape of input tensor
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.ExtmAttrs[source]
Attributes for extremum op, can be min or max op depending on the max boolean.
- Parameters:
axis – Axis or axes along which a mean operation is performed.
exclude – If exclude is true, we use the axes that are NOT in the axis field
keepdims – If set to true the axes reduces are left with a size of 1
max – If true the operation is max, if false the operation is min.
- class afe.ir.attributes.SumAttrs[source]
- Parameters:
axis – Axis or axes along which a mean operation is performed.
exclude – If exclude is true, we use the axes that are NOT in the axis field
keepdims – If set to true the axes reduces are left with a size of 1
num_element – Number of element to be summed. This attribute is not a default TVM attribute. It will be assigned during any floating point inference and used in quantization.
- class afe.ir.attributes.ProdAttrs[source]
- Parameters:
axis – Axis or axes along which a mean operation is performed.
exclude – If exclude is true, we use the axes that are NOT in the axis field
keepdims – If set to true the axes reduces are left with a size of 1
- class afe.ir.attributes.FullAttrs[source]
- Parameters:
shape – The shape of the target.
dtype – The data type of the target.
- class afe.ir.attributes.TileAttrs[source]
- Parameters:
reps – The number of times repeating the tensor data.
- class afe.ir.attributes.UpsamplingAttrs[source]
- Parameters:
input_shape – Shape of the input tensor.
scale_h – The scale factor for height upsampling.
scale_w – The scale factor for width upsampling.
layout – Layout of the input.
method – Scale method to used [nearest_neighbor, bilinear, bicubic].
align_corners – Whether to keep corners in proper place.
scalar_type – Data type.
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.ImageResize2DAttrs[source]
- Parameters:
size – The out size to which the image will be resized.
roi – The region of interest for cropping the input image. Expected to be of size 4 and format [start_h, start_w, end_h, end_w]. Only used if coordinate transformation_mode is ‘tf_crop_and_resize’.
layout – Layout of the input.
method – Scale method to used [nearest_neighbor, linear, bicubic].
coordinate_transformation_mode – Describes how to transform the coordinate in the resized tensor to the coordinate in the original tensor. Refer to the ONNX Resize operator specification for details. [half_pixel, align_corners, asymmetric]
rounding_method – (string, optional) - Indicates how to find the “nearest” pixel in nearest_neighbor method [round, floor, ceil]
cubic_alpha – (float) – Spline Coefficient for Bicubic Interpolation
cubic_exclude – (int) – Flag to exclude exterior of the image during bicubic interpolation
extrapolation_value – Fill value to use when roi is outside of the image.
out_dtype – Type to return. If left None returns the same type as input.
- class afe.ir.attributes.GridSampleAttrs[source]
Attributes of GridSample operator.
input_shape: Shape of the input tensor. grid_shape: Shape of the grid tensor. method: Interpolation method to use [“nearest”, “bilinear”, “bicubic”]. padding_mode: padding mode [“zeros”, “border”, “reflection”]. align_corners: Whether to align the corners in interpolation. scalar_type: Data type.
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.MaximumAttrs[source]
A class that stores attributes necessary for the execution of its associated AwesomeOperation. Subclasses should include all additional attributes in their __init__ functions and call back to the AwesomeAttributes __init__ function to include the default attributes
- class afe.ir.attributes.MinimumAttrs[source]
A class that stores attributes necessary for the execution of its associated AwesomeOperation. Subclasses should include all additional attributes in their __init__ functions and call back to the AwesomeAttributes __init__ function to include the default attributes
- class afe.ir.attributes.TensorManipulationBaseAttrs[source]
Do nothing. Used for better structuring data structure
- class afe.ir.attributes.TupleAttrs[source]
A class that stores attributes necessary for the execution of its associated AwesomeOperation. Subclasses should include all additional attributes in their __init__ functions and call back to the AwesomeAttributes __init__ function to include the default attributes
- input_types: List[afe.ir.tensor_type.TensorType][source]
- class afe.ir.attributes.TupleGetItemAttrs[source]
- Parameters:
input_types – List of input tensor types
index – The index of the tuple_value we return
- input_types: List[afe.ir.tensor_type.TensorType][source]
- class afe.ir.attributes.SqueezeAttrs[source]
- Parameters:
axis – Set of axes to remove
input_shape – Shape of input tensor
input_type – Data type of input tensor
- input_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.ConcatenateAttrs[source]
- Parameters:
scalar_type – Scalar tyoe of the output.
axis – The axis along which the tensors are concatenated.
input_types – List of input tensor types.
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- input_types: List[afe.ir.tensor_type.TensorType][source]
- class afe.ir.attributes.TransposeAttrs[source]
- Parameters:
axes – The target axes order, reverse order if not specified.
input_shape – Shape of input tensor
input_type – Data type of input tensor
- input_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.DepthToSpaceAttrs[source]
Attributes of DepthToSpace operator
block_size: Bolck size that is shifted from channels to height and width mode: DCR for depth-column-row order re-arrangement, CRD for column-row-depth order input_shape: Shape of input tensor input_type: Data type of input tensor
- input_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.ReshapeAttrs[source]
- Parameters:
input_shape – Shape of input tensor
dtype – Data type
newshape – The new shape.
- class afe.ir.attributes.ExpandDimsAttrs[source]
- Parameters:
axis – The axis that is expanded
num_newaxis – The number of axes to be inserted. Should be >= 0
input_shape – Shape of input tensor
input_type – Data type of input tensor
- input_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.BatchFlattenAttrs[source]
Do nothing. Used for better structuring data structure
- class afe.ir.attributes.SplitAttrs[source]
- Parameters:
indices_or_sections – Indices or sections to split into. Accepts an int or a tuple
If indices_or_sections is an integer, the input will be divided equally along given axis. If such a split is not possible, an error is raised. If indices_or_sections is a tuple of sorted integers, the entries indicate where along axis the array is split. :param axis: The axis over which to split. :param input_shape: Shape of input tensor :param input_type: Data type of input tensor
- input_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.TakeAttrs[source]
- Parameters:
axis – The axis over which to select values. By default, the flattened input array is used.
mode – Specifies how out-of-bound indices will behave [clip, wrap, fast]. clip: clip to the range (default). wrap: wrap around the indices. fast: no clip or wrap around (user must make sure indices are in-bound).
- input_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.StridedSliceAttrs[source]
- Parameters:
begin – The indices to begin with in the slicing.
end – Indices indicating end of the slice.
strides – Specifies the stride values, it can be negative in that case, the input tensor will be reversed in that particular axis.
axes – Tuple[int] or List[int], optional. Axes along which slicing is applied. When it is specified, the length of begin, end, strides, and axes must be equal. Moreover, begin, end, strides, and axes must be static (cannot be relay.Expr). Axes argument for dynamic parameter slicing is not supported yet.
slice_mode –
The slice mode [end, size]. end: The ending indices for the slice [default]. size: The input strides will be ignored, input end in this mode indicates
the size of a slice starting at the location specified by begin. If end[i] is -1, all remaining elements in that dimension are included in the slice.
input_shape – Shape of input tensor
input_type – Data type of input tensor
- input_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.LayoutTransformAttrs[source]
- Parameters:
input_type – Shape and data type of input tensor
src_layout – The source layout. (e.g NCHW)
dst_layout – The destination layout. (e.g. NCHW16c)
implicitly_removable – Whether this transform can be removed from the beginning or end of a model. If the field is True, transform can be removed in order to convert a model’s input and output data layout to NHWC (although the removal is done regardless of the actual data layout). Does not affect other optimizations that change or remove layout_transform operators.
- input_type: afe.ir.tensor_type.TensorType[source]
- class afe.ir.attributes.BroadcastToAttrs[source]
Do nothing. Used for better structuring data structure
- input_type: afe.ir.tensor_type.TensorType[source]
- class afe.ir.attributes.TessellationTransformAttrs[source]
- Parameters:
slice_shape – Shape of slice in tessellation
align_c16 – Flag to force 16-channel alignment in tessellation
cblock – Flag to interleave the 16-channel blocks in tessellation
frame_type – Tensor type before tessellation
- frame_type: afe.ir.tensor_type.TensorType[source]
- class afe.ir.attributes.DetessellationTransformAttrs[source]
- Parameters:
slice_shape – Shape of slice in de-tessellation
align_c16 – Flag to indicate that channels are aligned to 16 in tessellated slice.
cblock – Flag to indicate that tesseallated slice is interleaved by channel blocks.
frame_type – Tensor type after de-tessellation
input_shape – Shape of input tensor
- frame_type: afe.ir.tensor_type.TensorType[source]
- class afe.ir.attributes.PackTransformAttrs[source]
- Parameters:
input_shapes – List of input tensor shape tuples
result_scalar_type – Type of numbers in result tensor, must be ScalarType.int8
- input_shapes: List[afe.ir.tensor_type.TensorType][source]
- result_scalar_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.UnpackTransformAttrs[source]
- Parameters:
input_shape – Shape of input tensor
tensor_types – List of target tensor types to unpack
- tensor_types: List[afe.ir.tensor_type.TensorType][source]
- class afe.ir.attributes.NormalizationTransformAttrs[source]
- Parameters:
channel_params – The list of tuples for (divisor, mean, standard deviation)
input_type – Type and shape of input tensor
- input_type: afe.ir.tensor_type.TensorType[source]
- class afe.ir.attributes.QuantizationTransformAttrs[source]
- Parameters:
channel_params – The list of tuples for (quant_scale, zero_point) Length of the list can be 1 for per tensor quantization or equal to the number of channels of input_shape for per channel quantization.
input_shape – Shape of input tensor, expected to be channel last
num_bits – The number of bits used for quantization
rounding – The rounding type for quantization
output_data_type – If number of bits is 8 data type is int8 otherwise int32.
- output_data_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.DequantizationTransformAttrs[source]
- Parameters:
channel_params – The list of tuples for (quant_scale, zero_point) Length of the list can be 1 for per tensor quantization or equal to the number of channels of input_shape for per channel quantization.
input_type – Type and shape of input tensor, expected to be channel last.
output_type – Type of output tensor.
- input_type: afe.ir.tensor_type.TensorType[source]
- output_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.ResizeTransformAttrs[source]
- Parameters:
target_height – Target height of resized tensor
target_width – Target width of resized tensor
keep_aspect – Boolean flag to keep aspect ratio
deposit_location – Enum to indicate deposit position of resized image
method – Enum to indicate supported interpolation methods
input_type – Input tensor shape and scalar type
- deposit_location: afe.apis.defines.ResizeDepositLocation[source]
- input_type: afe.ir.tensor_type.TensorType[source]
- class afe.ir.attributes.ChromaUpsampleTransformAttrs[source]
- Parameters:
frame_height – Height of full sampling frame
frame_width – Width of full sampling frame
yuv_sampling – Chroma sampling Enum
- yuv_sampling: afe.apis.defines.ChromaSampling[source]
- input_type: afe.ir.tensor_type.TensorType[source]
- class afe.ir.attributes.YuvRgbConversionTransformAttrs[source]
- Parameters:
conversion – Direction of conversion between YUV and RGB
std – Standard for color space conversion
- conversion: afe.apis.defines.ColorConversion[source]
- class afe.ir.attributes.BgrRgbConversionTransformAttrs[source]
- Parameters:
conversion – Direction of conversion between BGR and RGB
- conversion: afe.apis.defines.ColorConversion[source]
- class afe.ir.attributes.SigmoidTransformAttrs[source]
- Parameters:
save_int16 – Boolean flag to save output as 16-bit fixed point
- class afe.ir.attributes.NmsMaxpoolTransformAttrs[source]
- Parameters:
kernel – Size of pooling kernel
- input_type: afe.ir.tensor_type.TensorType[source]
- class afe.ir.attributes.CastAttrs[source]
- Parameters:
out_dtype – The data type of the target.
input_shape – Shape of input tensor.
- input_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.UDFAttrs[source]
- Common attributes for UDF functions:
Sqrt
Rsqrt
Sigmoid
Exp
Tanh
log, log2, log10
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.LeakyReluAttrs[source]
- Parameters:
alpha – The slope for the small gradient when x < 0
- class afe.ir.attributes.SwishAttrs[source]
- Common attributes for UDF functions:
Sqrt
Rsqrt
Sigmoid
Exp
Tanh
log, log2, log10
- class afe.ir.attributes.PReluAttrs[source]
- Parameters:
scalar_type – Type of input and output. Must be a floating-point type.
axis – The axis channel dimension is specified.
alpha – The slope for the small gradient when x < 0 (constant tensor)
input_shape – Shape of input.
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.ClipQuantAttrs[source]
Attributes for Clip operation. Clip operation is always merged into a composite operator. Same class is used in floating-point and quantized version.
- Parameters:
a_min – min value of clip
a_max – max calue of clip
shape – Shape of input tensor
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.ReluQuantAttrs[source]
Base class of quantized operator attributes. This class is used for instance checking only.
- class afe.ir.attributes.AddActivationAttrs[source]
A class that stores attributes necessary for the execution of its associated AwesomeOperation. Subclasses should include all additional attributes in their __init__ functions and call back to the AwesomeAttributes __init__ function to include the default attributes
- class afe.ir.attributes.ConvAddActivationAttrs[source]
Attributes of a fused convolution operator consisting of convolution, optional bias-add, and optional activation function.
- weights_attrs: ConstantAttrs[source]
- bias_attrs: ConstantAttrs | None = None[source]
- add_attrs: AddAttrs | BiasAddAttrs | None = None[source]
- class afe.ir.attributes.TupleConcatenateAttrs[source]
A class that stores attributes necessary for the execution of its associated AwesomeOperation. Subclasses should include all additional attributes in their __init__ functions and call back to the AwesomeAttributes __init__ function to include the default attributes
- tuple_attrs: TupleAttrs[source]
- concat_attrs: ConcatenateAttrs[source]
- class afe.ir.attributes.ExternalAttrs[source]
- Parameters:
external_input_list – Parameter names of the external code. This list must be equal to list(node_type.keys()).
node_type – The external operation’s type.
backend – The build target.
irmod_str – The TVM IRModule of the external code saved in string form. Code representations in other fields are derived from this one. It has batch size 1, regardless of batch_size.
operations – A list of strings that detail the ops that are contained within the IRModule.
_graph_module – Lazily compiled executable representation of the external code. This module is used for executing this node on the compilation host.
batch_size – The batch size that this node handles.
- class afe.ir.attributes.QNNQuantizeAttrs[source]
Further reference: tvm/src/relay/qnn/op/quantize.cc :param out_dtype: Specifies the output data type. :param axis: The channel axis for quantization. :param input_type: Tensor input type.
- input_type: afe.ir.tensor_type.TensorType[source]
- class afe.ir.attributes.QNNDequantizeAttrs[source]
Further reference: tvm/src/relay/qnn/op/dequantize.cc :param axis: The channel axis for quantization.
- input_type: afe.ir.tensor_type.TensorType[source]
- class afe.ir.attributes.RequantizeAttrs[source]
Further reference: tvm/src/relay/qnn/op/requantize.cc :param axis: The channel axis for quantization. This axis only apply to the input :param rounding: Defines the rounding direction when the value is midway
between two representable values.
- Parameters:
compute_dtype – Specifies the data type used during requantize. Supported options: “int64”, “float32”, “float64”
out_dtype – Specifies the output data type.
- input_type: afe.ir.tensor_type.TensorType[source]
- class afe.ir.attributes.CustomOpAttrs[source]
Custom Op AwesomeAttributes :param custom_op_attrs: Union[str, Dic[str, Union[str, bool]]]. Custom op attrs
in either str format or a dictionary
- Parameters:
c_code_in_dtypes – Optional[List[str]]. Input tensors’ dtypes. This attribute will be assigned at the runtime
c_code_in_shapes – Optional[List[Tuple[int, …]]]. Input tensors’ shapes This attribute will be assigned at the runtime
function – Optional[OperatorFunction]. Compiled custom op C function This attribute will be assigned at the runtime
args_list – Optional[Any]. A list of arguments for the custom op C function. This attribute will be assigned at the runtime
- output_types: List[afe.ir.tensor_type.TensorType][source]
- class afe.ir.attributes.AddQuantAttrs[source]
Attributes for quantized AddActivationOp.
param lhs_scale: Scale correction applied to the left-hand side input. param rhs_scale: Scale correction applied to the right-hand side input. :param input_int16: If True, the inputs have int16 type. If false, the inputs have int8 type. :param requant: Requantization to perform on the output. :param relu_zero_point: Zero point of the output for relu activation. Ignored if
relu is not used.
param layer_bits: Number of bits used to quantize output tensor. param activ_attrs: Activation attributes used in Add composite operators.
- class afe.ir.attributes.SubtractQuantAttrs[source]
param attrs: SubtractAttrs class holding SubtractOp parameters :param input_int16: If True, the inputs have int16 type. If False, the inputs have int8 type. param lhs_scale: Scale correction applied to the left-hand side input. param rhs_scale: Scale correction applied to the right-hand side input. param layer_bits: Number of bits used to quantize output tensor.
- attrs: SubtractAttrs[source]
- class afe.ir.attributes.ConvQuantAttrs[source]
Used for all variants of convolution. The attributes describe the following sequence of operators (some are optional). Relu and clip are mutually exclusive.
convolution
bias_add
requantize
relu/clip
Due to limitations of how the backend is implemented, we cannot allow the combination zero_point != 0 and isinstance(activ_attrs, ReluAttrs) and isinstance(requant, ArithFoldedRequantization). The quantizer must conform to this restriction.
- Parameters:
conv_attrs – Attributes of the convolution operator.
weight_quant_data – Quantized weights data.
scale – Scale of the convolution operation.
zero_point – Zero point of the quantized output tensor.
input_zp – Zero point of input to the convolution.
bias_quant_data – Quantized bias data.
weight_bits – Number of bits used to quantize the weights.
bits – Number of bits used for quantization.
per_channel – If true, each output channel of the weights will have an independent scale.
activ_attrs – Activation attributes.
requant – Requantization to do after convolve and add.
input_int16 – Whether the input tensor has int16 type. If true, then the operator will execute using the 15-bit convolution algorithm.
msb_left_shift – Whether the 15-bit convolution algorithm will left-shift the MSB (effectively right-shifting the full product by 1). If false, it will right-shift the LSB (effectively right-shifting the full product by 8). Ignored if input_int16 is False.
- class afe.ir.attributes.UpsamplingQuantAttrs[source]
- Parameters:
input_zp
rounding_type
- upsampling_attrs: UpsamplingAttrs[source]
- class afe.ir.attributes.ImageResize2DQuantAttrs[source]
- Parameters:
input_zp
rounding_type
requant – Requantization to perform on the output.
input_int16 – If True, the inputs have int16 type. If False, the inputs have int8 type.
- image_resize2d_attrs: ImageResize2DAttrs[source]
- class afe.ir.attributes.LRNQuantAttrs[source]
- Parameters:
axis – Input data layout channel axis. Default value is 1 for NCHW format
size – The size of the local region to be considered for normalization.
lut_scale – The scale for quantization of LUT input .
lut_zp_corr – The zp correction for quantization of LUT input .
lut_sh – The shift for quantization of LUT input .
output_scale – The scale for quantization of output.
output_zp_corr – The zp correction for quantization of output.
output_sh – The shift for quantization of output.
# NOTES FOR TENSORFLOW # TVM defines size as size_tvm = (depth_radius_tf * 2) + 1 # TVM defines alpha as alpha_tvm = alpha_tf * size_tf
- class afe.ir.attributes.LayerNormQuantAttrs[source]
- Parameters:
axis – Indicates the dimension along which LayerNorm will be performed.
input_shape – Input shape.
lookup_table_rsqrt – Look-up table f(x) = 1 / sqrt(x + epsilon).
zp_rsqrt – Output zero point of the Rsqrt LUT.
requant_mean – Requantization parameters for input mean (integer inputs only).
requant_lut_input – Requantization parameters for Rsqrt LUT input.
requant_output – Requantization of final output.
- class afe.ir.attributes.InstanceNormQuantAttrs[source]
Quantized Instance Normalization operator attributes.
- attrs: InstanceNormAttrs[source]
- class afe.ir.attributes.RMSNormQuantAttrs[source]
- Parameters:
input_shape – Input shape.
zp_ifm – Input tensor zero point.
lookup_table_rsqrt – Look-up table f(x) = 1 / sqrt(x + epsilon).
zp_rsqrt – Output zero point of the Rsqrt LUT.
requant_lut_input – Requantization parameters for Rsqrt LUT input.
requant_output – Requantization of final output.
lut_input_pre_shift – LUT input requantization pre-shift value.
output_pre_shift – Output requantization pre-shift value.
enable_lut_int16 – If True, quantize LUT to int16 otherwise to int8.
- class afe.ir.attributes.SoftmaxQuantAttrs[source]
- Parameters:
axis – Input data layout channel axis.
input_shape – Input shape.
exp_zp – Exp zero point.
rec_zp – Rec zero point.
requant_lut – Requantization parameters for quantization of reciprocal LUT input.
requant_output – Requantization parameters for output.
lookup_table_exp – LUT for exponential function.
lookup_table_rec – LUT for reciprocal function.
enable_int16 – Whether int8 or int16 quantization is used.
lut_input_pre_shift – LUT input requantization pre-shift value (int16 only).
output_pre_shift – Output requantization pre-shift value (int16 only).
- class afe.ir.attributes.RequantizeQuantAttrs[source]
Base class of quantized operator attributes. This class is used for instance checking only.
- attrs: RequantizeAttrs[source]
- class afe.ir.attributes.ConcatQuantAttrs[source]
Contains quantization attributes for concatenate quantization.
- Parameters:
attrs – ConcatenateAttrs holding ConcatenateOp parameters.
requants – Requantization parameters
layer_bits – Number of bits used for quantizing the tensor.
input_scales – Quantized scale for eash inputs.
node_scales – Using the max input_scales as the concatenate output scale of the quantized output tensors(s).
node_zps – Zero points(s) of the quantized output tensors(s)
- attrs: ConcatenateAttrs[source]
- class afe.ir.attributes.CustomOpQuantAttrs[source]
Contains quantization attributes for custom operation quantization.
- Parameters:
custom_op_attrs – CustomOp attributes.
layer_bits – Number of bits used for quantizing the tensor.
node_zps – Zero points(s) of the quantized output tensors(s)
node_scales – Output scale of the quantized output tensors(s).
input_zps – Quantized zero points correction each input.
input_scales – Quantized scales for each input.
- custom_op_attrs: CustomOpAttrs[source]
- class afe.ir.attributes.PoolQuantAttrs[source]
Contains quantization attributes for pool quantization.
- Parameters:
pool_attrs – Pool attrs class holding MaxPool/AvgPoll operator parameters. Its scalar type does not determine the scalar type for the quantized operator.
pad_value – Padding value.
rounding_type – RoundType.
- class afe.ir.attributes.VarianceQuantAttrs[source]
-
- attrs: VarianceAttrs[source]
- class afe.ir.attributes.UDFQuantAttrs[source]
Base class of quantized operator attributes. This class is used for instance checking only.
- class afe.ir.attributes.DivideAttrs[source]
A class that stores attributes necessary for the execution of its associated AwesomeOperation. Subclasses should include all additional attributes in their __init__ functions and call back to the AwesomeAttributes __init__ function to include the default attributes
- multiply_attrs: MultiplyAttrs[source]
- class afe.ir.attributes.DivideQuantAttrs[source]
Base class of quantized operator attributes. This class is used for instance checking only.
- udf_attrs: UDFQuantAttrs[source]
- multiply_attrs: MultiplyQuantAttrs[source]
- class afe.ir.attributes.LeakyReluCompositeQuantAttrs[source]
Contains quantization attributes for both UDF and breakdown LeakyRelu quantization. :param attrs: LeakyRelu attributes class holding LeakyReluOp parameters. :param leaky_relu_uses_udf: bool. If True, use UDF version in quantization. Otherwise, use breakdown version. :param leaky_relu_quant_attrs: Contains quantization parameters for breakdown version if breakdown version is used. :param udf_quant_attrs: Contains quantization parameters for UDF version if UDF version is used.
- attrs: LeakyReluAttrs[source]
- leaky_relu_quant_attrs: LeakyReluQuantAttrs | None = None[source]
- udf_quant_attrs: UDFQuantAttrs | None = None[source]
- class afe.ir.attributes.PReluQuantAttrs[source]
The slope for quantized_intput < zero_point is (alpha >> right_shift)
- class afe.ir.attributes.PowerAttrs[source]
A class that stores attributes necessary for the execution of its associated AwesomeOperation. Subclasses should include all additional attributes in their __init__ functions and call back to the AwesomeAttributes __init__ function to include the default attributes
- class afe.ir.attributes.ArgMaxQuantAttrs[source]
Base class of quantized operator attributes. This class is used for instance checking only.
- attrs: ArgMaxAttrs[source]
- class afe.ir.attributes.BatchMatmulAttrs[source]
A class that stores attributes necessary for the execution of its associated AwesomeOperation. Subclasses should include all additional attributes in their __init__ functions and call back to the AwesomeAttributes __init__ function to include the default attributes
- scalar_type: afe.ir.tensor_type.ScalarType[source]
- class afe.ir.attributes.BatchMatmulQuantAttrs[source]
Base class of quantized operator attributes. This class is used for instance checking only.
- attrs: BatchMatmulAttrs[source]
- class afe.ir.attributes.SliceConcatAttrs[source]
A class that stores attributes necessary for the execution of its associated AwesomeOperation. Subclasses should include all additional attributes in their __init__ functions and call back to the AwesomeAttributes __init__ function to include the default attributes
- slice_attrs: List[StridedSliceAttrs][source]
- tuple_concat_attrs: TupleConcatenateAttrs[source]
- class afe.ir.attributes.SliceConcatQuantAttrs[source]
Base class of quantized operator attributes. This class is used for instance checking only.
- slice_attrs: List[StridedSliceAttrs][source]
- tuple_concat_attrs: ConcatQuantAttrs[source]
- class afe.ir.attributes.BroadcastToQuantAttrs[source]
Base class of quantized operator attributes. This class is used for instance checking only.
- input_type: afe.ir.tensor_type.TensorType[source]