Portable remainder kernel: wrong sign for integers and float64 rounded to float
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 82/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- backend, machine-learning
Direzione di ricerca
Leggi kernels/portable/cpu/util/math_util.h e il file op_remainder_test.cpp esistente. Verifica gli overload per interi e numeri in virgola mobile rispetto ai casi di segno e precisione indicati nell’issue, inclusa la forma scalare. Il lavoro è completato quando i test coprono questi casi e i kernel portabili corrispondono ai risultati di PyTorch.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
🐛 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).
cc @larryliu0820 @manuelcandales @JakeStevens
- Lingua principale
- Python
- Stelle
- 5.1k
- Fork
- 1.2k
- Merge medio
- 2g 10h
- PR unite (30g)
- 632
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pytorch/executorch
-
enhancement triaged
Difficoltà 2/5 Mezza giornata Idoneità per principianti 68/100
pytorch/executorch#21640 ·
I maintainer di solito rispondono entro 1 giorno
-
macOS Python wheel _portable_lib has non-relocatable libtorch rpathForse già presa @shoumikhin l’ha presa oggi. Aperta
pytorch/executorch#23742 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
Feedback about ToolsApertainvalid module: doc
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
pytorch/executorch#23706 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Portable floor_divide returns non-whole numbers for floats and wrong values for a zero divisorForse già presa @JakeStevens l’ha presa 1 giorno fa. Apertabug module: kernels
Difficoltà 3/5 1-2 giorni Idoneità per principianti 52/100
pytorch/executorch#23684 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
torch.var_mean and torch.std_mean fail in to_edge: aten.var_mean.correction is not core ATen and has no core decompositionForse già presa @usmanmateen l’ha presa 1 giorno fa. Apertabug module: exir triaged
Difficoltà 3/5 1-2 giorni Idoneità per principianti 58/100
pytorch/executorch#23680 · 2 assegnatari ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di pytorch/executorch
Issue simili
-
[Bug]: Streamed /v1/chat/completions sends unredacted agent error text (keys) in the final chunkForse già presa @rodricksz4h5 l’ha presa oggi. Apertaarea/streaming comp/gateway P2 type/security
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
NousResearch/hermes-agent#138245 ·
I maintainer di solito rispondono entro 1 giorno
-
[oblt-aw][autodoc] Update user onboarding guide for mandatory trigger CODEOWNERS stepForse già presa @github-actions l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
I maintainer di solito rispondono entro 1 giorno
-
correction metadata
Difficoltà 2/5 Meno di un'ora Idoneità per principianti 68/100
acl-org/acl-anthology#10378 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
cloudtrail_multi_region_enabled_logging_management_events fails when the advanced event selector has a custom nameForse già presa @12YYCCYY16 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
prowler-cloud/prowler#13033 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 1/5 1-3 ore Idoneità per principianti 88/100
graygarbage/HermesKey#23 ·