Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] Metal implementation of SVD #1392

Open
vgoklani opened this issue Sep 3, 2024 · 6 comments
Open

[Feature] Metal implementation of SVD #1392

vgoklani opened this issue Sep 3, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@vgoklani
Copy link

vgoklani commented Sep 3, 2024

Describe the bug
The mx.linalg.svd crashes

To Reproduce

Include code snippet

import mlx.core as mx

a = mx.array([ [1., 2], [2, 3] ])

u, singular_values, v_transpose = mx.linalg.svd(a=a)

libc++abi: terminating due to uncaught exception of type std::runtime_error: [SVD::eval_gpu] Metal SVD NYI.

Expected behavior

import numpy as np
import mlx.core as mx

a = mx.array([ [1., 2], [2, 3] ])

u, singular_values, v = np.linalg.svd(a=a)

singular_values
array([4.236068 , 0.23606798], dtype=float32)

Desktop (please complete the following information):
MLX 0.17.2

Additional context
Add any other context about the problem here.

@awni
Copy link
Member

awni commented Sep 3, 2024

That is unfortunately expected behavior. Right now svd (and several other linalg operations are only supported on the CPU back-end. You can fix that by passing in the CPU stream to the operation like so:

import mlx.core as mx

a = mx.array([ [1., 2], [2, 3] ])

u, singular_values, v_transpose = mx.linalg.svd(a=a, stream=mx.cpu)

@awni
Copy link
Member

awni commented Sep 3, 2024

I'm going to change this from a bug to a feature request and mark it as such. Note it's not a trivial op to implement on the GPU so it could take some time to get this feature into MLX.

@awni awni changed the title [BUG] SVD crashes [Feature] Metal implementation of SVD Sep 3, 2024
@awni awni added the enhancement New feature or request label Sep 3, 2024
@vgoklani
Copy link
Author

vgoklani commented Sep 3, 2024

Thanks!

@ArkAung
Copy link

ArkAung commented Oct 7, 2024

Is anyone working on this? If not, I would like to start working on this. Happy to collaborate with other contributors who would like to collab on the PR.

@awni
Copy link
Member

awni commented Oct 8, 2024

I don't know of anyone working on this. Happy to accept a contribution.

@huangrzh
Copy link

huangrzh commented Dec 4, 2024

Is anyone working on this? If not, I would like to start working on this. Happy to collaborate with other contributors who would like to collab on the PR.

Hi, how is it going with SVD?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants