[Bug][torchlib] aten_scatter_reduce(include_self=False) uses finite finfo.min/max instead of -inf/+inf, corrupting +/-inf inputs
Maintainer thường phản hồi trong vòng 2 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 72/100
Hướng nghiên cứu
Đọc aten_scatter_reduce trong onnxscript/function_libs/torch_lib/ops/core.py quanh các dòng 9169–9198, sau đó kiểm tra các bài kiểm thử hiện có cho scatter reduce. Tái hiện lỗi với include_self=False và các giá trị nguồn vô cực cho amax và amin trên các kiểu dữ liệu dấu phẩy động được liệt kê. Hoàn tất khi kết quả ONNX đã xuất giữ nguyên các giá trị vô cực mong đợi và hành vi với số nguyên vẫn chính xác.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Describe the bug
When include_self=False and reduce="amax" or reduce="amin", aten_scatter_reduce in onnxscript/function_libs/torch_lib/ops/core.py (lines 9169–9198) pre-fills impacted target indices before calling op.ScatterElements(..., reduction="max" | "min").
Although the comment on line 9169 notes # fill a dummy value (inf or -inf), the implementation fills finite np.finfo(dtype).min / np.finfo(dtype).max (±3.4028235e+38 for float32, ±65504.0 for float16) and torch.finfo(torch.bfloat16).min / max (±3.3895314e+38 for bfloat16) instead of IEEE-754 -inf / +inf.
As a result, whenever src contains -inf (under reduce="amax") or +inf (under reduce="amin"), max(-3.4028235e38, -inf) / min(+3.4028235e38, +inf) silently produces a finite float instead of -inf / +inf across float16, bfloat16, float32, and float64.
Minimal Reproduction
import onnx.reference
import torch
class ScatterReduceMaxNoSelf(torch.nn.Module):
def forward(self, x: torch.Tensor, index: torch.Tensor, src: torch.Tensor) -> torch.Tensor:
return torch.scatter_reduce(x, 0, index, src, reduce="amax", include_self=False)
model = ScatterReduceMaxNoSelf()
x = torch.tensor([10.0, 20.0], dtype=torch.float32)
index = torch.tensor([0], dtype=torch.int64)
src = torch.tensor([-float("inf")], dtype=torch.float32)
eager_out = model(x, index, src)
prog = torch.onnx.export(model, (x, index, src), dynamo=True)
ref = onnx.reference.ReferenceEvaluator(prog.model_proto)
(onnx_out,) = ref.run(None, {"x": x.numpy(), "index": index.numpy(), "src": src.numpy()})
print("PyTorch eager:", eager_out) # tensor([-inf, 20.])
print("ONNX exported:", onnx_out) # [-3.4028235e+38 20. ]
Root Cause
In onnxscript/function_libs/torch_lib/ops/core.py (aten_scatter_reduce):
reduce == "amax"usesnp.finfo(np_dtype).min/torch.finfo(torch.bfloat16).minfor floating-point dtypes instead of-float("inf").reduce == "amin"usesnp.finfo(np_dtype).max/torch.finfo(torch.bfloat16).maxfor floating-point dtypes instead of+float("inf").
(Integer dtypes do not have±inf, sonp.iinfo(np_dtype).min/maxremains the exact identity there.)
Environment
onnxscript:0.7.2andmain(f51083c)torch:2.11.0+cpuonnx:1.23.2
(Note: I noticed #3094 is currently open touching aten_scatter_reduce for reduce="mean", so I avoided opening a competing PR to prevent merge conflicts—happy to submit a small fix with float/int dtype tests once #3094 lands if helpful.)
- Ngôn ngữ chính
- Python
- Star
- 456
- Fork
- 159
- Merge trung bình
- 3 ngày 5 giờ
- Pull request đã merge (30 ngày)
- 23
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không 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 microsoft/onnxscript
-
`fuse_skip_rms_normalization` fuses a float16 residual into a norm whose scale is float32, which ONNX Runtime rejectsCó thể đã có người làm @justinchuby đã nhận 8 ngày trước. Đang mởmodule: optimizer
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
microsoft/onnxscript#3155 · 3 bình luận · 1 reaction · 2 người được giao ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Constant folding uses onnx's plain reference ops, never onnx.reference.ops_optimizedCó thể đã có người làm @todkarsant đã nhận 8 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
microsoft/onnxscript#3003 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
CI : Pin github actions to full commit SHACó thể đã có người làm @Aniketsy đã nhận 193 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
microsoft/onnxscript#2903 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
CastCast rewrite changes rounding for DOUBLE inputs by removing the FLOAT intermediateCó thể đã có người làm @itsrayeedscodespace đã nhận 1 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
microsoft/onnxscript#3204 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Partial rotary fusion sets `rotary_embedding_dim` without `num_heads`, which ONNX Runtime requiresCó thể đã có người làm @justinchuby đã nhận 3 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 25/100
microsoft/onnxscript#3185 ·
Maintainer thường phản hồi trong vòng 2 ngày
Tất cả issue của microsoft/onnxscript
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/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 70/100
Cygnux-Labs/Tracekit#827 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
SPIDevice selects an active-high device as soon as it is createdCó thể đã có người làm @mikeysklar đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 73/100
adafruit/circuitpython#11869 ·
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 80/100
glossyio/traffic-monitor#312 ·
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 70/100
narwhals-dev/narwhals#4154 ·
Maintainer thường phản hồi trong vòng 1 ngày