Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Portable div(rounding_mode="trunc") and fmod round int64 values through double

未关闭
#24,169 0 条评论 0 个 reaction 已指派 2 人 在 GitHub 查看

维护者通常 1 天内回复

@JakeStevens 已经在做这个了。

开始于 2026年10月27日。

  • #24170 来自 @usmanmateen —— 未关闭

评估

这个 Issue 还没有评估数据。

描述

bug module: kernels triaged
🐛 Describe the bug

The portable div with rounding_mode="trunc" and fmod give wrong results for int64 values above 2^53:

import torch
from executorch.exir import to_edge
from executorch.extension.pybindings.portable_lib import _load_for_executorch_from_buffer


class M(torch.nn.Module):
    def forward(self, a, b):
        return torch.div(a, b, rounding_mode="trunc"), torch.fmod(a, b)


a = torch.tensor([(1 << 62) + 3, -((1 << 62) + 3), 9007199254740993])
b = torch.tensor([3, 10, 2])
prog = to_edge(torch.export.export(M(), (a, b))).to_executorch()
print([t.tolist() for t in _load_for_executorch_from_buffer(prog.buffer).forward((a, b))])
print([t.tolist() for t in M()(a, b)])
[[1537228672809129216, -461168601842738816, 4503599627370496], [1, -4, 0]]
[[1537228672809129302, -461168601842738790, 4503599627370496], [1, -7, 1]]

div.out_mode and div.Scalar_mode_out compute the integer quotient with /, then call std::trunc on it, which converts it to double and back. fmod.Tensor_out and fmod.Scalar_out switch every integer compute type to Double and use std::fmod. Integer division already truncates, and % gives the fmod result directly, so neither needs a double.

I'll open a PR that skips std::trunc for integer types and computes integer fmod with %.

Versions

executorch 1.5.1 (kernels/portable/cpu/op_div.cpp and op_fmod.cpp are the same on main at 5b14a2f), torch 2.14.1+cpu, Python 3.12, Linux x86_64 (WSL2).

cc @larryliu0820 @manuelcandales @JakeStevens

主要语言
Python
星标
5.1k
派生
1.2k
平均合并
1 天 23 小时
30 天内合并 PR
698

环境准备

从这里开始

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

pytorch/executorch 的其他 Issue

查看 pytorch/executorch 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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