[Bug] [Relax][Runtime] CPU TopK builds for uint64 but fails in the runtime sort
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
阅读 src/runtime/extra/contrib/sort/sort.cc 中的 CPU 排序分派逻辑,尤其是第 456–575 行附近的 int64 分支。使用启用了 LLVM 的 TVM 构建运行提供的 ONNX TopK 复现;当 UINT64 返回预期的值和索引(与 INT64 对照用例相同)时,即表示完成。
由索引模型根据 Issue 内容生成。
描述
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,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
apache/tvm 的其他 Issue
-
[Bug] [Relax][ONNX] OneHot does not convert floating-point depth to int64可能已有人在做 @tandede 于 2 天前认领。 未关闭needs-triage type: bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
needs-triage type: bug
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
needs-triage type: bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
[Bug][Relax] ReorderTakeAfterMatmul fails on vector dot products可能已有人在做 @hiyufan 于 12 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
needs-triage type: bug
难度 2/5 1-3 小时 新手友好度 85/100
维护者通常 1 天内回复
相似的 Issue
-
bug good first issue
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 76/100
graphql-python/graphql-core#304 ·
维护者通常 1 天内回复
-
docs size:S
难度 1/5 1 小时以内 新手友好度 88/100
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 88/100
Gathin23/cleanyourtv#3464 ·
维护者通常 1 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复