图片解析应用
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
1.1 KiB

  1. class QuantOperatorBase:
  2. def __init__(self, onnx_quantizer, onnx_node):
  3. self.quantizer = onnx_quantizer
  4. self.node = onnx_node
  5. def should_quantize(self):
  6. if not self.quantizer.should_quantize_node(self.node):
  7. return False
  8. return self.quantizer.is_float_tensor(self.node.input[0])
  9. def quantize(self):
  10. """
  11. Given a node which does not support quantization, this method checks whether the input to
  12. this node is quantized and adds a DequantizeLinear node to dequantize this input back to FP32
  13. parameter node: Current node
  14. parameter new_nodes_list: List of new nodes created before processing current node
  15. return: List of new nodes created
  16. """
  17. for _, node_input in enumerate(self.node.input):
  18. dequantize_node = self.quantizer._dequantize_value(node_input)
  19. if dequantize_node is not None:
  20. self.quantizer.new_nodes.append(dequantize_node)
  21. # Append the original node
  22. self.quantizer.new_nodes.append(self.node)