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

未关闭 适合新手
#20,932 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python

调研方向

从 python/tvm/topi/image/resize.py 中 issue 链接的坐标计算开始,然后阅读 ONNX Resize-13 关于输出尺寸为 1 时的 align_corners 规则。使用高度 3 和 1 运行提供的复现;当高度为 1 的情况能够构建并返回 [[[[0, 0.5, 1]]]],且高度为 3 的对照情况仍然通过时,即为完成。为此情况添加或找到一个回归测试。

由索引模型根据 Issue 内容生成。

描述

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
主要语言
Python
星标
13.9k
派生
4k
平均合并
8 小时 6 分钟
30 天内合并 PR
147

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

apache/tvm 的其他 Issue

查看 apache/tvm 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。