`aten._grouped_mm` converter raises `TypeError` when the offsets are a constant
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ó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 74/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ệ
- python
- Lĩnh vực
- compilers, machine-learning
Hướng nghiên cứu
Bắt đầu từ bộ chuyển đổi grouped_mm trong torch_tensorrt/dynamo/conversion/impl/moe.py, nơi offs được truyền vào cast_trt_tensor trong converter_utils.py, rồi kiểm tra cách enforce_tensor_types xử lý đối số 2. Chạy lại repro trong issue với một buffer offs hằng số và xác nhận TypeError xuất hiện. Công việc được coi là xong khi trường hợp offset hằng số biên dịch được và khớp với PyTorch trong dung sai đã nêu, còn các test grouped_mm hiện có vẫn pass. Phối hợp với PR #5021 để hai bản sửa không xung đột nhau.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
What is wrong
In mixture-of-experts models the group offsets of torch._grouped_mm are sometimes fixed, for example a buffer that says how many rows each expert gets. After freezing, the offsets reach the converter as a constant torch.Tensor, not a TensorRT tensor. The converter only forces its first 2 arguments to TensorRT tensors (enforce_tensor_types({0: ..., 1: ...})), then passes offs to cast_trt_tensor, which expects an ITensor. The conversion fails with a TypeError inside that cast, so the grouped matmul does not run in TensorRT.
What this blocks
cosmos3 (pytorch/executorch#24353) hits this: its grouped matmul stays out of TensorRT, so the graph is split around it into more TensorRT engines and CUDA backend programs.
A fix keeps the grouped matmul inside the engine, so mixture-of-experts layers with fixed groups run fully in TensorRT.
Repro
import torch
import torch_tensorrt
class FixedGroups(torch.nn.Module):
def __init__(self, groups=4, k=64, n=32, rows_per_group=8):
super().__init__()
self.w = torch.nn.Parameter(torch.randn(groups, k, n))
ends = torch.arange(1, groups + 1, dtype=torch.int32) * rows_per_group
self.register_buffer("offs", ends)
def forward(self, x):
return torch._grouped_mm(x, self.w, offs=self.offs)
model = FixedGroups().cuda().bfloat16().eval()
x = torch.randn(32, 64, device="cuda", dtype=torch.bfloat16)
ep = torch.export.export(model, (x,))
trt_gm = torch_tensorrt.dynamo.compile(ep, arg_inputs=[x], min_block_size=1)
torch.testing.assert_close(trt_gm(x), model(x), rtol=2e-2, atol=2e-2)
Expected
The grouped matmul converts and matches PyTorch.
Actual
dynamo.compile raises inside the converter (end of the traceback):
File ".../torch_tensorrt/dynamo/conversion/impl/moe.py", line 93, in grouped_mm
offs_i32 = cast_trt_tensor(
File ".../torch_tensorrt/dynamo/conversion/converter_utils.py", line 276, in cast_trt_tensor
cast_layer = ctx.net.add_cast(input_val, trt_dtype)
TypeError: add_cast(): incompatible function arguments. The following argument types are supported:
1. (self: tensorrt_bindings.tensorrt.INetworkDefinition, input: tensorrt_bindings.tensorrt.ITensor, to_type: tensorrt_bindings.tensorrt.DataType) -> tensorrt_bindings.tensorrt.ICastLayer
Invoked with: <tensorrt_bindings.tensorrt.INetworkDefinition object at 0x7f4dc10b3d30>, tensor([ 8, 16, 24, 32], dtype=torch.int32), <DataType.INT32: 3>
While executing %_grouped_mm : [num_users=1] = call_function[target=torch.ops.aten._grouped_mm.default](args = (%x, %w, %offs), kwargs = {})
Versions
torch 2.15.0 (CUDA 13.2), torch_tensorrt 2.15.0, TensorRT 11.4.0.106, H100, driver 580.126.09.
What was tried
Reading the converter. A likely fix is to add 2: (TRTTensor,) to the converter's enforce_tensor_types, or to call get_trt_tensor on offs before the cast. The new grouped GEMM kernel path in the open PR #5021 already does the second; the default dense path does not.
- Ngôn ngữ chính
- Python
- Star
- 3k
- Fork
- 421
- Merge trung bình
- 4 ngày 7 giờ
- Pull request đã merge (30 ngày)
- 62
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
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 pytorch/TensorRT
-
🐛 [Bug] torch.fmod returns a tiny value with the wrong sign when the float quotient rounds upCó thể đã có người làm @micwill755 đã nhận 4 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
pytorch/TensorRT#4860 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Removing ptq.hĐang mởStory: Build & Install & Packaging
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 18/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của pytorch/TensorRT
Issue tương tự
-
README Quick Start query command fails, and doctor points to a missing Prerequisites sectionĐang mởdocumentation 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 1 ngày
-
add entry to blockĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 65/100
StevenBlack/hosts#3299 ·
-
`garak --report` overwrites the input report when its name has no ".report"Có thể đã có người làm @0z5a đã nhận hôm nay. Đang mởneeds-triage
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
trace: Pi's 1-hour cache writes are priced at 1.25x, but billed at 2xCó thể đã có người làm @Shizoqua đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
microsoft/TokenEconomizer#221 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
plot_graph crashes when a mesh node has no m2m edgeCó thể đã có người làm @tygvi đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
mllam/neural-lam#883 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày