Skip to content

Pass pad_width as Python ints in the MLX Pad dispatch - #2398

Open
guillaume-osmo wants to merge 1 commit into
pymc-devs:mainfrom
guillaume-osmo:fix-mlx-pad
Open

Pass pad_width as Python ints in the MLX Pad dispatch#2398
guillaume-osmo wants to merge 1 commit into
pymc-devs:mainfrom
guillaume-osmo:fix-mlx-pad

Conversation

@guillaume-osmo

Copy link
Copy Markdown

Closes #2392.

Motivation

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. test_mlx_pad[constant_default] and test_mlx_pad[edge] were already red on main.

Same root cause as #2386 and #2391.

Implementation

Resolve a Constant pad_width at funcify time, as the Reshape dispatch does — mx.compile is on by default and forbids reading a traced array. Fall back to a runtime conversion otherwise, raising NotImplementedError with an explanation if the value turns out not to be readable.

mx.pad also 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 × constant and edge modes under the full "MLX" mode.

Full tests/link/mlx/ suite: no regressions.

`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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MLX backend: every pad raises TypeError (pad_width passed as mx.array)

1 participant