Float scalars in float64 programs are rounded to float32 by ScalarToTensorPass
Les mainteneurs répondent en général sous 1 jour
Évaluation
Cette issue n'a pas encore été évaluée.
Description
🐛 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
- Langage dominant
- Python
- Étoiles
- 5.1k
- Forks
- 1.2k
- Merge moyen
- 2 j 6 h
- PR mergées (30 j)
- 692
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de pytorch/executorch
-
enhancement triaged
Difficulté 2/5 Une demi-journée Accessibilité débutants 68/100
pytorch/executorch#21640 ·
Les mainteneurs répondent en général sous 1 jour
-
module: cuda
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 10/100
pytorch/executorch#24353 ·
Les mainteneurs répondent en général sous 1 jour
-
More Exynos SoCs supportOuverte
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 10/100
pytorch/executorch#24350 ·
Les mainteneurs répondent en général sous 1 jour
-
`torch.complex` fails Edge export and CPU executionPeut-être pris @JakeStevens l’a pris aujourd’hui. Ouvertebug module: kernels triaged
pytorch/executorch#24328 · 2 personnes assignées ·
Les mainteneurs répondent en général sous 1 jour
-
module: openvino
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 15/100
pytorch/executorch#24325 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de pytorch/executorch
Issues similaires
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
BCDA-APS/polar-bits#93 ·
-
infer_audio_type only recognises one MPEG Layer III frame header, so most MP3 files are rejectedPeut-être pris @Steve-20-ai l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 1 jour
-
[BUG] - ssh_config `Match tagged` statement always appliesPeut-être pris @AtharvRG l’a pris aujourd’hui. OuverteBug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
paramiko/paramiko#2715 · 1 commentaire ·
Les mainteneurs répondent en général sous 9 jours
-
auto-rejected intake mcp-intake needs-salvage priority:high type:feature
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
Ikalus1988/MisakaNet#4221 · 2 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
Les mainteneurs répondent en général sous 1 jour