Portable remainder kernel: wrong sign for integers and float64 rounded to float
维护者通常 1 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 82/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
调研方向
阅读 kernels/portable/cpu/util/math_util.h 和现有的 op_remainder_test.cpp。根据 issue 中的符号和精度情况检查整数和浮点数重载,包括标量形式。测试覆盖这些情况且 portable kernels 与 PyTorch 的结果一致时,即为完成。
由索引模型根据 Issue 内容生成。
描述
🐛 Describe the bug
The portable remainder kernels give results that differ from PyTorch in two cases.
- Integers with mixed signs. ATen's
remaindertakes the sign of the divisor (-7 % 3 == 2), but for integer typesutils::remainder_overrideinkernels/portable/cpu/util/math_util.hreturnsa % b, which takes the sign of the dividend (-1). The floating-point overload already addsbin this case, as the comment above both overloads describes. The integer one doesn't. - float64 loses precision. The floating-point overload stores
std::fmod(a, b)in afloat, sodoubleresults are rounded to float precision.
import torch
from executorch.exir import to_edge
from executorch.runtime import Runtime
class Rem(torch.nn.Module):
def forward(self, a, b):
return torch.remainder(a, b)
def run(a, b):
prog = to_edge(torch.export.export(Rem(), (a, b))).to_executorch()
return Runtime.get().load_program(prog.buffer).load_method("forward").execute([a, b])[0]
a = torch.tensor([7, -7, 7, -7])
b = torch.tensor([3, 3, -3, -3])
print(torch.remainder(a, b).tolist(), run(a, b).tolist())
# [1, 2, -2, -1] [1, -1, 1, -1]
a = torch.tensor([123456789.123456789], dtype=torch.float64)
b = torch.tensor([1000.0], dtype=torch.float64)
print(torch.remainder(a, b).item(), run(a, b).item())
# 789.1234567910433 789.1234741210938
The integer case affects int8, int32 and int64, and remainder.Scalar too: torch.remainder(x, 3) gives -1 for x = -1 instead of 2. With the XNNPACK partitioner the result is the same, since these ops run on the portable kernel. A model that uses Python's % on integer tensors (for example to wrap positions or bucket ids) gets different values after export.
The existing op_remainder_test.cpp only covers 46 % 4. I have a fix with tests and will open a PR.
Versions
executorch 1.5.1 (math_util.h is the same on main at f2575be), torch 2.14.1+cpu, Python 3.12, Linux x86_64 (WSL2).
- 主要语言
- Python
- 星标
- 5.1k
- 派生
- 1.2k
- 平均合并
- 2 天 9 小时
- 30 天内合并 PR
- 632
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pytorch/executorch 的其他 Issue
-
enhancement triaged
难度 2/5 半天 新手友好度 68/100
pytorch/executorch#21640 ·
维护者通常 1 天内回复
-
Portable floor_divide returns non-whole numbers for floats and wrong values for a zero divisor可能已有人在做 @usmanmateen 于 1 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 52/100
pytorch/executorch#23684 ·
维护者通常 1 天内回复
-
torch.var_mean and torch.std_mean fail in to_edge: aten.var_mean.correction is not core ATen and has no core decomposition可能已有人在做 @usmanmateen 于 1 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 58/100
pytorch/executorch#23680 ·
维护者通常 1 天内回复
-
Prompts of max_seq_len tokens fail to prefill: export_llm bounds the KV-cache token input at max_seq_len - 1 but publishes get_max_seq_len = max_seq_len可能已有人在做 @alpharomercoma 于 2 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 20/100
pytorch/executorch#23678 ·
维护者通常 1 天内回复
-
[v1.6.0] Release Schedule and Tracker可能已有人在做 @JacobSzwejbka 于 3 天前认领。 未关闭
pytorch/executorch#23608 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 pytorch/executorch 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 75/100
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 2 天内回复
-
Status: Triage Type: Bug
难度 2/5 1-3 小时 新手友好度 86/100
-
Objects.List treats versions=false (and similar flags) as true可能已有人在做 @andaaron 今天认领。 未关闭priority: p2 type: bug
难度 2/5 1-3 小时 新手友好度 78/100
googleapis/storage-testbench#829 ·
维护者通常 2 天内回复
-
[Bug]: memory provider treats 1:1 DMs as shared surfaces, so DM turns never receive reviewed records未关闭
难度 2/5 1-3 小时 新手友好度 79/100
rlaope/oh-my-hermes#2088 ·
维护者通常 1 天内回复