Skip to content

Qualcomm: bmm over a flattened 4D input returns ~1/W of the right value when followed by unsqueeze (HTP fp16) #24502

Open

Description

@msluszniak

🐛 Describe the bug

On the HTP, bmm over a flattened 4D input returns wrong values when the same input also feeds a conv and the result is unsqueezed back to 4D. Every output element is ~1/W of the right value (W=24 here), as if only one spatial row were summed. Found in ZipDepth's GlobalContextBlock.

import torch, torch.nn.functional as F
from executorch.backends.qualcomm.serialization.qc_schema import QcomChipset
from executorch.backends.qualcomm.utils.utils import (
    generate_htp_compiler_spec, generate_qnn_executorch_compiler_spec, to_edge_transform_and_lower_to_qnn)

class M(torch.nn.Module):
    def __init__(self):
        super().__init__()
        self.conv = torch.nn.Conv2d(192, 1, 1)

    def forward(self, x):
        B, C, H, W = x.shape
        mask = F.softmax(self.conv(x).view(B, 1, H * W), -1)
        return torch.bmm(x.view(B, C, H * W), mask.transpose(1, 2)).unsqueeze(-1)

x = torch.rand(1, 192, 24, 24) * 0.5
cs = generate_qnn_executorch_compiler_spec(
    soc_model=QcomChipset.SM8850, backend_options=generate_htp_compiler_spec(use_fp16=True))
edge = to_edge_transform_and_lower_to_qnn(M().eval(), (x,), cs)

On an S26 Ultra (SM8850, QAIRT 2.47, fp16), main and 1.4.1: output sum 2.05 vs 48.04 on CPU, ratio ~0.043 for every element.

  • Without the unsqueeze, or with mask as a graph input: exact.
  • (x.view(B, C, H * W) * mask).sum(-1, keepdim=True).unsqueeze(-1): exact (our workaround).

Versions

ExecuTorch main (a489dca) and 1.4.1, QAIRT 2.47.0.260601, torch 2.14.

cc @cccclai @winskuo-quic @shewu-quic @haowhsu-quic @DannyYuyang-quic @qti-horodnic @cbilgin @abhinaykukkadapu @psiddh

Activity

  1. winskuo-quic commented on Nov 6, 2026

    @winskuo-quic
    Contributor

    Hi @psiddh,
    Could you help adding the label "module: qnn" so it helps us keep track of the issue?
    Thanks!

  2. added
    module: qnnIssues related to Qualcomm's QNN delegate and code under backends/qualcomm/
    on Nov 6, 2026
  3. added
    partner: qualcommFor backend delegation, kernels, demo, etc. from the 3rd-party partner, Qualcomm
    on Nov 9, 2026
  4. self-assigned this
    on Nov 9, 2026
  5. added theissue type on Nov 9, 2026
  6. jay23606 commented on Nov 13, 2026

    @jay23606

    I'd like to take a look at this. From the repro, the bmm lowering or the view/unsqueeze handling in backends/qualcomm is the likely place for the fix, and I'd check it with a QNN-vs-CPU comparison test on the bmm-plus-unsqueeze pattern. Could you assign it to me?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugmodule: qnnIssues related to Qualcomm's QNN delegate and code under backends/qualcomm/partner: qualcommFor backend delegation, kernels, demo, etc. from the 3rd-party partner, Qualcomm

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions