[Bug][Relax][PyTorch] float64 `matmul` / `mm` / `conv` results are downcast to float32 by `from_exported_program`
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
- 42/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- machine-learning
Hướng nghiên cứu
The float32 cast is likely hard-coded in the matmul, mm, addmm and conv converters of the PyTorch frontend under python/tvm/relax/frontend/torch, so start by searching there for out_dtype="float32". Reproduce with the matmul snippet in the issue and the Linear-with-bias case, which currently raises a TypeError. Done means float64 and bfloat16 inputs keep their dtype, and the bias case converts and matches eager output.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Expected behavior
torch.mm on float64 inputs returns float64. The model converted with from_exported_program should keep the dtype and precision.
Actual behavior
The result is silently float32, so the precision is lost. The same happens for torch.matmul, torch.einsum, Conv1d, Conv2d, ConvTranspose2d and Linear without bias, and for bfloat16 inputs. With a float64 bias (Linear, Conv2d), the conversion fails instead:
eager: torch.float64 [[5.0000000002]]
tvm: float32 [[5.0]]
TypeError: Binary operators must have the same datatype for both operands.
Possibly out_dtype="float32" is hard-coded in the matmul, mm, addmm and conv converters.
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 torch.mm(x, x.T)
x = torch.tensor([[1.0 + 1e-10, 2.0]], dtype=torch.float64)
e = M()(x)
print("eager:", e.dtype, e.tolist())
ep = torch.export.export(M(), (x,))
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(x.numpy()))[0].numpy()
print("tvm: ", out.dtype, out.tolist())
# With a bias, the conversion itself fails
m = torch.nn.Linear(2, 2, dtype=torch.float64)
ep = torch.export.export(m, (x,))
from_exported_program(ep)
- Ngôn ngữ chính
- Python
- Star
- 13.9k
- Fork
- 4k
- Merge trung bình
- 7 giờ 59 phút
- Pull request đã merge (30 ngày)
- 159
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
-
needs-triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 80/100
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug] [Relax][ONNX] OneHot does not convert floating-point depth to int64Có thể đã có người làm @tandede đã nhận 2 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 76/100
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 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
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug][Relax] ReorderTakeAfterMatmul fails on vector dot productsCó thể đã có người làm @hiyufan đã nhận 12 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
apache/tvm#20595 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
strawberry-graphql/strawberry#4794 ·
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 78/100
dataforgoodfr/cetolog#21 ·
-
security_citations_test fails against ecc 2026.11.6: SECURITY.md quotes ecc v2026.11.2's linesĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
btclib-org/btclib#2932 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
metrics priority: medium
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 86/100
LearningCircuit/local-deep-research#8336 ·
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 80/100