[MLX] Empty matrix multiplication crashes the process in Contiguous::eval_gpu

オープン
#25,331 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@jay23606 がすでに取り組んでいます。

2026年11月20日 から。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
cpp, python, pytorch

調査の方向性

Start by tracing the MLX backend execution path to Contiguous::eval_gpu, using the standalone op_test_runner reproduction with the empty (0, 5) and (5, 10) inputs. Compare MLX delegated execution with the portable kernel control; done means the runtime returns an empty (0, 10) tensor or safely rejects the unsupported shape instead of crashing.

索引モデルが issue の本文から書いたものです。

説明

good first issue module: mlx

An MLX-delegated torch.mm with valid inputs of shapes (0, 5) and (5, 10) terminates the process with SIGSEGV. PyTorch eager and the ExecuTorch portable kernel both return the expected empty (0, 10) tensor. Export succeeds and assigns the operation to MLX, so the failure reaches applications at runtime.

Reproduced on ExecuTorch 3e8e3f8a0ea22bac35cd67757add7a82c82bd287 with its original MLX pin 1f8e74e3f12f31365464a6867c6579f0e9b29d85 (v0.32.2), and independently with the proposed MLX pin 14dc9c673bce9a51dca4e58f5b2ccae80736431d. This predates the pin update being investigated for #25319.

Environment: Apple M5 Max, macOS 27.2, Release build, Python 3.12, PyTorch 2.15.0. Both the MLX-enabled Python runtime and the standalone C++ op_test_runner crash. Disabling TF32 does not prevent it.

With an MLX-enabled ExecuTorch Python runtime, this is sufficient to reproduce:

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 (
    _get_registered_backend_names,
    _load_for_executorch_from_buffer,
)

assert "MLXBackend" in _get_registered_backend_names()

class Model(torch.nn.Module):
    def forward(self, a, b):
        return torch.mm(a, b)

inputs = (torch.empty(0, 5), torch.ones(5, 10))
model = Model().eval()
print(model(*inputs))  # tensor([], size=(0, 10))
ep = torch.export.export(model, inputs)
edge = to_edge_transform_and_lower(ep, partitioner=[MLXPartitioner()])
assert sum(
    n.target == torch.ops.higher_order.executorch_call_delegate
    for n in edge.exported_program().graph.nodes
) == 1
program = edge.to_executorch()
runtime = _load_for_executorch_from_buffer(program.buffer)
print(runtime.forward(inputs))  # SIGSEGV

As a control, replacing the lowering with to_edge(ep) executes successfully through the portable kernel.

The standalone runner stops at a null dereference in Contiguous::eval_gpu:

stop reason = EXC_BAD_ACCESS (code=1, address=0x0)
mlx::core::Contiguous::eval_gpu(...) + 40
mlx::core::gpu::eval(...)
mlx::core::eval_impl(...)
mlx::core::async_eval(...)
executorch::backends::mlx::MLXBackend::execute(...)
executorch::runtime::Method::execute_instruction()

Expected: return the empty output. Unsupported empty shapes should at least be rejected safely before native execution. A normal model input should not terminate a hosting process.

Found during OpInfo validation; reproduced independently of that harness. Investigated and written with assistance from OpenAI Codex.

cc @metascroy

主要言語
Python
スター
5.2k
フォーク
1.3k
平均マージ
1日 7時間
マージ済み PR(30日)
644

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

pytorch/executorch のほかの issue

pytorch/executorch の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。