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

CPU and MPS differences for argmax #1074

Closed
ghost opened this issue Jun 23, 2023 · 2 comments · Fixed by #1080
Closed

CPU and MPS differences for argmax #1074

ghost opened this issue Jun 23, 2023 · 2 comments · Fixed by #1080

Comments

@ghost
Copy link

ghost commented Jun 23, 2023

'$argmax' and 'torch_argmax' seem to fail when run on MPS device

Example:

set.seed(100)

a = torch_randn(4, 4)$to(device = "cpu")
a

Output:
torch_tensor
0.3711 1.9380 -0.7856 -1.0108
-0.7952 -0.5836 -0.1242 0.1746
0.9352 0.4852 -1.8873 -0.8021
-1.3524 0.0546 0.6454 0.1427
[ CPUFloatType{4,4} ]

b = torch_randn(4, 4)$to(device = "mps")
b

Output:
torch_tensor
-1.1729 0.5144 1.0309 0.7047
-0.2580 -1.7188 -2.0322 -1.0363
1.4644 -0.7048 1.1910 -0.1933
0.5761 -0.3971 -0.8470 1.5876
[ MPSFloatType{4,4} ]

as.numeric(a$argmax(dim = 2)$to(device = "cpu"))
Output: [1] 2 4 1 3

as.numeric(a$argmax(dim = 2)$to(device = "mps"))
Output: [1] -29077583 50331649 0 0

as.numeric(b$argmax(dim = 2)$to(device = "cpu"))
Output: [1] 3 1 1 4

as.numeric(b$argmax(dim = 2)$to(device = "mps"))
Output: [1] -29077583 50331649 0 0

(On MacOSX Ventura 13.4.1 with R version 4.3.1 (2023-06-16) -- "Beagle Scouts")

@ghost
Copy link
Author

ghost commented Jun 23, 2023

Ok, the issue sits with the conversion function as.numeric(), which can only work on CPU located tensors.

@ghost ghost closed this as completed Jun 23, 2023
@dfalbel
Copy link
Member

dfalbel commented Jun 23, 2023

Thanks for reporting! We should make sure to return an error instead of wrong results

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 a pull request may close this issue.

1 participant