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

Aperta
#24,502 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
48/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
python, pytorch

Direzione di ricerca

Start with the issue's minimal model and run it on CPU and the SM8850 HTP using the shown ExecuTorch lowering utilities; compare outputs with and without the final unsqueeze and with mask supplied as a graph input. Done means the HTP output matches the CPU result for the reported bmm pattern, rather than producing values about 1/W as large.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

🐛 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 (a489dcac3b) and 1.4.1, QAIRT 2.47.0.260601, torch 2.14.

Lingua principale
Python
Stelle
5.2k
Fork
1.2k
Merge medio
1g 22h
PR unite (30g)
675

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pytorch/executorch

Tutte le issue di pytorch/executorch

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.