I've been trying to get some torch code working on an M1 Mac Studio (device = "mps"): I had to specify dtype = torch_float32()
to get it to run, but it works (the results are strange but I haven't looked into that yet): however, when I try to call as_array()
I get an error that seems to indicate it's trying to convert the tensors back to regular R types via a torch_float64(): here's a reproducible example:
> x <- torch_tensor(1, device = "mps", dtype = torch_float32())
> x
torch_tensor
1
[ MPSFloatType{1} ]
> as_array(x)
Error in cpp_as_array(x$ptr) :
Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead.
Exception raised from empty_mps at /Users/dfalbel/Documents/actions-runner/mlverse/_work/libtorch-mac-m1/libtorch-mac-m1/pytorch/aten/src/ATen/mps/EmptyTensor.cpp:40 (most recent call first):
frame #0: at::detail::empty_mps(c10::ArrayRef<long long>, c10::optional<c10::ScalarType>, c10::optional<c10::Layout>, c10::optional<c10::Device>, c10::optional<bool>, c10::optional<c10::MemoryFormat>) + 1048 (0x16f464f0c in libtorch_cpu.dylib)
frame #1: at::native::empty_strided_mps(c10::ArrayRef<long long>, c10::ArrayRef<long long>, c10::optional<c10::ScalarType>, c10::optional<c10::Layout>, c10::optional<c10::Device>, c10::optional<bool>) + 140 (0x16f46d278 in libtorch_cpu.dylib)
frame #2: at::_ops::empty_strided::redispatch(c10::DispatchKeySet, c10::ArrayRef<long long>, c10::ArrayRef<long long>, c10::optional<c10::ScalarType>, c10::optional<c10::Layout>, c10::optional<
Is there a workaround? NB: I filed an issue (can't call as_array() on a torch_float32() tensor on "mps" (M1 Mac Studio) GPU · Issue #972 · mlverse/torch · GitHub) but it hasn't been picked up and I guess may not be, so maybe this is a more appropriate forum for seeking help?
thanks!