Keras tensorflow package version mismatch and pipenv gpu problem


I am trying to use tensorflow with GPU acceleration on Manjaro 23.0.3 with KDE.
Unfortunately I ran into the following problem:
The python-tensorflow-* version is: 2.13.0-1
The python-keras version is: 2.12.0-2
But tensorflow 2.13 apparently requires keras 2.13 or throws exactly this error.

When I create a pipenv enviroment and install tf 2.12 and keras 2.12 or 2.13 and 2.13 my code works, but for some reason my gpu is then not recognized.

So my questions are:

  • can I somehow install keras 2.13?
  • or can I get my pipenv somehow to recognize my gpu?

thx in advance!

python-tensorflow-* packages have been been flagged out-of-date since September 30. You’ll either have to wait for the maintainer to update the packages or do it yourself (which will be difficult given the amount of dependencies).

Maybe, if we knew what your gpu was.

If you installed CUDA from the repositories, you’ll likely to have version 12.x installed. The tensorflow packages are compiled against 11.8, so it does not work.

However, newer versions might work because they now bring their own runtime.

Inside your virtualenv, you can use pip install tensorflow[and-cuda] and test if it works. (This is for tf 2.14, not 2.13)

Alrighty! Thx for the tip with the package! I just build a python-keras 2.13.1 package and at least this works now :slight_smile:

Here’s the code for other unfortunate souls encountering the same problem. Just paste the following code (original code here) into a PKGBUILD file, then run makepkg, followed by
sudo pacman -U python-keras-2.13.1-2-any.pkg.tar.zst

# Maintainer: Konstantin Gizdov <arch at kge dot pw>

pkgdesc='A deep learning API written in Python, running on top of the machine learning platform TensorFlow'
makedepends=('python-build' 'python-installer' 'python-wheel')
depends=('absl-py' 'python' 'python-h5py' 'python-keras-preprocessing' 'python-numpy' 'python-pandas' 'python-pillow'
         'python-pydot' 'python-scipy' 'python-six' 'python-tensorflow' 'python-yaml' 'tensorboard')

package () {
  python -m installer --destdir="$pkgdir" *.whl
  install -Dm 644 "${_pkgbase}-${pkgver}-LICENSE" "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE"

But the problem with the virtual envs not recognizing my gpu still persists. So any help here would be very much appreciated.

My pleasure :slight_smile:

$ nvidia-smi   
Tue Oct 10 20:30:37 2023       
| NVIDIA-SMI 535.113.01             Driver Version: 535.113.01   CUDA Version: 12.2     |
| GPU  Name                 Persistence-M | Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |         Memory-Usage | GPU-Util  Compute M. |
|                                         |                      |               MIG M. |
|   0  NVIDIA TITAN Xp                Off | 00000000:02:00.0  On |                  N/A |
| 23%   25C    P8              14W / 250W |    597MiB / 12288MiB |      0%      Default |
|                                         |                      |                  N/A |
| Processes:                                                                            |
|  GPU   GI   CI        PID   Type   Process name                            GPU Memory |
|        ID   ID                                                             Usage      |
|    0   N/A  N/A       670      G   /usr/lib/Xorg                               270MiB |
|    0   N/A  N/A       753      G   /usr/bin/kwalletd5                            3MiB |
|    0   N/A  N/A       826      G   /usr/bin/ksmserver                            3MiB |
|    0   N/A  N/A       828      G   /usr/bin/kded5                                3MiB |
|    0   N/A  N/A       829      G   /usr/bin/kwin_x11                            35MiB |
|    0   N/A  N/A       866      G   /usr/bin/plasmashell                         46MiB |
|    0   N/A  N/A       898      G   ...b/polkit-kde-authentication-agent-1        3MiB |
|    0   N/A  N/A       900      G   /usr/lib/xdg-desktop-portal-kde               3MiB |
|    0   N/A  N/A      1009      G   /usr/bin/msm_kde_notifier                     3MiB |
|    0   N/A  N/A      1011      G   /usr/lib/kdeconnectd                          3MiB |
|    0   N/A  N/A      1031      G   /usr/bin/kaccess                              3MiB |
|    0   N/A  N/A      1034      G   /usr/bin/pamac-tray-plasma                    3MiB |
|    0   N/A  N/A      1404      G   /usr/lib/baloorunner                          3MiB |
|    0   N/A  N/A      1409      G   /usr/bin/systemsettings                      18MiB |
|    0   N/A  N/A      1525      G   /usr/lib/firefox/firefox                    176MiB |
|    0   N/A  N/A      1963      G   /usr/bin/dolphin                              3MiB |

I tried this already, but unfortunately without success:

[~/dev/projects/test_tf_214]$ pipenv shell
Launching subshell in virtual environment...
 . /home/wurstkopf/.local/share/virtualenvs/test_tf_214-DyH0khk9/bin/activate
[~/dev/projects/test_tf_214]$  . /home/wurstkopf/.local/share/virtualenvs/test_tf_214-DyH0khk9/bin/activate
(test_tf_214) [~/dev/projects/test_tf_214]$ python
Python 3.11.5 (main, Oct 10 2023, 05:03:41) [GCC 13.2.1 20230801] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2023-10-10 20:39:05.333342: I tensorflow/tsl/cuda/] Could not find cuda drivers on your machine, GPU will not be used.
2023-10-10 20:39:05.365187: E tensorflow/compiler/xla/stream_executor/cuda/] Unable to register cuDNN factory: Attempting to register factory for plugin cuDNN when one has already been registered
2023-10-10 20:39:05.365218: E tensorflow/compiler/xla/stream_executor/cuda/] Unable to register cuFFT factory: Attempting to register factory for plugin cuFFT when one has already been registered
2023-10-10 20:39:05.365250: E tensorflow/compiler/xla/stream_executor/cuda/] Unable to register cuBLAS factory: Attempting to register factory for plugin cuBLAS when one has already been registered
2023-10-10 20:39:05.371660: I tensorflow/tsl/cuda/] Could not find cuda drivers on your machine, GPU will not be used.
2023-10-10 20:39:05.371865: I tensorflow/core/platform/] This TensorFlow binary is optimized to use available CPU instructions in performance-critical operations.
To enable the following instructions: AVX2 FMA, in other operations, rebuild TensorFlow with the appropriate compiler flags.
2023-10-10 20:39:06.326297: W tensorflow/compiler/tf2tensorrt/utils/] TF-TRT Warning: Could not find TensorRT
>>> print (tf.__version__)

Did I miss anything, or?

Did you install tensorflow[and-cuda] with pip?

If you’re using pipenv, you don’t need to install keras globally.
Also, you don’t need the keras package, if you install tf. It’s already included.

Yes - I ran pipenv shell and then installed tf via pip install tensorflow.

I would also prefer to use py-/pipenv over globally installed packages. At least I can run stuff for now with gpu, but it would be cool to get this also working with pipenv. Any idea what to check or do next?

I think the error mentioned in the first post occurred already when I only had a tf package installed. I am not sure rn. I can test it tomorrow.

To be sure, you have to run pip install "tensorflow[and-cuda]". The extra package is important.

1 Like

Alright! I got it working!

The problem was (or is) that the cuda package is version 12.2 and pip install tensorflow[and-cuda] installs tensorflow 2.13.1 but with specifying the version for 2.14.0 at least the GPU is recognized. Unfortunately cudnn, cublas and cufft from 12.2 aren’t supported in 2.14.0. But yeah so far so good :slight_smile:

Innocent question: As I am fairly new to arch (as you might can tell), I am wondering, if in general it would make sense to update driver packages at the point in time when they can actually be used? Or am I not seeing something here?

Thanks for the help! :slight_smile:

ps. headsup tf 2.14 only runs on python 3.10 as the required tensorrt package is not yet available for python 3.11

According to NVIDIA, TensorRT is not available for CUDA 12.2.

Python 3.11 is perfectly supported. Tensorrt is not needed to run Tensorflow.

Tensorrt is a requirement for tensorflow 2.14.0 and it’s not ready for python 3.11
As described here. I ran into the same problem.

And, yeah, basically nothing is available for cuda 12.2 - that’s why I asked if it wouldn’t make more sense to wait until it’s actually usable before updating the arch package.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.