Portable floor_divide returns non-whole numbers for floats and wrong values for a zero divisor
Maintainer thường phản hồi trong vòng 1 ngày
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 52/100
Hướng nghiên cứu
Start with kernels/portable/cpu/util/math_util.h and inspect utils::floor_divide; the issue says the same helper is used by portable div and by Cadence HiFi and Fusion G3 div operators. Compare its floating-point behavior with ATen's div_floor_floating, focusing on rounding errors and zero divisors, then add tests for the reported cases. Done means floating-point results match eager behavior for those cases while integer behavior remains unaffected.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
🐛 Describe the bug
For floating-point inputs, the portable floor_divide kernel often returns a value that is not a whole number, and it returns the wrong value when dividing by zero. div.Tensor_mode / div.Scalar_mode with rounding_mode="floor" use the same helper (utils::floor_divide in kernels/portable/cpu/util/math_util.h), so they behave the same way.
- Results that aren't whole numbers. The helper returns
(a - fmod(a, b)) / b, minus 1 if the signs differ. That quotient can be off from a whole number by a rounding error. ATen'sdiv_floor_floatingthen floors it and rounds up if the remainder is above 0.5; the portable helper skips that step. With random inputs (a in [-10, 10], b in [0.01, 2.01]), about 7% of float64 results and 6% of float32 results differ from eager. When the result is converted to an integer, as is common for bucket or index computations, it comes out one too small for positive results (2.9999999999999996 → 2) and one too large for negative ones (-3.9999999999999996 → -3). - Division by zero. For
b == 0the helper returns±infbased on the sign ofa. ATen returnsa / b, so0.0 // 0.0isnaninstead ofinf,nan // 0.0isnaninstead ofinf, and a-0.0divisor flips the sign (1.0 // -0.0is-inf).
import torch
from executorch.exir import to_edge
from executorch.runtime import Runtime
class FloorDiv(torch.nn.Module):
def forward(self, a, b):
return torch.div(a, b, rounding_mode="floor")
def run(a, b):
prog = to_edge(torch.export.export(FloorDiv(), (a, b))).to_executorch()
return Runtime.get().load_program(prog.buffer).load_method("forward").execute([a, b])[0]
a = torch.tensor([4.2, 0.7, -4.2], dtype=torch.float64)
b = torch.tensor([1.4, 0.1, 1.4], dtype=torch.float64)
print(torch.div(a, b, rounding_mode="floor").tolist(), run(a, b).tolist())
# [3.0, 6.0, -4.0] [2.9999999999999996, 6.000000000000001, -3.9999999999999996]
print(torch.div(a, b, rounding_mode="floor").long().tolist(), run(a, b).long().tolist())
# [3, 6, -4] [2, 6, -3]
a = torch.tensor([-6.4278764724731445])
b = torch.tensor([1.870701551437378])
print(torch.floor_divide(a, b).item(), run(a, b).item())
# -4.0 -3.999999761581421
a = torch.tensor([0.0, float("nan"), 1.0])
b = torch.tensor([0.0, 0.0, -0.0])
print(torch.floor_divide(a, b).tolist(), run(a, b).tolist())
# [nan, nan, -inf] [inf, inf, inf]
Integer inputs are not affected. utils::floor_divide is also used by the Cadence HiFi and Fusion G3 div operators. 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).
cc @larryliu0820 @manuelcandales @JakeStevens
- Ngôn ngữ chính
- Python
- Star
- 5.1k
- Fork
- 1.2k
- Merge trung bình
- 2 ngày 8 giờ
- Pull request đã merge (30 ngày)
- 610
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
-
Portable remainder kernel: wrong sign for integers and float64 rounded to floatCó thể đã có người làm @JakeStevens đã nhận hôm nay. Đang mởbug module: kernels triaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
pytorch/executorch#23682 · 2 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
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
-
Feedback about ToolsĐang mởinvalid module: doc
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
pytorch/executorch#23706 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
torch.var_mean and torch.std_mean fail in to_edge: aten.var_mean.correction is not core ATen and has no core decompositionCó thể đã có người làm @usmanmateen đã nhận hôm nay. Đang mởbug module: exir triaged
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 58/100
pytorch/executorch#23680 · 2 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
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_lenCó thể đã có người làm @alpharomercoma đã nhận 2 ngày trước. Đang mởbug module: extension module: llm triaged
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 20/100
pytorch/executorch#23678 ·
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ó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
gradio-app/gradio#13964 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 93/100
BSData/horus-heresy-3rd-edition#3232 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
jbacalso24/mimry#123 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
p:3-mid pydanty:bug pydanty:is-working
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
pydantic/pydantic-ai#10153 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue priority: medium size: S testing
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
cubrid-lab/cubrid-cookbook-python#316 ·
Maintainer thường phản hồi trong vòng 1 ngày