Pass pad_width as Python ints in the MLX Pad dispatch - #2398
Open
guillaume-osmo wants to merge 1 commit into
Open
Pass pad_width as Python ints in the MLX Pad dispatch#2398guillaume-osmo wants to merge 1 commit into
guillaume-osmo wants to merge 1 commit into
Conversation
`mlx_funcify_pad` forwarded `pad_width` straight to `mx.pad`, but the linker typifies every input to `mx.array` while `mx.pad` takes an int or a list of (before, after) int pairs, so no pad worked on this backend -- both `test_mlx_pad[constant_default]` and `test_mlx_pad[edge]` were already red on main. Resolve a constant `pad_width` at funcify time, as the `Reshape` dispatch does, since `mx.compile` forbids reading a traced array; fall back to a runtime conversion otherwise, with an explicit `NotImplementedError` if the value turns out not to be readable. Same root cause as pymc-devs#2386 and the sort/argsort `axis` fix.
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.
Closes #2392.
Motivation
mlx_funcify_padforwardedpad_widthstraight tomx.pad, but the linker typifies every input tomx.arraywhilemx.padtakes anintor a list of(before, after)int pairs, so no pad worked on this backend.test_mlx_pad[constant_default]andtest_mlx_pad[edge]were already red onmain.Same root cause as #2386 and #2391.
Implementation
Resolve a
Constantpad_widthat funcify time, as theReshapedispatch does —mx.compileis on by default and forbids reading a traced array. Fall back to a runtime conversion otherwise, raisingNotImplementedErrorwith an explanation if the value turns out not to be readable.mx.padalso rejects a nested list of lists, so a 2-d spec is normalised to a list of tuples.Tests
The two red tests pass now. Added
test_mlx_pad_width_forms, covering scalar, single-pair and per-axis widths ×constantandedgemodes under the full"MLX"mode.Full
tests/link/mlx/suite: no regressions.