From 8e29ee165f890631056cc8abbb460e3cfe8a3004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20S=C5=82uszniak?= Date: Mon, 2 Nov 2026 15:10:52 +0100 Subject: [PATCH] Qualcomm AI Engine Direct - Broadcast the constant base of quantized pow LiftConstantScalarOperands lifts the base of pow.Scalar to a one-element constant. Quantized HTP ElementWisePower does not broadcast its first input, so only the first output element is computed and the rest are 0. Expand a constant base to the output shape. --- backends/qualcomm/builders/op_pow.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/backends/qualcomm/builders/op_pow.py b/backends/qualcomm/builders/op_pow.py index 395f732c46f..ca8ed3cb807 100644 --- a/backends/qualcomm/builders/op_pow.py +++ b/backends/qualcomm/builders/op_pow.py @@ -12,6 +12,7 @@ from .node_visitor import NodeVisitor from .node_visitor_manager import register_node_visitor from .qnn_constants import OpElementWisePower, QNN_OP_PACKAGE_NAME_QTI_AISW +from .utils import is_parameter # pow.Tensor_Scalar should fall in this visitor because LiftConstantScalarOperands pass @@ -40,6 +41,13 @@ def define_node( # tensor input input_node = self.get_node(node.args[0]) input_tensor = self.get_tensor(input_node, node) + # pow.Scalar's base is lifted to a one-element constant, and quantized + # HTP ElementWisePower does not broadcast its first input: only the + # first output element is computed. Materialize the base at full shape. + if is_parameter(input_node, self.edge_program) and ( + input_tensor.shape != out_tensor.shape + ): + input_tensor = input_tensor.expand(out_tensor.shape).contiguous() tensor_type = PyQnnManager.Qnn_TensorType_t.QNN_TENSOR_TYPE_NATIVE