[MLX] Any empty output fails at runtime with "write_output: arr.data<void>() is null after wait()"
維護者通常 1 天內回覆
@galiliya 已經在處理了。
開始於 2026年11月23日。
評估
這個 Issue 還沒有評估資料。
描述
An MLX-delegated program fails at runtime whenever one of its outputs has zero elements. PyTorch eager returns the empty tensor, and export puts the whole graph on MLX, so the failure only shows up when the program runs:
RuntimeError: Failed to execute method forward, error: 0x1: MLX execute failed: write_output: arr.data<void>() is null after wait(); CALL_DELEGATE execute failed at instruction 0: 0x1
It isn't tied to one op. All of these fail, while x + 1 on a non-empty input runs fine:
| Model | Input shape | Expected output shapes |
|---|---|---|
torch.topk(x, 0) |
(3, 5) |
(3, 0), (3, 0) |
x[:, 2:2] * 2 |
(3, 5) |
(3, 0) |
x + 1 |
(0, 5) |
(0, 5) |
(x + 1, x[:, 2:2] * 2) |
(3, 5) |
(3, 5), (3, 0) |
write_output resizes the output and checks that the byte counts match (both are 0). It then throws because arr.data<void>() is null, which is what MLX gives for an empty array. Since there's nothing to copy, returning early before the null check fixes all four cases in my local build:
if (out_nbytes == 0) {
return;
}
FACTO found this while I was reviewing #25358. All 11 of its generated topk.default cases with k=0 fail this way, across int8, uint8, int64, float16, bfloat16 and float32 and for both values of largest. The MLX op tests have no empty-output configs, so CI doesn't catch it. #25331 is a separate empty-tensor bug (an empty mm crashes inside MLX) that this change doesn't address.
Repro, with an MLX-enabled Python runtime:
import torch
from executorch.backends.mlx.partitioner import MLXPartitioner
from executorch.exir import to_edge_transform_and_lower
from executorch.extension.pybindings.portable_lib import (
_load_for_executorch_from_buffer,
)
class Model(torch.nn.Module):
def forward(self, x):
values, indices = torch.topk(x, 0)
return values, indices
inputs = (torch.randn(3, 5),)
print(Model()(*inputs)) # two empty (3, 0) tensors
ep = torch.export.export(Model(), inputs)
edge = to_edge_transform_and_lower(ep, partitioner=[MLXPartitioner()])
runtime = _load_for_executorch_from_buffer(edge.to_executorch().buffer)
print(runtime.forward(inputs)) # RuntimeError
Environment: reproduced at #25358's head cbfc7ed1a6 with MLX pin 14dc9c67 (write_output is unchanged on main at 729de6f2c9), Release build, Apple M2 Ultra, macOS 27.2, Python 3.13, PyTorch 2.14.0.
Verified with help from Claude Code.
cc @metascroy
- 主要語言
- Python
- 星號
- 5.2k
- 分支
- 1.3k
- 平均合併
- 1 天 14 小時
- 30 天內合併 PR
- 678
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
pytorch/executorch 的其他 Issue
-
module: exir
難度 2/5 1-3 小時 新手友好度 66/100
pytorch/executorch#25620 ·
維護者通常 1 天內回覆
-
Qualcomm AI Engine Direct - fp16a8w quantization crashes on layer_norm可能已有人在做 @psiddh 於 14 天前認領。 未關閉bug module: qnn partner: qualcomm
難度 2/5 1-3 小時 新手友好度 74/100
pytorch/executorch#24434 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
enhancement triaged
難度 2/5 半天 新手友好度 68/100
pytorch/executorch#21640 ·
維護者通常 1 天內回覆
-
Reminder to update MLX pin to release tag可能已有人在做 @mergennachin 今天認領。 未關閉
pytorch/executorch#25602 · 已指派 1 人 ·
維護者通常 1 天內回覆
-
[MLX] repeat_interleave without `dim` does not flatten the input and fails at runtime可能已有人在做 @vineetha00 於 1 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 55/100
pytorch/executorch#25523 ·
維護者通常 1 天內回覆
查看 pytorch/executorch 的全部 Issue
相似的 Issue
-
flaky: test_fire_returns_thread_per_http_entry_on_head waits 5 s per dispatch worker on busy shards未關閉status/accepted type/bug
難度 2/5 1-3 小時 新手友好度 74/100
維護者通常 1 天內回覆
-
bug vector-store
難度 2/5 1-3 小時 新手友好度 85/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 74/100
EverMind-AI/Raven#1413 ·
維護者通常 1 天內回覆
-
Tests: parallel pyinstallcheck runs oversubscribe the machine through nested TBB and BLAS pools可能已有人在做 關聯的 PR 仍在進行中或已合併。 未關閉
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 86/100
ACCESS-NRI/containerised-environments-infra#143 ·
維護者通常 2 天內回覆