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

Đang mở Phù hợp với người mới
#20,896 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
80/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ệ
cpp, python
Lĩnh vực
compilers

Hướng nghiên cứu

Đọc logic dispatch sắp xếp CPU trong src/runtime/extra/contrib/sort/sort.cc, đặc biệt là nhánh int64 quanh các dòng 456–575. Chạy bản tái hiện ONNX TopK được cung cấp bằng bản build TVM có bật LLVM; công việc được xem là hoàn tất khi UINT64 trả về các giá trị và chỉ mục mong đợi, giống như trường hợp đối chứng INT64.

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

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
Ngôn ngữ chính
Python
Star
13.9k
Fork
4k
Merge trung bình
8 giờ 2 phút
Pull request đã merge (30 ngày)
180

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.