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

keras via tensorflow :: 2.13 :: AttributeError: module 'tensorflow.keras' has no attribute '__version__' #1370

Closed
bschulth opened this issue Jul 13, 2023 · 3 comments

Comments

@bschulth
Copy link

bschulth commented Jul 13, 2023

When using newer tensorflow python packages (2.13, probably also 2.12), loading keras package fails with:
AttributeError: module 'tensorflow.keras' has no attribute '__version__'

Granted...the current (https://packagemanager.posit.co/cran/__linux__/jammy/2023-07-12/) version of
R keras is 2.11.1, so this might just be a compatibility issue between
R keras 2.11.1 and Python tensorflow/keras > 2.11.1

From R:

> keras:::keras_version()

2023-07-13 09:30:47.605075: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.
2023-07-13 09:30:47.656239: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.
2023-07-13 09:30:47.656834: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX512F FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-07-13 09:30:48.617657: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
Error in py_get_attr_impl(x, name, silent) :
  AttributeError: module 'tensorflow.keras' has no attribute '__version__'
Run `reticulate::py_last_error()` for details.


> reticulate::py_last_error()

── Python Exception Message ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
AttributeError: module 'tensorflow.keras' has no attribute '__version__'

── R Traceback ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
     ▆
  1. └─keras:::keras_version()
  2.   ├─keras$"__version__" at keras/R/package.R:279:2
  3.   └─reticulate:::`$.python.builtin.module`(keras, "__version__") at keras/R/package.R:279:2
  4.     └─reticulate:::py_resolve_module_proxy(x) at reticulate/R/python.R:296:2
  5.       └─keras (local) on_load() at reticulate/R/python.R:1527:2
  6.         └─keras:::keras_version() at keras/R/package.R:123:6
  7.           ├─keras$"__version__" at keras/R/package.R:279:2
  8.           └─reticulate:::`$.python.builtin.module`(keras, "__version__") at keras/R/package.R:279:2
  9.             └─reticulate:::`$.python.builtin.object`(x, name) at reticulate/R/python.R:299:2
 10.               └─reticulate:::py_get_attr_or_item(x, name, TRUE) at reticulate/R/python.R:407:2
 11.                 └─reticulate::py_get_attr(x, name) at reticulate/R/python.R:375:4
 12.                   └─reticulate:::py_get_attr_impl(x, name, silent) at reticulate/R/python.R:971:2

> packageVersion("keras")

[1] ‘2.11.1> packageVersion("tensorflow")

[1] ‘2.11.0> reticulate::py_version()
[1] ‘3.8> system("pip list | grep -E '(keras|tensorflow)'")

keras                             2.13.1
tensorflow                        2.13.0
tensorflow-cpu                    2.13.0
tensorflow-estimator              2.13.0
tensorflow-io-gcs-filesystem      0.32.0



> getOption("repos")
                                                              CRAN
"https://packagemanager.posit.co/cran/__linux__/jammy/2023-07-12/"



> sessionInfo()

R version 4.2.3 (2023-03-15)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: Ubuntu 22.04.2 LTS

Matrix products: default
BLAS/LAPACK: /opt/intel/compilers_and_libraries_2020.4.304/linux/mkl/lib/intel64_lin/libmkl_gf_lp64.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
 [9] LC_ADDRESS=C               LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

other attached packages:
[1] keras_2.11.1    testthat_3.1.10

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.11       lattice_0.21-8    png_0.1-8         zeallot_0.1.0
 [5] rprojroot_2.0.3   brio_1.1.3        grid_4.2.3        R6_2.5.1
 [9] jsonlite_1.8.7    magrittr_2.0.3    tfruns_1.5.1      rlang_1.1.1
[13] cli_3.6.1         whisker_0.4.1     Matrix_1.6-0      reticulate_1.30
[17] generics_0.1.3    desc_1.4.2        pkgload_1.3.2.1   parallel_4.2.3
[21] compiler_4.2.3    base64enc_0.1-3   tensorflow_2.11.0

From Python:

# python
Python 3.8.3 (default, Jul 12 2023, 18:47:07)
[GCC 11.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.

>>> import tensorflow

2023-07-13 09:48:54.072448: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.
2023-07-13 09:48:54.119979: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.
2023-07-13 09:48:54.120575: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX512F FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-07-13 09:48:55.179887: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT

>>> tensorflow.__version__

'2.13.0'

>>> tensorflow.keras

<module 'keras.api._v2.keras' from '/opt/cfdads/python/3.8.3/lib/python3.8/site-packages/keras/api/_v2/keras/__init__.py'>

>>> tensorflow.keras.__version__

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/cfdads/python/3.8.3/lib/python3.8/site-packages/tensorflow/python/util/lazy_loader.py", line 59, in __getattr__
    return getattr(module, item)
AttributeError: module 'keras.api._v2.keras' has no attribute '__version__'


>>> import keras
>>> keras

<module 'keras' from '/opt/cfdads/python/3.8.3/lib/python3.8/site-packages/keras/__init__.py'>

>>> keras.__version__

'2.13.1'
@bschulth
Copy link
Author

bschulth commented Jul 13, 2023

Just an update, I can confirm that downgrading my python install of tensorflow/keras to 2.11.1 resolves the issue.
So maybe this is just an FYI for next release of R keras to support 2.12+ python versions.

From R:

> keras:::keras_version()
2023-07-13 10:18:56.477483: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations:  AVX2 AVX512F FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
[1] ‘2.11.0> system("pip list | grep -E '(keras|tensorflow)'")

keras                             2.11.0
tensorflow                        2.11.1
tensorflow-cpu                    2.11.1
tensorflow-estimator              2.11.0
tensorflow-io-gcs-filesystem      0.32.0


> packageVersion("keras")

[1] ‘2.11.1> packageVersion("tensorflow")

[1] ‘2.11.0

@t-kalinowski
Copy link
Member

Can you please try with the development version of the R package?

remotes::install_github("rstudio/keras")

@bschulth
Copy link
Author

Perfect! Thanks!
I can confirm the development version works with 2.13.0

> keras:::keras_version()
2023-07-13 12:08:01.417687: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.
2023-07-13 12:08:01.493816: I tensorflow/tsl/cuda/cudart_stub.cc:28] Could not find cuda drivers on your machine, GPU will not be used.
2023-07-13 12:08:01.495103: I tensorflow/core/platform/cpu_feature_guard.cc:182] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 AVX512F FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-07-13 12:08:02.784507: W tensorflow/compiler/tf2tensorrt/utils/py_utils.cc:38] TF-TRT Warning: Could not find TensorRT
[1] ‘2.13.0> system("pip list | grep -E '(keras|tensorflow)'")
keras                             2.13.1
tensorflow                        2.13.0
tensorflow-cpu                    2.13.0
tensorflow-estimator              2.13.0
tensorflow-io-gcs-filesystem      0.32.0

> packageVersion("keras")

[1] ‘2.11.1.9000> packageVersion("reticulate")

[1] ‘1.30.9000

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

No branches or pull requests

2 participants