Float scalars in float64 programs are rounded to float32 by ScalarToTensorPass
Los mantenedores suelen responder en 1 día
Evaluación
Este issue todavía no se ha evaluado.
Descripción
🐛 Describe the bug
In a float64 program, ops with a Python float operand lose precision after lowering: the scalar is rounded to float32 before the op runs.
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, x):
return x * 0.1
x = torch.tensor([1.0, 3.0, 123456.789], dtype=torch.float64)
prog = to_edge(torch.export.export(M(), (x,))).to_executorch()
print(_load_for_executorch_from_buffer(prog.buffer).forward((x,))[0].tolist())
print(M()(x).tolist())
[0.10000000149011612, 0.30000000447034836, 12345.679083964951]
[0.1, 0.30000000000000004, 12345.6789]
The same happens for x + 0.1, x - 0.1, x / 0.1, 0.1 - x and torch.deg2rad(x) (which multiplies by π/180): relative errors of about 1e-9 to 1.5e-8, where float64 should be exact to ~1e-16.
ScalarToTensorPass turns the scalar into torch.tensor(value), which is float32 by default. RemoveMixedTypeOperators then casts that constant to float64 with a _to_dim_order_copy, but by then 0.1 is already 0.10000000149011612. Float32 programs are unaffected.
Creating the constant as float64 when the op already has a float64 tensor operand keeps the value exact, and also drops the _to_dim_order_copy from those graphs. Other dtypes keep the current behavior. I'll open a PR with that.
Versions
executorch 1.5.1 (exir/passes/scalar_to_tensor_pass.py is the same on main at 5b14a2f), torch 2.14.1+cpu, Python 3.12, Linux x86_64 (WSL2).
cc @JacobSzwejbka @angelayi
- Lenguaje dominante
- Python
- Estrellas
- 5.1k
- Forks
- 1.2k
- Merge medio
- 1 d 23 h
- PR fusionados (30 d)
- 698
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
-
[Rpi5 setup] Make Raspberry Pi cross-compiled binaries run out of the box on supported OS versionsAbierto
Dificultad 5/5 Más de una semana Aptitud para principiantes 35/100
pytorch/executorch#24228 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
pytorch/executorch#24196 ·
Los mantenedores suelen responder en 1 día
-
Portable div(rounding_mode="trunc") and fmod round int64 values through doublePosiblemente ocupada @JakeStevens la tomó hace 2 días. Abiertobug module: kernels triaged
pytorch/executorch#24169 · 2 asignados ·
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
pytorch/executorch#24125 ·
Los mantenedores suelen responder en 1 día
Todos los issues de pytorch/executorch
Issues similares
-
Skill submission: negative-test-first (testing discipline; PR creation is collaborator-only)Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
ComposioHQ/awesome-claude-skills#2398 ·
Los mantenedores suelen responder en 2 días
-
bug converter
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
grafana/sigma-rule-deployment#435 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
datamodel-code-generator/datamodel-code-generator#5589 ·
Los mantenedores suelen responder en 1 día
-
Shell: serve the home app's Cookie Policy on a hard reloadPosiblemente ocupada @2001anshkaushik la tomó hoy. Abiertofeature module:ai
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
rocketride-org/rocketride-server#2899 · 1 comentario ·
Los mantenedores suelen responder en 2 días
-
GEFSv12
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100