[Bug][Relax] Integer tensor with a Python float scalar is truncated: `x * 0.5` returns zeros
Maintainer thường phản hồi trong vòng 3 ngày
@GoyalIshaan đang làm issue này rồi.
Từ ngày 6/11/2026.
Đá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
- 48/100
Hướng nghiên cứu
Start by tracing the Relax PyTorch frontend's _binary_op handling of Python scalar operands; the issue suggests it may construct the scalar using the tensor's dtype. Check how dtype promotion is handled for arithmetic and comparisons, then reproduce the provided integer tensor cases and compare them with PyTorch eager results. Done means float scalars produce the expected promoted results across the listed operations and tensor dtypes.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Expected behavior
An integer tensor with a Python float scalar is promoted to float32: x * 0.5 is [0.5, 1.0, 1.5] and x + 1.5 is [2.5, 3.5, 4.5].
Actual behavior
The result keeps the integer dtype and the scalar is truncated, so x * 0.5 is all zeros. The same happens for -, for the scalar on the left, for int32, uint8 and bool tensors, and for comparisons (x < 1.5 is all False). An integer scalar, or a float tensor, works.
eager: [([0.5, 1.0, 1.5], torch.float32), ([2.5, 3.5, 4.5], torch.float32)]
tvm: [([0, 0, 0], dtype('int64')), ([2, 3, 4], dtype('int64'))]
Possibly _binary_op builds the scalar as relax.const(rhs, lhs.ty.dtype), so a float scalar is cast to the tensor's integer dtype instead of the tensor being promoted.
Environment
- TVM: main @
2bf0532(0.28.dev0), built from source, targetllvm - PyTorch: 2.12.0+cu130
- Python: 3.12, Ubuntu x86_64
Steps to reproduce
import torch
import tvm
import tvm_tirx
from tvm import relax
from tvm.relax.frontend.torch import from_exported_program
class M(torch.nn.Module):
def forward(self, x):
return x * 0.5, x + 1.5
x = torch.tensor([1, 2, 3])
args = (x,)
print("eager:", [(t.tolist(), t.dtype) for t in M()(x)])
ep = torch.export.export(M(), args)
mod = from_exported_program(ep)
ex = tvm.compile(mod, target="llvm")
vm = relax.VirtualMachine(ex, tvm_tirx.cpu())
out = vm["main"](*[tvm_tirx.runtime.tensor(a.numpy()) for a in args])
print("tvm: ", [(o.numpy().tolist(), o.numpy().dtype) for o in out])
- 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 5 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 Dưới một giờ Mức phù hợp với người mới 92/100
Techiebutler/freeframe#687 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug verbose GC
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
IBM/javacore-analyser#677 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 79/100
Maintainer thường phản hồi trong vòng 2 ngày
-
area/config comp/plugins P1 platform/qqbot tool/file type/bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
NousResearch/hermes-agent#163932 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
plugins/dsh: todayStr() computes UTC but is documented as local — journal entries written 00:00–08:00 local land in the previous day's fileCó thể đã có người làm @Beehtrix đã nhận hôm nay. Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
zilliztech/memsearch#907 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày