5

I know this is one of the popular questions, but none of the solutions worked for me, so far.

I'm running a legacy code that is written in tensorflow v1.13.1 and keras v2.2.4. I cannot modify the code to run latest tensorflow version. Since keras has now been merged into tensorflow, I'm facing problems installing the specific versions of tensorflow and keras via pip. I found that anaconda has option to install keras and tensorflow with the above version. So, I installed it with

conda install -c conda-forge keras-gpu=2.2.4 tensorflow-gpu=1.13.1 

It installed the version and all works too. But it doesn't use GPU, and instead runs on CPU. I noticed that anaconda installed both CPU and GPU versions of tensorflow and I guess this is why it is defaulting to CPU version. So, my question is, how can I force it to use GPU version?

PS: There are many answers out there that suggest to remove CPU version of tensorflow. But when I try to remove CPU version, conda uninstalls everything including keras. So, I assume there should be a way to use tensorflow-gpu when both of them are installed. Any help in this regard is appreciated!

4
  • Do you get errors like xxx library could not be loaded when the program runs? Commented Oct 8, 2021 at 7:18
  • Yes, I do. I tried searching for those errors in SO and none of the solutions worked. Cuda 10.0 is already installed in the machine. Setting LD_LIBRARY_PATH also didn't help Commented Oct 8, 2021 at 7:27
  • Can you tell us what the error is exactly? Commented Oct 8, 2021 at 7:38
  • Please post all errors, without them we cannot really help you. Commented Oct 8, 2021 at 8:46

2 Answers 2

2

Let me start off with the assumption you're using an NVIDIA GPU. It's most likely due to you either not having CUDA installed or having the wrong version. Although, do double check to make sure you also have the latest NVIDIA drivers. If you look at this list you can see that tensorflow_gpu-1.13.1 uses CUDA version 10.0 and CudNN 7.4. To install those through anaconda use the following command.

conda install cudatoolkit==10.0.130 

As for cudnn 7.4 check out the archive

Sign up to request clarification or add additional context in comments.

2 Comments

I installed cudatoolkit (10.0.130) and cudnn (7.6.5.32) in the conda environment. Won't that be sufficient? Do I have to separately download cudnn from NVIDIA website? Anyway, after installing the two in conda environment also, GPU is not detected.
@NagabhushanSN normally tf is very picky about versions (to the minor release) so let's just say if you have cuda 10.1.XXX installed then that version of tf won't work because it needs 10.0.XXX. I think the same goes for cudnn but I'm not sure. I'm glad you figured it out!
0

Installing tensorflow first and then keras worked!

conda install tensorflow-gpu=1.13.1 conda install keras-gpu=2.2.4 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.