Portable remainder kernel: wrong sign for integers and float64 rounded to float
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 82/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Activo
- Área
- backend, machine-learning
Línea de trabajo
Lee kernels/portable/cpu/util/math_util.h y el op_remainder_test.cpp existente. Comprueba las sobrecargas para enteros y números de punto flotante con los casos de signo y precisión del issue, incluida la forma escalar. El trabajo estará listo cuando las pruebas cubran esos casos y los kernels portables coincidan con los resultados de PyTorch.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
🐛 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).
- Lenguaje dominante
- Python
- Estrellas
- 5.1k
- Forks
- 1.2k
- Merge medio
- 2 d 9 h
- PR fusionados (30 d)
- 632
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de pytorch/executorch
-
enhancement triaged
Dificultad 2/5 Medio día Aptitud para principiantes 68/100
pytorch/executorch#21640 ·
Los mantenedores suelen responder en 1 día
-
Portable floor_divide returns non-whole numbers for floats and wrong values for a zero divisorPosiblemente ocupada @usmanmateen la tomó hace 1 día. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 52/100
pytorch/executorch#23684 ·
Los mantenedores suelen responder en 1 día
-
torch.var_mean and torch.std_mean fail in to_edge: aten.var_mean.correction is not core ATen and has no core decompositionPosiblemente ocupada @usmanmateen la tomó hace 1 día. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 58/100
pytorch/executorch#23680 ·
Los mantenedores suelen responder en 1 día
-
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_lenPosiblemente ocupada @alpharomercoma la tomó hace 2 días. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 20/100
pytorch/executorch#23678 ·
Los mantenedores suelen responder en 1 día
-
[v1.6.0] Release Schedule and TrackerPosiblemente ocupada @JacobSzwejbka la tomó hace 3 días. Abierto
pytorch/executorch#23608 · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de pytorch/executorch
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
-
good first issue No-AI
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
-
🐛 Bug: Calendar work items cannot be opened on mobilePosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 2 días