Repository navigation
fix(ops): pass one shift for each axis in roll(_:shift:axes:) - #50
Merged
Merged
Conversation
roll(_:shift:axes:) passed one shift value for all the axes, so MLX raised an error when there were two or more axes. Repeat the shift for each axis, as Python mx.roll does for an integer shift. RollMultipleAxesTests covers it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Oct 1, 2026
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
Defect
Source/MLX/Ops.swift:2595,roll(_:shift:axes:)passes[shift](one value) with all the axes tomlx_roll_axes. The C++roll(a, Shape shift, axes)needs one shift value for each axis, so with two or more axes MLX raises[roll] At least one shift value per axis is required.PR #41 found this with
OpsCoverageTests.testRollMultipleAxes(Fork Tests run 36806791209 recorded it as an expected failure).Reference behavior
Python
mx.roll(a, 1, axis=(0, 1))calls the C++ overloadroll(a, int shift, axes), which repeats the shift for each axis. Fora = [[0, 1, 2], [3, 4, 5]]the result is[[5, 3, 4], [2, 0, 1]].Fix
Repeat the shift once for each axis before the call.
Test
Tests/MLXTests/RollMultipleAxesTests.swiftaddstestRollMultipleAxes. It checks the two-axis roll above and a one-axis roll. It is the same test asOpsCoverageTests.testRollMultipleAxesin #41, without theXCTExpectFailurewrapper.Merge note
This PR fixes the defect that #41 records in
OpsCoverageTests.testRollMultipleAxes. After #41 has removed its wrapper and merged, the duplicate test in this PR can be deleted.Merge order for the fix and recording PRs
XCTExpectFailurewrappers (its PR body has a checklist with file and line), and in test: cover Transformer and the recurrent layers #37 changetestCausalMaskValuesfrom-1e9to the dtype minimum. Do this BEFORE the recording PR merges. XCTest reports an unexpected pass insideXCTExpectFailureas a failure, so with this ordermaindoes not go red between merges.fork.yamlsection at the same line: fix(nn): keep the float16 causal mask finite #39 with fix(nn): make the deprecated SoftMax use the last axis #47, and fix(nn): use the normalized sum as post-norm decoder cross-attention queries #40 with fix(ops): default nanToNum infinities to the largest finite value #51. Git reports a conflict for the second PR of each pair. After the first PR of a pair merges, mergemaininto the branch of the second PR (no rebase), then merge it.DType.complex64.finfo.minis the float64 minimum. In complex64 that value is-inf, so a complex64 mask from fix(nn): keep the float16 causal mask finite #39 is NaN at allowed positions (0 * -inf).Upstream status
Upstream
ml-explore/mlx-swiftmainalready has the fixes of #44, #48, #49 and #51. It still has the defects that #39, #40, #43, #47 and #50 fix.Checklist
pre-commit run --all-filesto format my code / installed pre-commit prior to committing changes (ranswift format format --in-place --configuration .swift-formaton the changed files)fork.yaml;check_forkdiff.pypasses)🤖 Generated with Claude Code