Skip to content

Commit ef10a57

Browse files
committed
Fix: issue removing Q/DQ nodes around custom ops with constant inputs
1 parent 1cf78b2 commit ef10a57

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

modelopt/onnx/quantization/qdq_utils.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -790,8 +790,8 @@ def remove_input_dq_and_output_q(
790790
if cons_idx in quantizable_custom_ops[consumer.op_type]["inp"]:
791791
consumer.input[cons_idx] = q_node.output[0]
792792
else:
793-
q_node_prev = tensor_producers[q_node.input[0]]
794-
consumer.input[cons_idx] = q_node_prev.output[0]
793+
q_node_prev = tensor_producers.get(q_node.input[0], None)
794+
consumer.input[cons_idx] = q_node_prev.output[0] if q_node_prev else q_node.input[0]
795795
break
796796

797797
# Track DequantizeLinear node indices for cleanup
@@ -828,8 +828,11 @@ def remove_input_dq_and_output_q(
828828
if quantizable_custom_ops[producer.op_type]["out"]:
829829
dq_node[0].input[0] = producer.output[0]
830830
else:
831-
dq_node_next = tensor_consumers[dq_node[0].output[0]]
832-
dq_node_next[0].input[0] = producer.output[0]
831+
dq_node_next = tensor_consumers.get(dq_node[0].output[0], None)
832+
if dq_node_next:
833+
dq_node_next[0].input[0] = producer.output[0]
834+
else:
835+
dq_node[0].input[0] = producer.output[0]
833836

834837
# Track QuantizeLinear node indices for cleanup
835838
q_indices.append(node_idx)

0 commit comments

Comments
 (0)