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

オープン 初心者向け
#20,896 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
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分
マージ済み PR(30日)
159

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

apache/tvm のほかの issue

apache/tvm の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。