Skip to content

MLX backend: every reshape raises TypeError (shape passed as mx.array) #2386

Description

@jessegrabowski

mlx_funcify_Reshape forwards the shape input straight to mx.reshape, but the linker typifies every input to mx.array and mx.reshape wants a Python sequence of ints, so no reshape works on this backend at all.

import numpy as np
import pytensor
import pytensor.tensor as pt

x = pt.matrix("x", shape=(6, 4), dtype="float32")
xv = np.zeros((6, 4), dtype="float32")

print(pytensor.function([x], x.reshape((24,)), mode="CVM")(xv).shape)  # (24,)
print(pytensor.function([x], x.reshape((24,)), mode="MLX")(xv).shape)
# TypeError: reshape(): incompatible function arguments
#   Invoked with types: mlx.core.array, mlx.core.array

Potential fix (requires testing):

def reshape(x, shp):
    return mx.reshape(x, tuple(shp.tolist()) if isinstance(shp, mx.array) else tuple(shp))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingmlx

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions