[Bug] InferLayoutStack does not handle negative axis

Đang mở
#20,902 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ó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
68/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

Start at src/relax/op/tensor/manipulate.cc around line 1787, where InferLayoutStack handles the axis, and reproduce the failure with the provided R.stack(..., axis=-1) example followed by ConvertLayout({}). Trace how the axis is validated and used to insert into layout_str; done means this negative-axis case no longer crashes and the relevant tests pass.

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

https://github.com/apache/tvm/blob/main/src/relax/op/tensor/manipulate.cc#L1787 trys to convert axis to size_t and insert a character at such position to layout_str. However as described by https://tvm.apache.org/docs/reference/api/python/relax/op.html#tvm.relax.op.stack, the axis can be negative. Program will crash if the axis is negative.

C++ does check whether the position is valid, and throws errors like tvm.error.InternalError: basic_string::replace: __pos (which is 18446744073709551615) > this->size() (which is 2)

Steps to reproduce
from tvm.script import ir as I
from tvm.script import relax as R

@I.ir_module
class Module:
    @R.function
    def main(inp_0: R.Tensor((2, 3), dtype="float32")) -> R.Tuple(R.Tensor((2, 3, 2), dtype="float32")):
        with R.dataflow():
            lv: R.Tensor((2, 3, 2), dtype="float32") = R.stack((inp_0, inp_0), axis=-1)
            gv: R.Tuple(R.Tensor((2, 3, 2), dtype="float32")) = (lv,)
            R.output(gv)
        return gv

import tvm
tvm.relax.transform.ConvertLayout({})(Module)
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.