[Bug] [Relax][ONNX] Resize align_corners divides by zero for a unit output extent

Đang mở Phù hợp với người mới
#20,932 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 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
78/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
backend, machine-learning

Hướng nghiên cứu

Bắt đầu với phép tính tọa độ được liên kết trong issue tại python/tvm/topi/image/resize.py, sau đó đọc quy tắc align_corners của ONNX Resize-13 cho kích thước đầu ra bằng một. Chạy ví dụ tái hiện được cung cấp với chiều cao 3 và 1; hoàn thành khi trường hợp chiều cao 1 được biên dịch và trả về [[[[0, 0.5, 1]]]], trong khi trường hợp đối chứng chiều cao 3 vẫn đạt. Thêm hoặc tìm một bài kiểm thử hồi quy cho trường hợp này.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

needs-triage type: bug
Expected behavior

Resize-13 maps the coordinate to zero when an align_corners output extent is one. Resizing this input to (1,1,1,3) should return [[[[0,0.5,1]]]].

Actual behavior

Output height 3 executes correctly; changing only height to 1 fails while building with Divide by zero. The coordinate calculation divides by output_size-1 without the unit-extent case. This differs from #20877, which concerns the tf_crop_and_resize branch.

Environment

TVM 0.28.dev0, LLVM 18.1.3, Linux x86_64; Python 3.12.3, NumPy 2.5.4, ONNX 1.22.0. Installed binary build revision is unknown. Current main was inspected statically, not rebuilt.

Steps to reproduce
import numpy as np
import onnx
import tvm
from onnx import TensorProto as T, helper as h, numpy_helper as nh
from onnx.reference import ReferenceEvaluator
from tvm import relax
from tvm.relax.frontend.onnx import from_onnx

x = np.arange(4, dtype="float32").reshape(1, 1, 2, 2)
for height in [3, 1]:
    shape = [1, 1, height, 3]
    model = h.make_model(h.make_graph([
        h.make_node("Resize", ["x", "", "", "sizes"], ["y"], mode="linear", coordinate_transformation_mode="align_corners")],
        "resize", [h.make_tensor_value_info("x", T.FLOAT, x.shape)],
        [h.make_tensor_value_info("y", T.FLOAT, shape)],
        [nh.from_array(np.array(shape, dtype="int64"), "sizes")]),
        opset_imports=[h.make_opsetid("", 13)], ir_version=10)
    onnx.checker.check_model(model, full_check=True)
    expected = ReferenceEvaluator(model).run(None, {"x": x})[0]
    if height == 1:
        np.testing.assert_array_equal(expected, [[[[0, .5, 1]]]])
    try:
        mod = from_onnx(model, keep_params_in_input=False)
        vm = relax.VirtualMachine(relax.build(mod, target="llvm"), tvm.cpu())
        actual = vm["main"](tvm.runtime.tensor(x)).numpy()
    except Exception as error:
        if height != 1:
            raise
        assert "zero" in str(error).lower()
        print("size-one failure:", type(error).__name__, str(error).splitlines()[-1])
    else:
        np.testing.assert_allclose(actual, expected)
        assert height != 1, "Expected the reported divide-by-zero failure"
        print("non-unit output control passed")
Triage
  • needs-triage
Ngôn ngữ chính
Python
Star
13.9k
Fork
4k
Merge trung bình
8 giờ 6 phút
Pull request đã merge (30 ngày)
147

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của apache/tvm

Tất cả issue của apache/tvm

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.