Closed jonbry closed 3 months ago
I think this is an issue specific to the tensorflow-macos
package for M1 mac. Fortunately, with TensorFlow release 2.16, we no longer have to use the tensorflow-macos
package.
The R package function tensorflow::install_tensorflow()
has not been updated yet to install 2.16, but you can install the latest release (2.16.1 today) manually:
reticulate::virtualenv_create(
"r-tensorflow", force = TRUE, python = ">=3.9,<=3.11",
packages = c("tensorflow", "tensorflow-metal")
)
~Then this succeeds without error:~
library(tensorflow)
## -------------------------------------------------------------------------
v <- tf$Variable(initial_value = tf$random$normal(shape(3, 1)))
v
## -------------------------------------------------------------------------
v$assign(tf$ones(shape(3, 1)))
## -------------------------------------------------------------------------
v[1, 1]$assign(3)
Actually, I spoke too soon. I still reproduce the error on the latest version if the Mac GPU is initialized and available to the TensorFlow session.
The issue is fundementally that the tensorflow-metal
package doesn't implement a required Op for the GPU: ResourceStridedSliceAssign
.
We'll have to wait until tensorflow-metal
is updated (the latest today is 1.1.0): https://pypi.org/project/tensorflow-metal/
In the interim, you can disable the GPU or install a CPU-only version of tensorflow on M1 macs to avoid this issue:
Disable the GPU:
library(tensorflow)
tf$config$list_physical_devices("CPU") |> tf$config$set_visible_devices()
Install a CPU only version:
reticulate::virtualenv_create(
"r-tensorflow", force = TRUE, python = ">=3.9,<=3.11",
packages = c("tensorflow") # don't install "tensorflow-metal"
)
Ok, I'll switch over to the CPU. Thanks for your help!
I am working through an example from Deep Learning with R and I get a colocation error when I try to assign a value to a subset of a TensorFlow variable (which I believe is of
dtype = float32
):I'm using an M1 Mac and I saw on the TensorFlow website for R that I may be able to resolve the issue by running on the CPU using
with(tf$device("CPU"), ...)
, but I am getting the same error.Is there any way to fix or get around this issue? I am using TensorFlow 2.15, Python 3.10.4, and R 4.3.2 if that is helpful. Let me know if there is any additional information I can provide to help troubleshot the issue.
Thank you!