Skip to content

[Feature] Construct mx.array from mps and cuda arrays from other frameworks  #2848

@nbardy

Description

@nbardy

Describe the bug
dlpack doesn't work on mps tensors.

To Reproduce

Include code snippet

>>> import torch
>>> import mlx.core as mx
>>> mx.array(torch.tensor([1,2,3]).to("mps"))
Exception ignored in PyObject_HasAttrString(); consider using PyObject_HasAttrStringWithError(), PyObject_GetOptionalAttrString() or PyObject_GetAttrString():
Traceback (most recent call last):
  File "<python-input-7>", line 1, in <module>
RuntimeError: imag is not implemented for tensors with non-complex dtypes.
Exception ignored in PyObject_HasAttrString(); consider using PyObject_HasAttrStringWithError(), PyObject_GetOptionalAttrString() or PyObject_GetAttrString():
Traceback (most recent call last):
  File "<python-input-7>", line 1, in <module>
RuntimeError: imag is not implemented for tensors with non-complex dtypes.
Traceback (most recent call last):
  File "<python-input-7>", line 1, in <module>
    mx.array(torch.tensor([1,2,3]).to("mps"))
    ~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: Invalid type torch.Tensor received in array initialization.
>>> mx.array(torch.tensor([1,2,3]).to("cpu"))
array([1, 2, 3], dtype=int64)
>>>

Expected behavior
A clear and concise description of what you expected to happen.

Desktop (please complete the following information):

  • MacOS 15.5 (24F74)
>>> mx.__version__
'0.30.0'

Additional context
Add any other context about the problem here.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions