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

未关闭
#25,822 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@AxelNoun 已经在做这个了。

开始于 2026年11月30日。

  • #25824 来自 @AxelNoun —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
25/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
cpp, python, pytorch

调研方向

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.

由索引模型根据 Issue 内容生成。

描述

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

主要语言
Python
星标
5.2k
派生
1.3k
平均合并
1 天 7 小时
30 天内合并 PR
644

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

pytorch/executorch 的其他 Issue

查看 pytorch/executorch 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。