You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[MLX] sort/argsort(descending=True) silently returns ascending order #25363
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.
I'd like to work on this. Plan: make _sort_handler/_argsort_handler honor descending (sort ascending, then flip along dim when requested), and add descending=True configs to SortTest/ArgsortTest so CI covers it. Will verify on Apple Silicon against current main.
Fix up in #25419 — the lowering now emits an ascending SortNode/ArgsortNode into a tmp slot followed by a full-reverse SliceNode (step=-1) along dim when descending is set, reusing _topk_handler's reverse trick, plus descending=True configs in SortTest/ArgsortTest.
Activity
doge-th commentedon Nov 21, 2026
I'd like to work on this. Plan: make
_sort_handler/_argsort_handlerhonordescending(sort ascending, then flip alongdimwhen requested), and adddescending=Trueconfigs toSortTest/ArgsortTestso CI covers it. Will verify on Apple Silicon against current main.doge-th commentedon Nov 21, 2026
Fix up in #25419 — the lowering now emits an ascending
SortNode/ArgsortNodeinto a tmp slot followed by a full-reverseSliceNode(step=-1) alongdimwhendescendingis set, reusing_topk_handler's reverse trick, plusdescending=Trueconfigs inSortTest/ArgsortTest.