[MLX] Any empty output fails at runtime with "write_output: arr.data<void>() is null after wait()"
Mantenedores costumam responder em até 1 dia
@galiliya já está trabalhando nisso.
Desde 23/11/2026.
Avaliação
Esta issue ainda não foi avaliada.
Descrição
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
- Linguagem predominante
- Python
- Estrelas
- 5.2k
- Forks
- 1.3k
- Merge médio
- 1d 14h
- PRs com merge (30d)
- 678
Preparar o ambiente
- Sem Dockerfile nem arquivo Docker Compose
- Tem um modelo de pull request
- Ler o guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de pytorch/executorch
-
module: exir
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 66/100
pytorch/executorch#25620 ·
Mantenedores costumam responder em até 1 dia
-
Qualcomm AI Engine Direct - fp16a8w quantization crashes on layer_normTalvez já em andamento @psiddh assumiu há 14 dias. Abertabug module: qnn partner: qualcomm
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
pytorch/executorch#24434 · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
enhancement triaged
Dificuldade 2/5 Meio dia Facilidade para iniciantes 68/100
pytorch/executorch#21640 ·
Mantenedores costumam responder em até 1 dia
-
Reminder to update MLX pin to release tagTalvez já em andamento @mergennachin assumiu hoje. Aberta
pytorch/executorch#25602 · 1 responsável ·
Mantenedores costumam responder em até 1 dia
-
[MLX] repeat_interleave without `dim` does not flatten the input and fails at runtimeTalvez já em andamento @vineetha00 assumiu há 1 dia. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 55/100
pytorch/executorch#25523 ·
Mantenedores costumam responder em até 1 dia
Todas as issues de pytorch/executorch
Issues semelhantes
-
bug game: 0100FF500E34A000 game: 0400FF500E34A001 mac packing
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
Mantenedores costumam responder em até 2 dias
-
bug
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
jxxghp/MoviePilot#7576 ·
Mantenedores costumam responder em até 1 dia
-
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 88/100
Mantenedores costumam responder em até 1 dia
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 64/100
jbaruch/software-factory#266 ·
Mantenedores costumam responder em até 1 dia
-
cron: raise a distinct error when next_fire finds no match in its search bound (from #813 item 5)Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
Mantenedores costumam responder em até 1 dia