(self, operation: Operation)
| 50 | # 我建议你针对这类情况进行回应。或者,在探测到算子类型并非可量化类型后进行报错 |
| 51 | # ------------------------------------------------------------ |
| 52 | def init_quantize_config(self, operation: Operation) -> OperationQuantizationConfig: |
| 53 | # ------------------------------------------------------------ |
| 54 | # 为卷积算子初始化量化信息,只量化卷积算子的输出 |
| 55 | # ------------------------------------------------------------ |
| 56 | if operation.type == 'Conv': |
| 57 | config = self.create_default_quant_config( |
| 58 | op = operation, |
| 59 | num_of_bits = 8, |
| 60 | quant_max = 127, |
| 61 | quant_min = -128, |
| 62 | observer_algorithm = 'percentile', |
| 63 | policy = QuantizationPolicy( |
| 64 | QuantizationProperty.PER_TENSOR + |
| 65 | QuantizationProperty.LINEAR + |
| 66 | QuantizationProperty.SYMMETRICAL), |
| 67 | rounding = RoundingPolicy.ROUND_HALF_EVEN) |
| 68 | |
| 69 | # ------------------------------------------------------------ |
| 70 | # 关闭所有输入量化,状态设置为fp32 |
| 71 | # ------------------------------------------------------------ |
| 72 | for tensor_quant_config in config.input_quantization_config: |
| 73 | tensor_quant_config.state = QuantizationStates.FP32 |
| 74 | |
| 75 | return config |
| 76 | else: |
| 77 | raise TypeError(f'Unsupported Op Type: {operation.type}') |
| 78 | |
| 79 | # ------------------------------------------------------------ |
| 80 | # 当前量化器进行量化的算子都将被发往一个指定的目标平台 |
nothing calls this directly
no test coverage detected