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

Ouverte
#24,502 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
4/5
Temps estimé
3-5 jours
Accessibilité débutants
48/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
python, pytorch

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

🐛 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.

Langage dominant
Python
Étoiles
5.1k
Forks
1.2k
Merge moyen
1 j 22 h
PR mergées (30 j)
675

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de pytorch/executorch

Toutes les issues de pytorch/executorch

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.