[Bug] [Relax] RewriteDataflowReshape breaks value semantics when combined with call_tir_inplace
Maintainer thường phản hồi trong vòng 3 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 72/100
Hướng nghiên cứu
Start by reading the Relax transform implementation for RewriteDataflowReshape and the tests that cover it; the issue does not name specific files or tests. Use the supplied reproduction to compare the transformed output with the expected tuple values, then add regression coverage for the later in-place write. Done means both tuple fields retain their expected values when the pass runs.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Expected behavior
Applying relax.transform.DataflowUseInplaceCalls() and compiling the result should preserve the values of all tuple fields.
For the input [0.0], the example below should return [1.0] and [1.5], both with shape (1,) and dtype float32.
Actual behavior
The transformed program returns [1.5] for both tuple fields. The first result is overwritten by the later in-place update.
The untransformed program returns the expected values. Compiling the same transformed program with RewriteDataflowReshape disabled also returns the expected values.
The relevant IR changes from a separate identity-copy result to a view of m:
# After LegalizeOps:
first = R.call_tir(cls.add1, (m,), out_ty=R.Tensor((1,), "float32"))
# After RewriteDataflowReshape:
first = R.reshape(m, R.shape([1]))
The following R.call_tir_inplace(..., (m,), inplace_indices=[0]) adds 0.5 to m. Consequently, the view returned as first observes the updated value. This suggests that the copy-to-view rewrite needs to account for the later in-place write.
Environment
- OS: Ubuntu 22.04.5 LTS, x86_64; Linux kernel 6.8.0-52-generic
- CPU: 13th Gen Intel Core i9-13900K
- Python: 3.11.16
- TVM:
0.26.dev0+source.8f328e8 - TVM source snapshot:
8f328e802cfe5e41fcc8f5c17e7582b1c28bfce4 - LLVM: 15.0.7
- Target:
llvm; Relax VM on CPU - Python API:
DataflowUseInplaceCalls; its PassInfo name in this build isDataflowInsertInPlaceCalls
Steps to reproduce
Save the following as repro.py and run python repro.py. It uses only TVM and NumPy.
import numpy as np
import tvm
from tvm import relax
from tvm.script import ir as I, relax as R
@I.ir_module
class Before:
@R.function
def main(x: R.Tensor((1,), "float32")):
with R.dataflow():
m = R.add(x, R.const(1.0, "float32"))
first = R.add(m, R.const(0.0, "float32"))
second = R.add(m, R.const(0.5, "float32"))
result = (first, second)
R.output(result)
return result
inplace = relax.transform.DataflowUseInplaceCalls()
after = inplace(Before)
def run(module, skip_reshape=False):
disabled = [str(inplace.info.name)]
if skip_reshape:
disabled.append(str(relax.transform.RewriteDataflowReshape().info.name))
with tvm.transform.PassContext(disabled_pass=disabled):
executable = tvm.compile(module, target="llvm")
vm = relax.VirtualMachine(executable, tvm.cpu())
x = tvm.runtime.tensor(np.zeros((1,), dtype="float32"))
return [value.numpy().copy() for value in vm["main"](x)]
off = run(Before)
on = run(after)
control = run(after, skip_reshape=True)
print("OFF:", off)
print("ON:", on)
print("ON with RewriteDataflowReshape disabled:", control)
expected = [np.array([1.0], dtype="float32"),
np.array([1.5], dtype="float32")]
for actual in (off, control):
for got, want in zip(actual, expected):
np.testing.assert_array_equal(got, want)
np.testing.assert_array_equal(on[1], expected[1])
np.testing.assert_array_equal(on[0], expected[0]) # Fails: [1.5] != [1.0]
Output before the final assertion:
OFF: [array([1.], dtype=float32), array([1.5], dtype=float32)]
ON: [array([1.5], dtype=float32), array([1.5], dtype=float32)]
ON with RewriteDataflowReshape disabled: [array([1.], dtype=float32), array([1.5], dtype=float32)]
The final assertion fails with actual [1.5] and expected [1.0]; the maximum absolute error is 0.5.
Triage
- needs-triage
- Ngôn ngữ chính
- Python
- Star
- 13.9k
- Fork
- 4.1k
- Merge trung bình
- 4 ngày 22 giờ
- Pull request đã merge (30 ngày)
- 22
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
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/tvm
-
[Bug] [Relax] `relax.op.unique(return_inverse=True)` returns an input-shaped inverse for N-D input when `axis` is NoneCó thể đã có người làm Có pull request liên kết đang mở hoặc đã được merge. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 3 ngày
-
[Bug][TOPI] `topi.scanop` (`cumsum` / `cumprod`) performs out-of-bounds write/read on empty tensorsĐang mởneeds-triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Maintainer thường phản hồi trong vòng 3 ngày
-
[Bug] [Relax] take_backward does not normalize negative axis causing heap OOB write and wrong gradientsCó thể đã có người làm @pierceluu10 đã nhận 4 ngày trước. Đang mởneeds-triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 3 ngày
-
[Bug][Relax][ONNX] NonZero returns the wrong output shape for scalar inputsCó thể đã có người làm @tandede đã nhận 9 ngày trước. Đang mởneeds-triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
Maintainer thường phản hồi trong vòng 3 ngày
-
needs-triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
apache/tvm#21043 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
Issue tương tự
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 78/100
web-push-libs/pywebpush#216 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
AgriciDaniel/claude-seo#572 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
area:print-dispatch
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 92/100
Maintainer thường phản hồi trong vòng 1 ngày
-
area: docs domain: technical-writing good first issue type: documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
Deepak3699/Ai_Mentor#919 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày