@@ -413,18 +413,18 @@ def try_get_arg(node: Node, idx: int) -> Argument | None:
413413 return node .args [idx ] if idx < len (node .args ) else None
414414
415415
416- def input_quantization_type (
416+ def input_quantization_parameters (
417417 node : Node , input_index : int | tuple [int , int ]
418- ) -> torch .dtype | None :
419- """Return the quantization input datatype of the QDQ quantized `node`.
418+ ) -> tuple [ Scale , ZeroPoint , torch .dtype ] | None :
419+ """Return the input quantization parameters of the QDQ quantized `node`.
420420
421421 :param node: The compute node.
422422 :param input_index: The index into the `node.args`. If a tuple of 2 ints is provided,
423423 `args[input_index[0]][input_index[1]]` is used instead.
424- :return: The input quantization datatype of the QDQ quantized `node`, or `None` if the graph does not follow the
424+ :return: The input quantization parameters of the QDQ quantized `node`, or `None` if the graph does not follow the
425425 QDQ pattern or some metadata is incomplete or an invalid input index is given.
426426
427- │ <returned type >
427+ │ <returned parameters >
428428 ┌─────▼──────┐
429429 │ Dequantize │
430430 └─────┬──────┘
@@ -455,17 +455,24 @@ def input_quantization_type(
455455 if (dequantize_input_val := dequantize_node .args [0 ].meta .get ("val" )) is None :
456456 return None # Invalid metadata.
457457
458- return dequantize_input_val .dtype
458+ params = get_quantization_parameters_for (dequantize_node )
459+ dtype = dequantize_input_val .dtype
460+ if params is None or dtype is None :
461+ return None
462+
463+ return * params , dtype
459464
460465
461- def output_quantization_type (node : Node , output_index : int ) -> torch .dtype | None :
462- """Return the quantization output datatype of the QDQ quantized `node`.
466+ def output_quantization_parameters (
467+ node : Node , output_index : int
468+ ) -> tuple [Scale , ZeroPoint , torch .dtype ] | None :
469+ """Return the output quantization parameters of the QDQ quantized `node`.
463470
464471 :param node: The compute node.
465472 :param output_index: If the `node` has multiple outputs and therefore multiple `getitem` nodes follow it, the
466473 index selects the output. If no `getitem` nodes follow it, the operator
467474 produces only 1 output (most common case), and the value `0` must be used.
468- :return: The output quantization datatype of the QDQ quantized `node`, or `None` if the graph does not follow the
475+ :return: The output quantization parameters of the QDQ quantized `node`, or `None` if the graph does not follow the
469476 QDQ pattern or some metadata is incomplete or an invalid input index is given.
470477
471478 ┌───▼────┐
@@ -477,10 +484,10 @@ def output_quantization_type(node: Node, output_index: int) -> torch.dtype | Non
477484 ┌────▼─────┐ or │ getitem(output_index) │ ...
478485 │ Quantize │ └─────────┬─────────────┘
479486 └────┬─────┘ │ float
480- │ <returned type> ┌────▼─────┐
487+ │ <returned parameters> ┌────▼─────┐
481488 │ Quantize │
482489 └────┬─────┘
483- │ <returned type >
490+ │ <returned parameters >
484491 """
485492 users = list (node .users )
486493 if len (users ) == 1 and _is_quantize (quantize_node := users [0 ]):
@@ -512,4 +519,9 @@ def output_quantization_type(node: Node, output_index: int) -> torch.dtype | Non
512519 if (quantize_val := quantize_node .meta .get ("val" )) is None :
513520 return None # Invalid metadata.
514521
515- return quantize_val .dtype
522+ params = get_quantization_parameters_for (quantize_node )
523+ dtype = quantize_val .dtype
524+ if params is None or dtype is None :
525+ return None
526+
527+ return * params , dtype
0 commit comments