Skip to content
9 changes: 7 additions & 2 deletions backends/qualcomm/_passes/insert_io_qdq.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,16 @@ class InsertIOQDQ(ExportPass):
"""

q_dq_map = {
# per tensor
# per tensor (quantize -> dequantize)
exir_ops.edge.quantized_decomposed.quantize_per_tensor.default: exir_ops.edge.quantized_decomposed.dequantize_per_tensor.tensor,
exir_ops.edge.quantized_decomposed.quantize_per_tensor.tensor: exir_ops.edge.quantized_decomposed.dequantize_per_tensor.tensor,
# per channel
# per tensor (dequantize -> dequantize, for nodes with dequantize encoding)
exir_ops.edge.quantized_decomposed.dequantize_per_tensor.default: exir_ops.edge.quantized_decomposed.dequantize_per_tensor.default,
exir_ops.edge.quantized_decomposed.dequantize_per_tensor.tensor: exir_ops.edge.quantized_decomposed.dequantize_per_tensor.tensor,
# per channel (quantize -> dequantize)
exir_ops.edge.quantized_decomposed.quantize_per_channel.default: exir_ops.edge.quantized_decomposed.dequantize_per_channel.default,
# per channel (dequantize -> dequantize, for nodes with dequantize encoding)
exir_ops.edge.quantized_decomposed.dequantize_per_channel.default: exir_ops.edge.quantized_decomposed.dequantize_per_channel.default,
Comment on lines 33 to +43
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding dequantize ops as keys in q_dq_map changes _create_node() behavior: it checks if target in self.q_dq_map to decide when to pop QCOM_QUANT_ATTRS and cast meta['val'] to the quantized dtype. After this change, inserted dequantize nodes (e.g. dequantize_per_tensor.tensor / dequantize_per_channel.default) will now satisfy that condition, causing their meta['val'] dtype to be incorrectly cast to the quantized dtype and moving QCOM_QUANT_ATTRS off the original node. The special-case should apply only to quantize ops; consider switching the check to if target in q_ops (or an explicit quantize-op set) so output dequant nodes keep float meta['val'] and don’t steal the original node’s quant metadata.

Copilot uses AI. Check for mistakes.
Comment on lines +37 to +43
Copy link

Copilot AI Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change fixes a previously crashing edge case (nodes whose QCOM_ENCODING is already a dequantize op), but there doesn’t appear to be any unit coverage for InsertIOQDQ in backends/qualcomm/tests/. Adding a small FX graph test that sets QCOM_QUANT_ATTRS[QCOM_ENCODING] to dequantize_per_tensor.default and asserts the pass inserts the expected output dequant node (and doesn’t alter output meta['val'] dtype) would help prevent regressions.

Copilot uses AI. Check for mistakes.
}

def __init__(self, edge_program: torch.export.ExportedProgram):
Expand Down
Loading