Quantized quantize/dequantize kernels abort the process on a bfloat16 input or output

Ouverte
#25,822 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

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

@AxelNoun y travaille déjà.

Depuis le 30/11/2026.

  • #25824 par @AxelNoun — ouverte

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
25/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
À l'abandon
Stack technique
cpp, python, pytorch

Piste de recherche

Start with kernels/quantized/cpu/op_quantize.cpp and op_dequantize.cpp, especially the four dispatches named in the issue. Compare their dtype handling for Half with the failing BFloat16 cases, then inspect the C++ tests for these quantized operators. Done means all five reproduced operations return successfully for bfloat16 and match eager PyTorch; a linked pull request is already open.

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

Description

🐛 Describe the bug

The quantized_decomposed kernels in kernels/quantized/cpu handle Half but not BFloat16. quantize_per_tensor_out and quantize_per_channel_out dispatch their input over ET_FORALL_FLOATH_TYPES, and dequantize_per_tensor_out and dequantize_per_channel_out dispatch their output over ET_FORALL_FLOATH_TYPES_WITH. A bfloat16 input or out_dtype falls through to ET_CHECK_MSG(false, "Unhandled ... dtype"), so the process aborts instead of execute() returning an error. Eager PyTorch runs the same program. I found this while comparing the runtime's outputs with eager on small exported programs.

import torch
import executorch.kernels.quantized  # registers the out variants
from executorch.exir import to_edge
from executorch.runtime import Runtime

class M(torch.nn.Module):
    def forward(self, t):
        return torch.ops.quantized_decomposed.dequantize_per_tensor(
            t, 0.25, -3, -128, 127, torch.int8, out_dtype=torch.bfloat16
        )

x = torch.tensor([-128, 0, 5, 127], dtype=torch.int8)
prog = to_edge(torch.export.export(M(), (x,))).to_executorch()
Runtime.get().load_program(prog.buffer).load_method("forward").execute([x])
[op_dequantize.cpp:321] In function dequantize_per_tensor_out(), assert failed (false): Unhandled output dtype 15

The process is then killed by SIGABRT. The same happens for quantize_per_tensor with a bfloat16 input (op_quantize.cpp:346, Unhandled input dtype 15), quantize_per_channel with a bfloat16 input (op_quantize.cpp:630), and dequantize_per_channel and dequantize_per_token with a bfloat16 output (op_dequantize.cpp:517). The Half versions of all five calls run and match eager.

I would expect bfloat16 to be handled like Half. I have a small fix that adds BFloat16 to these four dispatches, with C++ tests, and will open a PR linked to this issue.

Versions

ExecuTorch built from main at 0e7e80e (Python bindings and quantized_ops_aot_lib built from source), PyTorch 2.15.0+cpu, Python 3.12.3, Ubuntu 24.04 on WSL2, x86_64.

This issue was written with the help of Claude Code (Anthropic); I verified the reproduction.

Langage dominant
Python
Étoiles
5.2k
Forks
1.3k
Merge moyen
1 j 7 h
PR mergées (30 j)
644

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.