[MLX] sort/argsort(descending=True) silently returns ascending order
I maintainer di solito rispondono entro 1 giorno
@2648782102 ci sta già lavorando.
Dal 20/11/2026.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 76/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Ambito
- backend, machine-learning
Direzione di ricerca
Start with _sort_handler and _argsort_handler in backends/mlx/ops.py, then check the MLX SortTest and ArgsortTest cases. Run the reported op test harness with descending=True and compare values and indices with PyTorch. Done means descending results are correct, or those calls remain undelegated, with tests covering both operations.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
The MLX delegate accepts torch.sort(..., descending=True) and torch.argsort(..., descending=True) but ignores descending. Both ops are fully delegated and return ascending results.
For x = [4, -2, 7, 1]:
sort values |
sort indices |
argsort |
|
|---|---|---|---|
| PyTorch / expected | [7, 4, 1, -2] |
[2, 0, 3, 1] |
[2, 0, 3, 1] |
| MLX delegate / actual | [-2, 1, 4, 7] |
[1, 3, 0, 2] |
[1, 3, 0, 2] |
_sort_handler and _argsort_handler both accept up to three args but only read x and dim. SortTest and ArgsortTest have no descending=True configs, so CI doesn't catch it. This is the same kind of bug as #25332 (topk ignoring largest). Either descending needs to affect the lowering, or descending=True should stay undelegated.
Repro with the MLX op test harness. It needs op_test_runner: cmake --preset mlx-release -DEXECUTORCH_BUILD_TESTS=ON && cmake --build cmake-out --target op_test_runner.
import torch
from executorch.backends.mlx.test.test_utils import OpTestCase
class Sort(torch.nn.Module):
def forward(self, x):
values, indices = torch.sort(x, descending=True)
return values, indices
class Argsort(torch.nn.Module):
def forward(self, x):
return torch.argsort(x, descending=True)
class Case(OpTestCase):
def __init__(self, name, model):
self.name, self.model = name, model
def create_model(self):
return self.model
def create_inputs(self):
return (torch.tensor([4.0, -2.0, 7.0, 1.0]),)
for name, model in [("sort_descending", Sort()), ("argsort_descending", Argsort())]:
print(name, "PASS" if Case(name, model).run_test() else "FAIL")
Both cases print MLX delegation verified and then fail the output comparison.
Environment: main at ba0d826cc8, MLX pin 1f8e74e3, Release build, Apple M2 Ultra, macOS 27.2, Python 3.13, PyTorch 2.14.0.
Found while reviewing #25358, and verified with help from Claude Code.
cc @metascroy
- Lingua principale
- Python
- Stelle
- 5.2k
- Fork
- 1.3k
- Merge medio
- 1g 7h
- PR unite (30g)
- 644
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di pytorch/executorch
-
to_edge_transform_and_lower ignores some ops_to_not_decompose requests: multi-output ops, and non-core ops without a decompositionForse già presa @Eureka-Zhang l’ha presa 7 giorni fa. Apertamodule: exir
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
pytorch/executorch#25620 ·
I maintainer di solito rispondono entro 1 giorno
-
Qualcomm AI Engine Direct - fp16a8w quantization crashes on layer_normForse già presa @psiddh l’ha presa 21 giorni fa. Apertabug module: qnn partner: qualcomm
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
pytorch/executorch#24434 · 1 assegnatario ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement triaged
Difficoltà 2/5 Mezza giornata Idoneità per principianti 68/100
pytorch/executorch#21640 ·
I maintainer di solito rispondono entro 1 giorno
-
quantize_per_channel and dequantize_per_tensor.tensor abort the process on a float32 scaleForse già presa @AxelNoun l’ha presa oggi. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
pytorch/executorch#25873 ·
I maintainer di solito rispondono entro 1 giorno
-
XNNPACK INT4 linear returns incorrect per-channel outputs and fails groupwise FP16 on Apple M4 MaxForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertabug module: quantization module: xnnpack
Difficoltà 4/5 3-5 giorni Idoneità per principianti 43/100
pytorch/executorch#25854 ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di pytorch/executorch
Issue simili
-
Container fails to start when GitHub Releases is unavailable: uv run re-downloads the tvl wheelAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
trezor/trezor-user-env#421 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100
-
Difficoltà 1/5 1-3 ore Idoneità per principianti 91/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
tangentcode/tangentswarm#167 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno