Float scalars in float64 programs are rounded to float32 by ScalarToTensorPass
メンテナーはふだん 1 日以内に返信
評価
この issue はまだ評価されていません。
説明
🐛 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
- 主要言語
- Python
- スター
- 5.1k
- フォーク
- 1.2k
- 平均マージ
- 1日 23時間
- マージ済み PR(30日)
- 698
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
pytorch/executorch のほかの issue
-
enhancement triaged
難易度 2/5 半日 初心者へのやさしさ 68/100
pytorch/executorch#21640 ·
メンテナーはふだん 1 日以内に返信
-
[Rpi5 setup] Make Raspberry Pi cross-compiled binaries run out of the box on supported OS versions対応中かも @digantdesai が今日担当しました。 オープンmodule: microcontrollers rfc
難易度 5/5 1週間以上 初心者へのやさしさ 35/100
pytorch/executorch#24228 · 担当者 2 名 ·
メンテナーはふだん 1 日以内に返信
-
[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 accurate対応中かも @SS-JIA が今日担当しました。 オープンmodule: vulkan rfc
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
pytorch/executorch#24196 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
Portable div(rounding_mode="trunc") and fmod round int64 values through double対応中かも @JakeStevens が 2 日前に担当しました。 オープンbug module: kernels triaged
pytorch/executorch#24169 · 担当者 2 名 ·
メンテナーはふだん 1 日以内に返信
-
[QNN] 16a8w: gathered tensor read wrong by a consumer that only feeds a graph output対応中かも @psiddh が今日担当しました。 オープンbug module: qnn partner: qualcomm
難易度 4/5 3〜5日 初心者へのやさしさ 48/100
pytorch/executorch#24125 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
pytorch/executorch の issue をすべて見る
似ている issue
-
factory
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
Arize-ai/phoenix#17420 · コメント 1 件 · リアクション 1 件 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
FireDynamics/LEDSmokeAnalysis#176 ·
メンテナーはふだん 1 日以内に返信
-
PC
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
dependencies
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
dlt-contrib/dlt-filesystem#51 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信