[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時間
- マージ済み PR(30日)
- 678
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
[Maintainer] task area:visualizer
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
RailtownAI/railtracks#1824 ·
メンテナーはふだん 3 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
apache/datafusion#27688 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
heasarc/heasarc-tutorials#317 ·
-
bug good first issue help wanted
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
mloda-ai/mloda-registry#1664 ·
メンテナーはふだん 1 日以内に返信