[MLX] repeat_interleave without `dim` does not flatten the input and fails at runtime

未关闭
#25,523 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@vineetha00 已经在做这个了。

开始于 2026年11月22日。

  • #25524 来自 @vineetha00 —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
55/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python

调研方向

Start with _repeat_interleave_handler in backends/mlx/ops.py, where a missing dim is read as 0 instead of the None default that flattens the input first. Read the existing repeat_interleave tests, which always pass dim, and add a case without it using the 2x3 input from the report. Done when the MLX-delegated output matches PyTorch's flattened shape [12] with values [0,0,1,1,...,5,5]. The reporter says they already have a fix and plan to open a PR, so check with them before starting.

由索引模型根据 Issue 内容生成。

描述

torch.repeat_interleave(x, repeats) with no dim repeats the elements of the flattened input and returns a 1-D tensor. The MLX delegate treats a missing dim as dim=0, so for inputs with more than one dimension it repeats along axis 0 without flattening. The program exports and is delegated to MLX, then fails when it runs because the output rank does not match.

For x = torch.arange(6.0).reshape(2, 3) and torch.repeat_interleave(x, 2):

Result
PyTorch / expected [0., 0., 1., 1., 2., 2., 3., 3., 4., 4., 5., 5.], shape [12]
MLX delegate / actual runtime error
Failed to execute method forward, error: 0x1: Attempted to change the tensor rank which is immutable: old=1, new=2; MLX execute failed: write_output: failed to resize output tensor; CALL_DELEGATE execute failed at instruction 0: 0x1

Reproduced on ExecuTorch 8c3f75dfb1d70ad12161ab3c42b06b7e7a65e8ce.

Environment: Apple Silicon MacBook Air, macOS 15.1, Xcode 16.2, Python 3.12, built with install_executorch.py.

With an MLX-enabled ExecuTorch 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):
        return torch.repeat_interleave(x, 2)


inputs = (torch.arange(6.0).reshape(2, 3),)
model = Model().eval()
print(model(*inputs))  # tensor([0., 0., 1., 1., 2., 2., 3., 3., 4., 4., 5., 5.])
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

_repeat_interleave_handler in backends/mlx/ops.py uses dim = args[2] if len(args) > 2 else 0, but the default for aten.repeat_interleave.self_int is dim=None, which means flatten first. The existing repeat_interleave tests always pass dim.

Found by reading the op handlers for arguments whose defaults are not honored, after #25332 and #25363. I have a fix with tests and will open a PR.

Investigated and written with assistance from Anthropic Claude.

cc @metascroy

主要语言
Python
星标
5.2k
派生
1.3k
平均合并
1 天 14 小时
30 天内合并 PR
678

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

pytorch/executorch 的其他 Issue

查看 pytorch/executorch 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。