Get input QuantizationParams in a program, maximum one per input to the program. Args: program (ExportedProgram): The program to get input quantization parameters from. Returns: list[QuantizationParams]: The found quantization parameters.
(
program: ExportedProgram,
)
| 110 | |
| 111 | |
| 112 | def get_input_quantization_params( |
| 113 | program: ExportedProgram, |
| 114 | ) -> list[QuantizationParams]: |
| 115 | """Get input QuantizationParams in a program, maximum one per input to the |
| 116 | program. |
| 117 | |
| 118 | Args: |
| 119 | program (ExportedProgram): The program to get input quantization parameters from. |
| 120 | Returns: |
| 121 | list[QuantizationParams]: The found quantization parameters. |
| 122 | |
| 123 | """ |
| 124 | |
| 125 | quant_params = [] |
| 126 | input_names = get_input_names(program) |
| 127 | num_inputs = len(input_names) |
| 128 | for node in program.graph.nodes: |
| 129 | if ( |
| 130 | node.target == torch.ops.quantized_decomposed.quantize_per_tensor.default |
| 131 | and node.args[0].name in input_names |
| 132 | ): |
| 133 | qp = QuantizationParams( |
| 134 | node_name=node.args[0].name, |
| 135 | scale=node.args[1], |
| 136 | zp=node.args[2], |
| 137 | qmin=node.args[3], |
| 138 | qmax=node.args[4], |
| 139 | dtype=node.args[5], |
| 140 | ) |
| 141 | quant_params.append(qp) |
| 142 | if ( |
| 143 | len(quant_params) == num_inputs |
| 144 | ): # break early if we have all the inputs quantized parameters |
| 145 | break |
| 146 | if len(quant_params) == 0: |
| 147 | logger.warning("No input quantization parameters found in exported model.") |
| 148 | return quant_params |
| 149 | |
| 150 | |
| 151 | def get_output_quantization_params( |
no test coverage detected