Metal backend: generated kernels index a packed copy of a non-packed view out of bounds (wrong results, crash in MPSGraph)
Maintainer thường phản hồi trong vòng 1 ngày
@abdelaziz-mahdy đang làm issue này rồi.
Từ ngày 22/9/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
🐛 Describe the bug
With inductor's default layout optimization, models built on chunk + cat along C (the YOLO C2f block) return wrong values on the Metal backend, and yolov8n crashes inside MPSGraph.
aoti_torch__reinterpret_tensor replaces a view that is not densely packed with a packed copy (materialize_packed). Kernels generated by inductor never look at the tensor they are handed: they index with the strides they were compiled with, and they write through such views as well as read them. In channels-last a chunk along C is non-packed, and a cat is filled by writing through views of it:
buf52 = reinterpret_tensor_wrapper(buf55, 4, {1, 32, 80, 80}, {819200, 1, 10240, 128}, 32) // alias
buf55 has 819200 elements and the copy that stands in for buf52 has 204800. The kernel writing "into buf52" indexes up to 819200 into that copy, which is an out-of-bounds GPU access, and nothing reaches buf55. #22957 lists the lost writes under "Not fixed here" (linear_chunk_cat_last_dim is skipped for it); the out-of-bounds part is new, and it is what takes yolov8n down: 10 out of 10 runs crash with EXC_BAD_ACCESS in -[MPSGraphExecutable runInternalWithDevice:...] -> getFuncOp -> mlir::SymbolTable::lookupSymbolIn, called from aoti_torch_mps_convolution, on a pointer that reads as two floats. With torch._inductor.config.layout_optimization = False there are no such views and the same model runs correctly.
Repro. The C2f block reduced to 1x1 convs, so that it only needs matmuls. For MODULE_REGISTRY in backends/apple/metal/tests/test_modules.py:
class PointwiseC2f(nn.Module):
class Inner(nn.Module):
def __init__(self, channels: int):
super().__init__()
self.conv1 = nn.Conv2d(channels, channels, kernel_size=1)
self.conv2 = nn.Conv2d(channels, channels, kernel_size=1)
def forward(self, x):
return x + self.conv2(torch.relu(self.conv1(x)))
def __init__(self):
super().__init__()
self.conv_in = nn.Conv2d(16, 16, kernel_size=1)
self.inner = nn.ModuleList(PointwiseC2f.Inner(8) for _ in range(2))
self.conv_out = nn.Conv2d(32, 16, kernel_size=1)
def forward(self, x):
parts = list(self.conv_in(x).chunk(2, dim=1))
for block in self.inner:
parts.append(block(parts[-1]))
return self.conv_out(torch.cat(parts, dim=1))
MODULE_REGISTRY["pointwise_c2f"] = {
"model_class": PointwiseC2f,
"input_shapes": [(2, 16, 8, 8)],
"description": "C2f block whose cat is filled through non-packed channels-last views",
}
Output mismatch - max_atol=0.586, max_rtol=1.64 in float32, 0.755 / 1.71 in bfloat16.
Versions
ExecuTorch: #22957 @ 89dbe34077 (main @ 9b91b43098 plus that PR)
PyTorch version: 2.14.0
OS: macOS 27.0 (26A428), arm64, Apple M2 Pro
Clang version: 21.0.0 (clang-2100.3.34.2)
CMake version: 4.4.3
Python version: 3.10.11
- Ngôn ngữ chính
- Python
- Star
- 5k
- Fork
- 1.2k
- Merge trung bình
- 2 ngày 9 giờ
- Pull request đã merge (30 ngày)
- 555
Chuẩn bị môi trường
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/executorch
-
enhancement triaged
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 68/100
pytorch/executorch#21640 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement module: examples
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
pytorch/executorch#23164 · 7 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Qualcomm: 8-bit per-channel weight scales are floored at the 16-bit eps, and the HTP miscomputes near-zero channelsCó thể đã có người làm @psiddh đã nhận 1 ngày trước. Đang mởmodule: qnn partner: qualcomm
pytorch/executorch#23160 · 1 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[cpu kernels] native_layer_norm: layer_norm_scalar returns NaN on large-mean rows; Half/BF16 at N>=256 slow after #23153Có thể đã có người làm @JakeStevens đã nhận 1 ngày trước. Đang mởmodule: kernels
pytorch/executorch#23159 · 2 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
module: vulkan
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 66/100
pytorch/executorch#23158 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của pytorch/executorch
Issue tương tự
-
pydanty:is-working
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pydantic/pydantic-ai#8843 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
breaking change enhancement server
Độ 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
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
sktime/sktime#11310 · 1 bình luận ·
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 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
needs-triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
Maintainer thường phản hồi trong vòng 1 ngày