You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -43,24 +43,61 @@ In order to conduct PTQ for floating point precision graph, observers are requir
43
43
Qualcomm backend will consume the generated encodings and lower operators with fixed precision. This tutorial will guide you through the details of inserting observer and some useful utilities.
44
44
45
45
### Register Annotation via Operator Type
46
-
Let's start with hooking callback for designated operator target:
46
+
Let's start with hooking callback for designated operator target in `annotators/{backend}_rules.py`:
The `register_annotator` decorator provides a convenient way to attach your own annotation logic, which requires list of operator type as its input argument.<br/> For example, the torch activation functions have `copy`, `in-place` implementation with small difference appears in naming (an extra `_` postfix), which will map to the same [Core ATen](https://pytorch.org/docs/stable/torch.compiler_ir.html) operators after `to_edge`:
64
+
The `register_annotator` decorator provides a convenient way to attach your own annotation and validation logic, which requires list of operator type as its input argument and a QNN operation name<br/> For example, the torch activation functions have `copy`, `in-place` implementation with small difference appears in naming (an extra `_` postfix), which will map to the same [Core ATen](https://pytorch.org/docs/stable/torch.compiler_ir.html) operators after `to_edge`:
Where `torch.ops.aten.relu.default` / `torch.ops.aten.relu_.default` map to `copy` / `in-place` version and both will be converted into `torch.ops.aten.relu.default` ultimately.<br/>
72
+
The `qnn_op` is used to specify quantization constraints for validation with the `BackendOpInfo` library. If an operator doesn’t directly correspond to a QNN operator, you can set its value to `None`, which will skip validation for that operator.
The `operator.getitem` function acts as a skip operator in the QNN backend and does not correspond to any QNN operator. Therefore, we assign `qnn_op=None`.<br/><br>
77
+
78
+
Create a base class `GeneralOpDef` that establishes the standard annotation and validation function behaviors.
Where `torch.ops.aten.relu.default` / `torch.ops.aten.relu_.default` map to `copy` / `in-place` version and both will be converted into `torch.ops.aten.relu.default` ultimately.<br/><br>
60
96
61
-
The function signature is defined as follow with two arguments:
97
+
The `annotate`function signature is defined as follow with two arguments:
We first check if current graph node has been annotated. If not, an `input_qspec_map` dictionary required by PyTorch framework will be declared for providing mapping between graph nodes and their configurations.<br/>
146
194
The parameters' order could be found [here](https://github.com/pytorch/pytorch/blob/main/aten/src/ATen/native/Convolution.cpp) mentioned in [ATen Operator Definitions](#pytorch). Since bias node is optional, the implementation will invoke `_derived_bias_quant_spec` to calculate the per-channel bias encoding only if it exists.
147
195
148
196
- Update node's meta with framework compatible data structure
After done processing `input_qspec_map`, it's required to have it in node's meta with special tag (`Q_ANNOTATION_KEY`) for`convert_pt2e` to properly insert observers.
- Validate against the backend constraints by doing the following:
260
+
- Make sure that `SharedQuantizationSpec`is applied for`is_math_invariant` operator, such as view operations.
261
+
- Check the `scale`and`zero_point` values for specific operations. For example, sigmoid op requires `scale = 1/ (q_max - q_min +1)`and`zero_point = 0`.
262
+
- Ensure that the `qscheme` satisfies symmetric constraints.
263
+
- Verify that the inputand output `dtype` are supported.
158
264
### Common Annotators
159
265
For operators without extra parameters to be observed, there are pre-defined annotation method for convenience:
This annotator only works for single-in-single-out scenario with node's input that has already been annotated. If not, we still need to invoke `annotate_single_in_single_out` again (this path should be less likely).
306
+
This annotator only works for single-in-single-out scenario with node's input that has already been annotated. If not, we still need to invoke `annotate_single_in_share_out` again (this path should be less likely).
184
307
185
308
## Issues
186
309
Please refer to the [issue section](../README.md#issues) for more information.
0 commit comments