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

Abierto
#25,822 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@AxelNoun ya está trabajando en esto.

Desde el 30/11/2026.

  • #25824 de @AxelNoun — abierto

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
25/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
cpp, python, pytorch

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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

Lenguaje dominante
Python
Estrellas
5.2k
Forks
1.3k
Merge medio
1 d 7 h
PR fusionados (30 d)
644

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de pytorch/executorch

Todos los issues de pytorch/executorch

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.