[MLX] argmax/argmin(keepdim=True) without `dim` fails at runtime with a rank mismatch
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 25/100
Línea de trabajo
The bug is in the dim is None branch of _argmax_handler and _argmin_handler in backends/mlx/ops.py, which reads keepdim but hardcodes keepdims=False. Check the existing argmax/argmin tests, which only cover dim=None with keepdim=False. Done when keepdim=True with no dim returns a tensor with x.ndim dimensions of size 1. Linked PR #25522 is already open against this issue, so coordinate there before starting.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
torch.argmax(x, keepdim=True) and torch.argmin(x, keepdim=True) with no dim export and are delegated to MLX, but the program fails when it runs. PyTorch returns a tensor with x.ndim dimensions of size 1. The MLX handler flattens the input and emits the arg-reduction with keepdims=False, so the delegate produces a 0-d tensor and the output cannot be written.
For x = torch.tensor([[1., 5.], [7., 2.]]):
| Call | PyTorch / expected | MLX delegate / actual |
|---|---|---|
torch.argmax(x, keepdim=True) |
tensor([[2]]), shape [1, 1] |
runtime error |
torch.argmin(x, keepdim=True) |
tensor([[0]]), shape [1, 1] |
runtime error |
[tensor_impl.cpp:113] Attempted to change the tensor rank which is immutable: old=2, new=0
[MLXBackend.cpp:677] MLX execute failed: write_output: failed to resize output tensor
[method.cpp:1786] 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.
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.argmax(x, keepdim=True)
inputs = (torch.tensor([[1.0, 5.0], [7.0, 2.0]]),)
model = Model().eval()
print(model(*inputs)) # tensor([[2]])
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
In backends/mlx/ops.py, the dim is None branch of _argmax_handler and _argmin_handler reads keepdim but hardcodes keepdims=False. The existing tests cover dim=None only with keepdim=False, and the shared test model drops keepdim when dim is None.
Found by reading the op handlers for accepted-but-unused arguments, 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
- Lenguaje dominante
- Python
- Estrellas
- 5.2k
- Forks
- 1.3k
- Merge medio
- 1 d 7 h
- PR fusionados (30 d)
- 644
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de pytorch/executorch
-
to_edge_transform_and_lower ignores some ops_to_not_decompose requests: multi-output ops, and non-core ops without a decompositionPosiblemente ocupada @Eureka-Zhang la tomó hace 7 días. Abiertomodule: exir
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
pytorch/executorch#25620 ·
Los mantenedores suelen responder en 1 día
-
Qualcomm AI Engine Direct - fp16a8w quantization crashes on layer_normPosiblemente ocupada @psiddh la tomó hace 21 días. Abiertobug module: qnn partner: qualcomm
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
pytorch/executorch#24434 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
enhancement triaged
Dificultad 2/5 Medio día Aptitud para principiantes 68/100
pytorch/executorch#21640 ·
Los mantenedores suelen responder en 1 día
-
quantize_per_channel and dequantize_per_tensor.tensor abort the process on a float32 scalePosiblemente ocupada @AxelNoun la tomó hoy. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 35/100
pytorch/executorch#25873 ·
Los mantenedores suelen responder en 1 día
-
XNNPACK INT4 linear returns incorrect per-channel outputs and fails groupwise FP16 on Apple M4 MaxPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abiertobug module: quantization module: xnnpack
Dificultad 4/5 3-5 días Aptitud para principiantes 43/100
pytorch/executorch#25854 ·
Los mantenedores suelen responder en 1 día
Todos los issues de pytorch/executorch
Issues similares
-
Container fails to start when GitHub Releases is unavailable: uv run re-downloads the tvl wheelAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
trezor/trezor-user-env#421 ·
-
Support new version of pythonAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
-
Dificultad 1/5 1-3 horas Aptitud para principiantes 91/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
tangentcode/tangentswarm#167 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día