Skip to content

Commit 89e6619

Browse files
committed
fix duplicate name from same input
Signed-off-by: samcheng <samcheng@nvidia.com>
1 parent 60f9f5d commit 89e6619

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

modelopt/onnx/quantization/graph_utils.py

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,9 +1091,9 @@ def find_nodes_from_matmul_to_exclude(
10911091
) -> list[str]:
10921092
"""Find MatMul nodes that meets gemv or small-gemm condition to exclude.
10931093
1094-
Either of m or n in matmul is 1 (GEMV), or K or N is smaller than
1094+
Either of m or n in matmul is 1, or K or N is smaller than
10951095
_MIN_MATMUL_DIM_INT8 (16), this matmul cannot efficiently utilize
1096-
INT8 TensorCores. The perf of adding Q/DQ layers is not good in
1096+
INT8 kernels. The perf of adding Q/DQ layers is not good in
10971097
TRT. Thus, in this case, do not add Q/DQ layers to this matmul.
10981098
10991099
Args:
@@ -1214,7 +1214,8 @@ def find_nodes_from_convs_to_exclude(graph: Graph, quantize_mode: str = "int8"):
12141214
if quantize_mode == "fp8" and filter_size > 32:
12151215
logger.debug(f"Found large filter conv for FP8: {node.name}")
12161216
unsupported_conv_nodes.append(node.name)
1217-
continue # skip the small-channel check below; already excluded
1217+
# skip the small-channel check below; already excluded
1218+
continue
12181219

12191220
# For FP8, exclude small-channel convolutions. These layers do not benefit from
12201221
# FP8 quantization and cause perf regressions on GPUs where the FP8 conv kernels
@@ -1314,7 +1315,7 @@ def _exclude_matmuls_by_shape_inference(
13141315
elif len(dims) < 3 and any(out.dim_value == 1 for out in dims):
13151316
nodes_to_exclude.append(matmul_node.name)
13161317
continue
1317-
# Small-gemm check: exclude if N or K < 16 (INT8 Tensor Cores need >= 16).
1318+
# Small-gemm check: exclude if N or K < 16 (INT8 kernels need >= 16).
13181319
n_dim = dims[-1].dim_value if len(dims) >= 2 else 0
13191320
k_dim = _get_inp_b_k_dim(matmul_node, value_info_map=value_info_map)
13201321
small_n = 0 < n_dim < _MIN_MATMUL_DIM_INT8
@@ -1341,11 +1342,18 @@ def _exclude_matmuls_by_inference(
13411342
) -> list[str]:
13421343
"""Use actual inference to find MatMuls with dimension 1 or small K/N (INT8)."""
13431344
# Add matmul outputs and second-input outputs to model outputs
1345+
existing_output_names = {out.name for out in model.graph.output}
13441346
for matmul_node in matmul_nodes:
1345-
model.graph.output.extend([onnx.ValueInfoProto(name=matmul_node.outputs[0].name)])
1347+
out_name = matmul_node.outputs[0].name
1348+
if out_name not in existing_output_names:
1349+
model.graph.output.extend([onnx.ValueInfoProto(name=out_name)])
1350+
existing_output_names.add(out_name)
13461351
# Also add second input for K-dimension check (only if it's a Variable, not a Constant)
13471352
if isinstance(matmul_node.inputs[1], Variable):
1348-
model.graph.output.extend([onnx.ValueInfoProto(name=matmul_node.inputs[1].name)])
1353+
inp_b_name = matmul_node.inputs[1].name
1354+
if inp_b_name not in existing_output_names:
1355+
model.graph.output.extend([onnx.ValueInfoProto(name=inp_b_name)])
1356+
existing_output_names.add(inp_b_name)
13491357

13501358
output_map = get_extended_model_outputs(
13511359
onnx_path,
@@ -1371,7 +1379,7 @@ def _exclude_matmuls_by_inference(
13711379
nodes_to_exclude.append(matmul_node.name)
13721380
continue
13731381

1374-
# Small-gemm check: exclude if N or K < 16 (INT8 Tensor Cores need >= 16).
1382+
# Small-gemm check: exclude if N or K < 16 (INT8 kernels need >= 16).
13751383
n_dim = matmul_output.shape[-1] if len(matmul_output.shape) >= 2 else 0
13761384
k_dim = _get_inp_b_k_dim(matmul_node, output_map=output_map)
13771385
small_n = 0 < n_dim < _MIN_MATMUL_DIM_INT8

0 commit comments

Comments
 (0)