OperationQuantizationConfig serves as a collection of tensor quantization configuration. See TensorQuantizationConfig for more information.
| 950 | |
| 951 | |
| 952 | class OperationQuantizationConfig(Iterable): |
| 953 | """OperationQuantizationConfig serves as a collection of tensor |
| 954 | quantization configuration. |
| 955 | |
| 956 | See TensorQuantizationConfig for more information. |
| 957 | """ |
| 958 | def __init__( |
| 959 | self, |
| 960 | input_quantization_configs: List[TensorQuantizationConfig] = None, |
| 961 | output_quantization_configs: List[TensorQuantizationConfig] = None, |
| 962 | is_positive_quant_op: bool = True |
| 963 | ): |
| 964 | """Create an operation quantization configuration. |
| 965 | |
| 966 | Args: |
| 967 | input_quantization_configs (List[TensorQuantizationConfig], optional): |
| 968 | a list contains all configuration of all input variables. |
| 969 | |
| 970 | output_quantization_configs (List[TensorQuantizationConfig], optional): |
| 971 | a list contains all configuration of all output variables. |
| 972 | |
| 973 | ATTENTION: whether a variable is gonna to be quantized or not, it must have a quantization configuration. |
| 974 | |
| 975 | is_positive_quant_op (bool, optional): [description]. Defaults to True. |
| 976 | some operations are passively quantized, such as Maxpooling, Padding. |
| 977 | For those operations, set this property as False, PPQ will use this property to optimize your graph. |
| 978 | """ |
| 979 | self.input_quantization_config = self.__check_famliy_config(input_quantization_configs) |
| 980 | self.output_quantization_config = self.__check_famliy_config(output_quantization_configs) |
| 981 | self.is_active_quant_op = is_positive_quant_op |
| 982 | |
| 983 | def export(self) -> str: |
| 984 | raise Exception('Implement this first') |
| 985 | |
| 986 | def __check_famliy_config(self, famliy_configs): |
| 987 | for famliy_config in famliy_configs: |
| 988 | if not isinstance(famliy_config, TensorQuantizationConfig): |
| 989 | raise TypeError( |
| 990 | f'You are trying to set famliy quantization config of {str(self)}, ' \ |
| 991 | f'However your input is invalid, except one TensorQuantizationConfig object, ' \ |
| 992 | f'while a {type(famliy_config)} was given.' |
| 993 | ) |
| 994 | return famliy_configs |
| 995 | |
| 996 | def __str__(self) -> str: |
| 997 | return f'Inputs config: {self.input_quantization_config}, '\ |
| 998 | f'Outputs config {self.output_quantization_config}' |
| 999 | |
| 1000 | def __iter__(self) -> TensorQuantizationConfig: |
| 1001 | return (self.input_quantization_config + self.output_quantization_config).__iter__() |
| 1002 | |
| 1003 | def copy(self): |
| 1004 | """Create an operation config from this one, keep policy and state |
| 1005 | unchanged. |
| 1006 | |
| 1007 | if this one has an non-empty scale or offset, they will be cloned too. |
| 1008 | """ |
| 1009 | return OperationQuantizationConfig( |
no outgoing calls
no test coverage detected