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時間
- マージ済み PR(30日)
- 632
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
good first issue No-AI
難易度 2/5 1〜3時間 初心者へのやさしさ 69/100
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
🐛 Bug: Calendar work items cannot be opened on mobile対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープン
難易度 1/5 1時間未満 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信