FS#71919 - [python-tensorflow] Needs standalone keras package in some cases
Attached to Project:
Community Packages
Opened by Chih-Hsuan Yen (yan12125) - Wednesday, 25 August 2021, 09:39 GMT
Last edited by Konstantin Gizdov (kgizdov) - Monday, 30 August 2021, 10:48 GMT
Opened by Chih-Hsuan Yen (yan12125) - Wednesday, 25 August 2021, 09:39 GMT
Last edited by Konstantin Gizdov (kgizdov) - Monday, 30 August 2021, 10:48 GMT
|
Details
Description:
For Tensorflow 2.6, somehow the keras package is needed in some cases: $ python -c 'from tensorflow.compat.v1.nn.rnn_cell import BasicLSTMCell' WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation. WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation. WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation. WARNING:root:Limited tf.summary API due to missing TensorBoard installation. WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation. WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation. WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation. $ python -c 'import tensorflow; tensorflow.compat.v1.nn.rnn_cell.BasicLSTMCell' WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation. WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation. WARNING:root:Limited tf.compat.v2.summary API due to missing TensorBoard installation. WARNING:root:Limited tf.summary API due to missing TensorBoard installation. Traceback (most recent call last): File "<string>", line 1, in <module> File "/usr/lib/python3.9/site-packages/tensorflow/python/util/lazy_loader.py", line 62, in __getattr__ module = self._load() File "/usr/lib/python3.9/site-packages/tensorflow/python/util/lazy_loader.py", line 45, in _load module = importlib.import_module(self.__name__) File "/usr/lib/python3.9/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 1030, in _gcd_import File "<frozen importlib._bootstrap>", line 1007, in _find_and_load File "<frozen importlib._bootstrap>", line 984, in _find_and_load_unlocked ModuleNotFoundError: No module named 'keras' The second way appears in tests of my AUR package python-tf2onnx: https://github.com/onnx/tensorflow-onnx/blob/v1.9.2/tests/test_seq2seq.py#L16. I suspect it is not a common practice, but still a valid way. If I create a package python-keras 2.6.0, both ways work. I attached a proof-of-concept PKGBUILD based on the (out-dated) AUR package python-keras. It requires some cleanups, though (dependencies, ...) Additional info: python-tensorflow 2.6.0-2 Steps to reproduce: 1. Upgrade python-tensorflow to 2.6.0-2 2. Make sure keras is not installed (ex: `pip show keras` reports a warning) 3. Try to import RNN cells as described above |
This task depends upon
Closed by Konstantin Gizdov (kgizdov)
Monday, 30 August 2021, 10:48 GMT
Reason for closing: Fixed
Additional comments about closing: tensorflow 2.6.0-3
Monday, 30 August 2021, 10:48 GMT
Reason for closing: Fixed
Additional comments about closing: tensorflow 2.6.0-3
PKGBUILD
```
$ python -c 'from tensorflow.compat.v1.nn.rnn_cell import BasicLSTMCell; a = BasicLSTMCell; print(a)'
<class 'tensorflow.python.keras.layers.legacy_rnn.rnn_cell_impl.BasicLSTMCell'>
$ ls /usr/lib/python3.9/site-packages/tensorflow/python/keras/layers/legacy_rnn/rnn_cell_impl.py
/usr/lib/python3.9/site-packages/tensorflow/python/keras/layers/legacy_rnn/rnn_cell_impl.py
```
The module is installed correctly and available. What I think is happening is that the `lazy_loader.py` is failing when it does not get full module paths starting at package root. This could be a bug in the way LazyLoader is called or implemented, or it could be an incorrect usage to call it this way. If it succeeds when Keras is installed separately, that means LazyLoader just fails to recognise where the module should be located when called the second way and then looks inside the normal python package path rather than inside TensorFlow.
In any case, I do not see a reason to ship Keras as a separate package. Could we open a bug on both upstreams and let them give more background?
Hmm, I saw something different. From release notes of Tensorflow 2.6, (https://github.com/tensorflow/tensorflow/releases/tag/v2.6.0)
> Keras been split into a separate PIP package (keras), and its code has been moved to the GitHub repository keras-team/keras. The API endpoints for tf.keras stay unchanged, but are now backed by the keras PIP package. The existing code in tensorflow/python/keras is a staled copy and will be removed in future release (2.7).
Mind to share a link for deprecation of Keras? Then I can ask for clarification from upstream devs.
> The module is installed correctly and available.
Yep that is indeed strange. I think your reasoning is likely.
By the way, I noticed tensorflow 2.6 already declares keras as a dependency:
$ grep keras /usr/lib/python3.9/site-packages/tensorflow-2.6.0.dist-info/METADATA
Requires-Dist: keras-preprocessing
Requires-Dist: keras
However, I think calling tensorflow.compat is also not supported anymore (refer to TF 2.6.0 release notes).
> However, I think calling tensorflow.compat is also not supported anymore (refer to TF 2.6.0 release notes).
Looks like some classes under tf.compat are deprecated, not the whole tf.compat namespace. Anyway, this is the issue for my AUR package tensorflow-onnx :)