Get output QuantizationParams from a program. Args: output_nodes (list(Node)): A list of output nodes to get output quantization parameters from. Returns: dictionary mapping the output nodes to the found quantization parameters. If no quantization parameters were fou
(
output_node: Node,
)
| 149 | |
| 150 | |
| 151 | def get_output_quantization_params( |
| 152 | output_node: Node, |
| 153 | ) -> dict[Node, QuantizationParams | None]: |
| 154 | """Get output QuantizationParams from a program. |
| 155 | |
| 156 | Args: |
| 157 | output_nodes (list(Node)): A list of output nodes to get output quantization parameters from. |
| 158 | Returns: |
| 159 | dictionary mapping the output nodes to the found quantization parameters. |
| 160 | If no quantization parameters were found, the entry is None. |
| 161 | Raises: |
| 162 | RuntimeError if no output quantization parameters are found. |
| 163 | |
| 164 | """ |
| 165 | quant_params: dict[Node, QuantizationParams | None] = {} |
| 166 | for node in output_node.args[0]: # type: ignore[union-attr] |
| 167 | if ( |
| 168 | node.target # type: ignore[union-attr] |
| 169 | == torch.ops.quantized_decomposed.dequantize_per_tensor.default |
| 170 | ): |
| 171 | quant_params[node] = QuantizationParams( # type: ignore[index] |
| 172 | node_name=node.args[0].name, # type: ignore[arg-type, union-attr] |
| 173 | scale=node.args[1], # type: ignore[arg-type, union-attr] |
| 174 | zp=node.args[2], # type: ignore[arg-type, union-attr] |
| 175 | qmin=node.args[3], # type: ignore[arg-type, union-attr] |
| 176 | qmax=node.args[4], # type: ignore[arg-type, union-attr] |
| 177 | dtype=node.args[5], # type: ignore[arg-type, union-attr] |
| 178 | ) |
| 179 | else: |
| 180 | quant_params[node] = None # type: ignore[index] |
| 181 | return quant_params |
| 182 | |
| 183 | |
| 184 | def torch_tensor_to_numpy(tensor: torch.Tensor) -> np.ndarray: |