Float scalars in float64 programs are rounded to float32 by ScalarToTensorPass
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
Issue này chưa được đánh giá.
Mô tả
🐛 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
- Ngôn ngữ chính
- Python
- Star
- 5.1k
- Fork
- 1.2k
- Merge trung bình
- 1 ngày 21 giờ
- Pull request đã merge (30 ngày)
- 695
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của pytorch/executorch
-
enhancement triaged
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 68/100
pytorch/executorch#21640 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Rpi5 setup] Make Raspberry Pi cross-compiled binaries run out of the box on supported OS versionsCó thể đã có người làm @digantdesai đã nhận hôm nay. Đang mởmodule: microcontrollers rfc
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
pytorch/executorch#24228 · 2 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[ET-VK] fp16 linear on an RDNA3.5 iGPU: default (texture) export runs at ~1.1 TFLOP/s, coopmat unreachable without buffer storage, and the stock buffer path is ~20x less accurateCó thể đã có người làm @SS-JIA đã nhận hôm nay. Đang mởmodule: vulkan rfc
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 42/100
pytorch/executorch#24196 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Portable div(rounding_mode="trunc") and fmod round int64 values through doubleCó thể đã có người làm @JakeStevens đã nhận 2 ngày trước. Đang mởbug module: kernels triaged
pytorch/executorch#24169 · 2 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[QNN] 16a8w: gathered tensor read wrong by a consumer that only feeds a graph outputCó thể đã có người làm @psiddh đã nhận hôm nay. Đang mởbug module: qnn partner: qualcomm
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 48/100
pytorch/executorch#24125 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của pytorch/executorch
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
aws-samples/sample-per-model-bedrock#639 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
awslabs/visual-asset-management-system#937 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
project-codeflare/codeflare-sdk#1195 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Bump numpy dependencyĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
pandas-dev/pandas-stubs#2051 ·
Maintainer thường phản hồi trong vòng 1 ngày