Hello.
There is some weird behavior when calling keras function for the first time in session GPU back-end. First time I called k_constant I got the following error, but then if I just re-run the command, and it went threw through.
library(keras)
> k_constant(9)
2020-02-21 17:42:02.289796: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libnvinfer.so.6
2020-02-21 17:42:02.291236: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libnvinfer_plugin.so.6
Error in py_get_attr_impl(x, name, silent) :
AttributeError: module 'kerastools' has no attribute 'progbar'
>
> k_constant(9)
## GPU info and returned tensor correctly
Same error when connection to GPU established with tf$constant:
> library(keras)
> library(tensorflow)
2020-02-21 17:54:12.384704: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libnvinfer.so.6
2020-02-21 17:54:12.386085: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libnvinfer_plugin.so.6
> tf$constant(2)
## gpu info
tf.Tensor(2.0, shape=(), dtype=float32)
> k_constant(2)
Error in py_get_attr_impl(x, name, silent) :
AttributeError: module 'kerastools' has no attribute 'progbar'
> k_constant(2)
tf.Tensor(2.0, shape=(), dtype=float32)
Session info:
R version 3.6.2 (2019-12-12)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 18.04.4 LTS
Matrix products: default
BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=sl_SI.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=sl_SI.UTF-8 LC_MESSAGES=en_US.UTF-8
[7] LC_PAPER=sl_SI.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=sl_SI.UTF-8 LC_IDENTIFICATION=C
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] tensorflow_2.0.0 keras_2.2.5.0
loaded via a namespace (and not attached):
[1] compiler_3.6.2 magrittr_1.5 R6_2.4.1 generics_0.0.2
[5] whisker_0.4 base64enc_0.1-3 rappdirs_0.3.1 Rcpp_1.0.3
[9] reticulate_1.14 zeallot_0.1.0 jsonlite_1.6.1 tfruns_1.4
Any idea how to fix that first error?
Keras version = 2.3.0
TF version = 2.1.0
R-retiuclate conda list:
# Name Version Build Channel
_libgcc_mutex 0.1 main
_tflow_select 2.1.0 gpu
absl-py 0.9.0 py36_0
asn1crypto 1.3.0 py36_0
astor 0.8.0 py36_0
blas 1.0 mkl
blinker 1.4 py36_0
c-ares 1.15.0 h7b6447c_1001
ca-certificates 2020.1.1 0
cachetools 3.1.1 py_0
certifi 2019.11.28 py36_0
cffi 1.14.0 py36h2e261b9_0
chardet 3.0.4 py36_1003
click 7.0 py36_0
cloudpickle 1.3.0 pypi_0 pypi
cryptography 2.8 py36h1ba5d50_0
cudatoolkit 10.1.243 h6bb024c_0
cudnn 7.6.5 cuda10.1_0
cupti 10.1.168 0
decorator 4.4.1 pypi_0 pypi
gast 0.2.2 py36_0
google-auth 1.11.2 py_0
google-auth-oauthlib 0.4.1 py_2
google-pasta 0.1.8 py_0
grpcio 1.27.2 py36hf8bcb03_0
h5py 2.10.0 py36h7918eee_0
hdf5 1.10.4 hb1b8bf9_0
idna 2.9 pypi_0 pypi
intel-openmp 2020.0 166
keras 2.3.0 pypi_0 pypi
keras-applications 1.0.8 py_0
keras-preprocessing 1.1.0 py_1
ld_impl_linux-64 2.33.1 h53a641e_7
libedit 3.1.20181209 hc058e9b_0
libffi 3.2.1 hd88cf55_4
libgcc-ng 9.1.0 hdf63c60_0
libgfortran-ng 7.3.0 hdf63c60_0
libprotobuf 3.11.4 hd408876_0
libstdcxx-ng 9.1.0 hdf63c60_0
markdown 3.1.1 py36_0
mkl 2020.0 166
mkl-service 2.3.0 py36he904b0f_0
mkl_fft 1.0.15 py36ha843d7b_0
mkl_random 1.1.0 py36hd6b4f25_0
ncurses 6.1 he6710b0_1
numpy 1.18.1 py36h4f9e942_0
numpy-base 1.18.1 py36hde5b4d6_1
oauthlib 3.1.0 py_0
openssl 1.1.1d h7b6447c_4
opt_einsum 3.1.0 py_0
pillow 7.0.0 pypi_0 pypi
pip 20.0.2 py36_1
protobuf 3.11.4 py36he6710b0_0
pyasn1 0.4.8 py_0
pyasn1-modules 0.2.7 py_0
pycparser 2.19 py36_0
pyjwt 1.7.1 py36_0
pyopenssl 19.1.0 py36_0
pysocks 1.7.1 py36_0
python 3.6.10 h0371630_0
pyyaml 5.3 pypi_0 pypi
readline 7.0 h7b6447c_5
requests 2.22.0 py36_1
requests-oauthlib 1.3.0 py_0
rsa 4.0 py_0
scipy 1.4.1 py36h0b6359f_0
setuptools 45.2.0 py36_0
six 1.14.0 py36_0
sqlite 3.31.1 h7b6447c_0
tensorboard 2.1.0 py3_0
tensorflow 2.1.0 gpu_py36h2e5cdaa_0
tensorflow-base 2.1.0 gpu_py36h6c5654b_0
tensorflow-estimator 2.1.0 pyhd54b08b_0
tensorflow-gpu 2.1.0 h0d30ee6_0
tensorflow-hub 0.7.0 pypi_0 pypi
tensorflow-probability 0.9.0 pypi_0 pypi
termcolor 1.1.0 py36_1
tk 8.6.8 hbc83047_0
urllib3 1.25.8 py36_0
werkzeug 1.0.0 py_0
wheel 0.34.2 py36_0
wrapt 1.11.2 py36h7b6447c_0
xz 5.2.4 h14c3975_4
zlib 1.2.11 h7b6447c_3
Best ml
I upgraded TF from 2.0 to 2.1.0 today with conda install (Anaconda). My session info is the same as yours except that I am using Windows 7.
I have the same problem when calling k_constant() and other keras functions (e.g. dataset_cifar10) first time
> library(tensorflow)
> library(keras)
> k_constant(1)
2020-02-21 11:28:31.288439: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library cudart64_101.dll
Error in py_get_attr_impl(x, name, silent) :
AttributeError: module 'kerastools' has no attribute 'progbar'
But this would be fixed if I called it again
> k_constant(1)
2020-02-21 11:28:58.241980: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library nvcuda.dll
....
6 MB memory) -> physical GPU (device: 0, name: GeForce RTX 2070, pci bus id: 0000:01:00.0, compute capability: 7.5)
tf.Tensor(1.0, shape=(), dtype=float32)
It just looks like TensorFlow is not invoked until the second call.
I have another similar problem too. Even after the second call, the keras::to_categorical() does not work anymore.
> cifar10 <- dataset_cifar10()
> y_train <- to_categorical(cifar10$train$y, num_classes = 10)
Error in py_get_attr_impl(x, name, silent) :
AttributeError: module 'tensorflow.python.keras.utils' has no attribute 'to_categorical'
I thus checked
> keras:::keras
Module(tensorflow.python.keras)
> y_train <- tf$keras$utils$to_categorical(cifar10$train$y, num_classes = 10L) #works
It seems that I should replace tensorflow.python.keras with tensorflow.keras. How could one do this?
I can confirm the same probelm with tensorflow 2.10-gpu
I was having trouble with initialising a mutli_gpu_model, in R, you can use a try-catch to avoid the errors, and I had to do it twice to get rid off the 'kerastools' has no attribute 'progbar' error:
try(k_constant(1), silent=TRUE)
try(k_constant(1), silent=TRUE)
And to avoid the AttributeError: module 'tensorflow.python.keras.utils' has no attribute 'multi_gpu_model' error, I had to explicitly specify keras utils without the python parent:
parallel_model <- tf$keras$utils$multi_gpu_model(model, gpus=5L)
I have the same problem on Arch linux. See https://stackoverflow.com/q/60281616/674552
I also tried to install everything within a docker container, but ended up with the same issue.
Here is how to reproduce the bug.
Create a dedicated docker image named deep-learning-r.dockerfile (after downloading the rstudio-server-1.2.5033-amd64.deb file at the same location):
FROM tensorflow/tensorflow:latest-gpu
MAINTAINER "Me"
ENV CRAN_URL https://cloud.r-project.org/
ENV DISTRIB_NAME disco-cran35
ENV DEBIAN_FRONTEND=noninteractive
RUN set -e \
echo "deb ${CRAN_URL}bin/linux/ubuntu ${DISTRIB_NAME}/" \
| tee -a /etc/apt/sources.list \
&& apt-get -y update \
&& apt-get install -y --no-install-recommends --allow-unauthenticated \
r-base \
r-base-dev \
gdebi-core \
&& apt-get -y autoremove \
&& apt-get clean
# I manually downloaded the file and moved the file at the same location than the deep-learning-r.dockerfile file
COPY rstudio-server-1.2.5033-amd64.deb /tmp/rstudio.deb
RUN set -e \
&& gdebi -n /tmp/rstudio.deb \
&& rm -rf /tmp/* \
&& apt-get -y autoremove \
&& apt-get clean
RUN set -e \
&& useradd -m -d /home/rstudio rstudio \
&& echo rstudio:rstudio \
| chpasswd \
&& apt-get -y autoremove \
&& apt-get clean
EXPOSE 8787
CMD ["/usr/lib/rstudio-server/bin/rserver", "--server-daemonize=0", "--server-app-armor-enabled=0"]
To build the image, I used the following command line:
nvidia-docker build --rm -f deep-learning-r.dockerfile --tag rdev:0.1 .
Running the image is done by using the command:
docker run --gpus all -d --rm -p 8787:8787 --name rdev1 --mount type=volume,source=deep-learning-r,target=/home/rstudio rdev:0.1
Then, I open a browser at the address: http://0.0.0.0:8787/ and login with rstudio/rstudio.
I installed keras with tensorflow 2.1.0 for gpu from RStudio server.
Running the following leads to the error:
> library(keras)
> model <- keras_model_sequential()
2020-03-01 14:39:49.938097: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libnvinfer.so.6
2020-03-01 14:39:49.939212: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libnvinfer_plugin.so.6
Error in py_get_attr_impl(x, name, silent) :
AttributeError: module 'kerastools' has no attribute 'progbar'
Calling model <- keras_model_sequential() a second time indeed works...
I can reproduce with the CRAN version, but not with the dev version. Could you try devtools::install_github("rstudio/keras") and see if the error is gone?
With dev verison the issue is gone, great thanks!
@masterlord99 Thanks!
Most helpful comment
I upgraded TF from 2.0 to 2.1.0 today with conda install (Anaconda). My session info is the same as yours except that I am using Windows 7.
I have the same problem when calling
k_constant()and other keras functions (e.g.dataset_cifar10) first timeBut this would be fixed if I called it again
It just looks like TensorFlow is not invoked until the second call.
I have another similar problem too. Even after the second call, the
keras::to_categorical()does not work anymore.I thus checked
It seems that I should replace
tensorflow.python.keraswithtensorflow.keras. How could one do this?