Fix Device and Stream lexicographic ordering - #4086
Merged
Merged
Conversation
wgu9
force-pushed
the
fix-device-stream-ordering
branch
from
August 9, 2026 02:54
adb0455 to
10a2170
Compare
zcbenz
approved these changes
Aug 9, 2026
zcbenz
left a comment
Member
There was a problem hiding this comment.
This is a very beautiful fix, thanks!
CharlieTLe
added a commit
to CharlieTLe/mlx-swift
that referenced
this pull request
Aug 9, 2026
ml-explore/mlx#4083 was fixed by ml-explore/mlx#4086, which uses `std::tie` rather than the hand-rolled comparison this patch carried. The fix is not in a release yet -- v0.32.0 is still the newest tag and it landed after -- so the patch has to stay for now. Making it byte-identical to the upstream commit means `patch-mlx.sh` sees the patch as already applied once mlx carries the fix, so it no-ops rather than failing. Verified against e2aa0d096. Note in vendor-README.md what to delete when mlx is next bumped to a release containing it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Proposed changes
Fixes #4083.
This makes
DeviceandStreamcomparisons lexicographic, so they satisfy strict weak ordering when the first and second fields sort in opposite directions.I also added regression coverage for asymmetry, transitivity, and
std::setordering for both types.Testing
pre-commit run --files mlx/device.h mlx/stream.h tests/device_tests.cppcmake -S . -B build -DMLX_BUILD_METAL=OFF -DMLX_BUILD_EXAMPLES=OFF -DMLX_BUILD_PYTHON_BINDINGS=OFFcmake --build build --target tests -j 8ctest --test-dir build --output-on-failure -j 1(248/248 passed)Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes