afe.ir.node_observer ==================== .. py:module:: afe.ir.node_observer .. autoapi-nested-parse:: Infrastructure adapting the ModelSDK utilization of PyTorch Observers. Classes ------- .. autoapisummary:: afe.ir.node_observer.NodeObserver Module Contents --------------- .. py:class:: NodeObserver(*, calibration_method: afe.apis.defines.CalibrationMethod = MinMaxMethod(), asymmetry: bool = True, node_reporter: Optional[afe.ir.defines.NodeReporter] = None, do_mean_estimation: bool = False, per_channel_min_max: bool = False, qdq_quantization: Optional[afe.ir.defines.Quantization] = None) A module used for observing the statistics of the node's output data and calculation of quantization parameters. It uses the PyTorch and Onnx observer infrastructures to collect the statistics and calculate quantization parameters. Variable _observer is the instance of the PyTorch, Onnx or special Mean observer. Onnx and Pytorch are used for calibration and calculating scales and zero points, while Mean observer tracks mean statistics. Currently, MinMaxObserver, MovingAverageMinMaxObserver and HistogramMSE are supported with PyTorch. Onnxruntime is used for HistogramEntropy and HistogramPercentile observers. The observer flavor is determined by the calibration_method constructor argument. The symmetric/asymmetric quantization scheme is selected using the asymmetry constructor argument. :param calibration_method: Flavor of observer used in calibration. :param node_reporter: Node reporter for the node being observed. :param do_mean_estimation: Boolean determining whether we do mean estimation. If True, calibration methods are ignored and MeanObserver is used, which will simply calculate the mean. .. py:method:: update(x: numpy.ndarray) Updates the statistic of the node's output data. :param x: np.ndarray. The node's output data. .. py:method:: calculate_quantization(qrange: Optional[Tuple[int, int]] = None) -> afe.ir.defines.DataValue[afe.ir.defines.Quantization] Calculates the output Quantization parameters of the node. It calls the ObserverWrapperBase.calculate_scale_and_zp method. When constructing Quantization instance, scale is modified to follow SiMa quantization scheme (reciprocal value is used). :param qrange: The numeric range to quantize for. If None, the range is determined based on how the observer was initialized. :return: DataValue[Quantization]. Quantization parameters of the node's output wrapped in the DataValue instance. Since currently there is no support for nodes producing multiple outputs, TensorValue is always used. .. py:method:: observer_type() -> Optional[afe.apis.defines.CalibrationMethod] .. py:method:: asymmetry() -> bool .. py:method:: min_max() -> Tuple[float, float] .. py:method:: get_mean()