Hi,
We are working on servers with no GPU. Hence, our users use the CPU version of tensorflow.
What we did to install is
library(tensorflow)
install_tensorflow(envname="r-tensorflow",
version = "cpu",
python = "/applis/Python/3.6.10/bin/python3",
ignore_installed = FALSE)
Everything is fine and we get tensorflow-cpu installed.
Collecting tensorflow-cpu==2.2.0
But when trying to test the installation with the keras tutorial
library(keras)
# load data (we are on offline servers so they are cached)
c(c(x_train, y_train), c(x_test, y_test)) %<-% dataset_mnist(path = "/home/share/echange/data/mnist.npz")
keras will reinstall tensorflow
Using virtual environment '/home/bureau.si.interne/dervieuxchr/.virtualenvs/r-tensorflow' ...
Looking in indexes: https://devin-depot.rte-france.com/repository/pypi-all/simple
Collecting tensorflow
Looking with pip list in the virtualenv I have both
tensorflow 2.2.0
tensorflow-cpu 2.2.0
This will cause tensorflow to be used, and I have what I think to be GPU related errors.
With tensorflow-cpu only, everything is working fine.
note that this happens only the first time I use
c(c(x_train, y_train), c(x_test, y_test)) %<-% dataset_mnist(path = "/home/share/echange/data/mnist.npz")
in a R session.
I don't really know what happens 🤔 Is there a check somewhere for tensorflow when fist executing a Keras function ?
In fact it will happen with any first keras function I use... There seems to be a check when keras is first loaded, and this check will not look for the tensorflow-cpu version and so will reinstall it using the default tensorflow version. Am I right ?
(I tried to skip the data_mnist step by loading the variables from a RData, but I got the same situation using
x_train <- array_reshape(x_train, c(nrow(x_train), 784))
executing this line the first time will install tensorflow even if I have tensorflow-cpu in the same version in my virtualenv.
Is this intended ?
This behavior is a bug.
What happens is the: https://rstudio.github.io/reticulate/reference/configure_environment.html
and in the meantime you can disable it by setiing the RETICULATE_AUTOCONFIGURE env var to FALSE
Thanks for the workaround, I did not know that.
However, when I set this variable, I got this error
library(keras)
Erreur : package or namespace load failed for ‘keras’: .onLoad a échoué dans loadNamespace() pour 'tensorflow', détails : appel : py_module_import(module, convert = convert) erreur : ModuleNotFoundError: No module named 'tensorflow'
I correctly have tensorflow-cpu in my environment (from what I see from pip list)
What happens if you import tensorflow directly from python ins this environment?
Many times this message is misleading and the problem is that there was an error loading tensorflow.
I get an error
>>> import tensorflow
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'tensorflow'
let me try to reinstall tensorflow-cpu in a clean virtualenv 🤔
Ok my bad. The virtualenvironment was corrupted by the automatic installation then the removal.
I redid an installation of tensorflow-cpu and with the env var set to FALSE, I don't have the automatic installation behavior.
Thanks, this workaround will help while waiting for a fix on CRAN for this bug.
Glad it worked! Yes, will work on a fix for this!
Tracking here now: https://github.com/rstudio/reticulate/issues/791