[Bug] [Relax][Runtime] CPU TopK builds for uint64 but fails in the runtime sort

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

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

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

调研方向

阅读 src/runtime/extra/contrib/sort/sort.cc 中的 CPU 排序分派逻辑,尤其是第 456–575 行附近的 int64 分支。使用启用了 LLVM 的 TVM 构建运行提供的 ONNX TopK 复现;当 UINT64 返回预期的值和索引(与 INT64 对照用例相同)时,即表示完成。

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

描述

needs-triage type: bug
Expected behavior

A legal UINT64 ONNX TopK should return the selected values and indices on CPU, as the equivalent INT64 control does.

Actual behavior

Both models import and build. INT64 runs correctly, but UINT64 fails only when the VM executes:

InternalError: Unsupported input dtype: uint64

The CPU sort dispatch has an int64 branch but no uint64 branch. The script checks ONNX reference results and uses nonnegative values representable in both types.

Environment

TVM 0.28.dev0, LLVM 18.1.3, Linux x86_64; Python 3.12.3, NumPy 2.5.4, ONNX 1.22.0, ORT 1.29.0. The installed binary build revision is unknown; current main was inspected statically, not rebuilt.

Steps to reproduce

Run with an LLVM-enabled TVM installation:

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

for dtype, elem_type in (("int64", T.INT64), ("uint64", T.UINT64)):
    x = np.array([1, 4, 2], dtype=dtype)
    expected = [np.array([4, 2], dtype=dtype), np.array([1, 2], dtype="int64")]
    model = h.make_model(h.make_graph([
        h.make_node("TopK", ["x", "k"], ["values", "indices"])], "topk",
        [h.make_tensor_value_info("x", elem_type, [3])],
        [h.make_tensor_value_info("values", elem_type, [2]),
         h.make_tensor_value_info("indices", T.INT64, [2])],
        [nh.from_array(np.array([2], dtype="int64"), "k")]),
        opset_imports=[h.make_opsetid("", 11)], ir_version=10)
    onnx.checker.check_model(model, full_check=True)
    for a, b in zip(ReferenceEvaluator(model).run(None, {"x": x}), expected):
        np.testing.assert_array_equal(a, b)
    mod = from_onnx(model, keep_params_in_input=False)
    vm = relax.VirtualMachine(relax.build(mod, target="llvm"), tvm.cpu())
    try:
        actual = vm["main"](tvm.runtime.tensor(x))
        for a, b in zip(actual, expected):
            np.testing.assert_array_equal(a.numpy(), b)
        print(dtype, "control passed")
    except Exception as error:
        if dtype == "int64":
            raise
        print(dtype, type(error).__name__, str(error).splitlines()[-1])
Triage
  • needs-triage
主要语言
Python
星标
13.9k
派生
4k
平均合并
7 小时 59 分钟
30 天内合并 PR
159

环境准备

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

从这里开始

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

apache/tvm 的其他 Issue

查看 apache/tvm 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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