[Feature] Construct `mx.array` from `mps` and `cuda` arrays from other frameworks
Open
Nobody has claimed this yet.
enhancement
python
- Dominant language
- C++
- Stars
- 28.5k
- Forks
- 2.3k
- Avg merge
- 3d 8h
- Merged PRs (30d)
- 62
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the reported mx.array(torch...to("mps")) failure and compare it with the working CPU case. Trace the DLPack conversion path used by mx.array, then verify that arrays from the reported mps and cuda cases are accepted with correct values and dtypes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- api, machine-learning
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100