CastCast rewrite changes rounding for DOUBLE inputs by removing the FLOAT intermediate
Maintainer thường phản hồi trong vòng 2 ngày
@itsrayeedscodespace đang làm issue này rồi.
Từ ngày 12/11/2026.
- #3205 của @itsrayeedscodespace — đang mở
Đá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
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- python
- Lĩnh vực
- backend-api-design
Hướng nghiên cứu
Find the CastCast rewrite rule in onnxscript.rewriter.rules.common and read how it determines whether the intermediate cast can be removed. Add focused tests for the reported DOUBLE rounding boundary and for supported mixed precision source types, then run the relevant rewrite tests. Done means the rewrite preserves both casts for DOUBLE or unknown source types while still collapsing the supported combinations; an open linked pull request already addresses this issue.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description
The CastCast rewrite checks the intermediate/output dtype pair but ignores the source dtype. It currently treats both Cast(Cast(X, FLOAT), FLOAT16) and Cast(Cast(X, FLOAT), BFLOAT16) as equivalent to a direct cast for every source type.
That is not true for wider sources: rounding to FLOAT can land exactly on a lower-precision midpoint, so the second rounding can differ from a direct cast. This silently changes valid model outputs.
Reproduction
Reproduced locally on main f51083c, Python 3.12.16, macOS arm64, using the ONNX reference evaluator:
import numpy as np
import onnx
import onnx.reference
import onnx_ir as ir
from onnxscript.rewriter.rules.common import _basic_rules
h = onnx.helper
model = h.make_model(
h.make_graph(
[
h.make_node("Cast", ["X"], ["M"], to=onnx.TensorProto.FLOAT),
h.make_node("Cast", ["M"], ["Y"], to=onnx.TensorProto.FLOAT16),
],
"rounding",
[h.make_tensor_value_info("X", onnx.TensorProto.DOUBLE, [1])],
[h.make_tensor_value_info("Y", onnx.TensorProto.FLOAT16, [1])],
),
opset_imports=[h.make_opsetid("", 18)],
ir_version=10,
)
rewritten = ir.from_proto(model)
print(_basic_rules.cast_cast_rule.apply_to_model(rewritten)) # 1
feeds = {"X": np.array([1.00048828125 + 2**-30], dtype=np.float64)}
for candidate in (model, ir.to_proto(rewritten)):
y = onnx.reference.ReferenceEvaluator(candidate).run(None, feeds)[0]
print(y, y.view(np.uint16))
Original: [1.] [15360]
Rewritten: [1.001] [15361]
NumPy independently gives the same distinction for x.astype(np.float32).astype(np.float16) versus x.astype(np.float16).
This is semantic correctness evidence from the reference evaluator, not a GPU/performance claim. In my local ONNX Runtime CPU check, both graphs returned the lower value; that runtime result does not independently demonstrate this rewrite's numerical difference.
Proposed fix
Restrict elimination to source dtypes for which widening to FLOAT is exact, retaining the intended mixed-precision cases (FLOAT, FLOAT16 and BFLOAT16). Preserve both casts for DOUBLE, unproven source types, or missing source-type information. Add exact-result tests around rounding boundaries plus positive tests that the supported mixed-precision combinations still collapse.
I checked open PRs and searched issues/PRs for CastCast and cast rounding/precision; I did not find a competing fix for this source-type guard.
- 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
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
microsoft/onnxscript#3200 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
`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
-
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ự
-
fleet size/m
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
sipyourdrink-ltd/bernstein#7548 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
good first issue help wanted level 1 wocs
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
GianlucaBave/murmury#73 ·
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 78/100
G-nn-r/lg_heatpump#52 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
agno-agi/agno#11657 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
category:codebase:gpi category:codebase:handle type:bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Maintainer thường phản hồi trong vòng 1 ngày