44

Recently, I wanted to move my Python libraries to a pendrive to keep all the libraries constant while switching between my workstation and laptop. (Also so that if I update one, it's updated on other also.)

For this, I have installed a tensorflow-gpu version on my pendrive (my laptop doesn't have a GPU). Everything works fine without a problem on both PC (it detects and uses my GPU without a problem) and laptop (it automatically uses my CPU).

That's where my question lies. What is the difference between a

tensorflow-gpu 

AND just

tensorflow

? (Because when no GPU is found, tensorflow-gpu automatically uses the CPU version.)

Does the difference lie only in the GPU support? Then why at all have a non GPU version of tensorflow?

Also, is it alright to proceed like this? Or should I create virtual environments to keep separate installations for CPU and GPU?

The closest answer I can find is How to develop for tensor flow with gpu without a gpu.

But it only specifies that it's completely okay to use tensorflow-gpu on a CPU platform, but it still does not answer my first question. Also, the answer might be outdated as tensorflow keeps releasing new updates.

I had installed the tensorflow-gpu version on my workstation with GTX 1070 (Thus a successful install).

Also I understand the difference is that pip install tensorflow-gpu will require CUDA enabled device to install, but my question is more towards the usage of the libraries because I am not getting any problems when using the tensorflow-gpu version on my laptop (with no GPU) and all my scripts run without any error.

(Also removed pip install from above to avoid confusion)

Also, isn't running tensorflow-gpu on a system with no GPU the same as setting CUDA_VISIBLE_DEVICES=-1?

Null
  • 1,950
  • 9
  • 30
  • 33
Rohan Pooniwala
  • 475
  • 1
  • 5
  • 10
  • 2
    `tensorflow-gpu` depends on CUDA, and (at least until recent versions, and I believe it has not changed) trying to import it without CUDA installed (the right version of CUDA and CUDNN, that is) will fail. `tensorflow-cpu` will always work after it is installed correctly. – jdehesa Oct 03 '18 at 10:22
  • 1
    Importing tensorflow-gpu with out CUDA results in no error and works like a charm. I just checked it again right now to be sure. Edit: I also checked the tensorflow version and it is tensorflow-gpu and not the cpu version. – Rohan Pooniwala Oct 03 '18 at 10:25
  • How did you install `tensorflow-gpu`? If you got [this distribution](https://anaconda.org/anaconda/tensorflow-gpu) (e.g. with `conda install -c anaconda tensorflow-gpu`), I think it bundles CUDA/CUDNN in the environment for you (that is not something standard `pip` would be able to do, I think... and still, it makes it significantly bigger and slower to load). – jdehesa Oct 03 '18 at 10:32
  • I installed it on my workstation (thus successful installation) and then used it on my laptop. I will mention it in the question also for clarification. – Rohan Pooniwala Oct 03 '18 at 10:35

3 Answers3

33

One thing to Note: CUDA can be installed even if you don't have a GPU in your system.

For packages tensorflow and tensorflow-gpu I hope this clears the confusion. yes/no means "Will the package work out of the box when executing import tensorflow as tf"? Here are the differences:

| Support for TensorFlow libraries | tensorflow | tensorflow-gpu  |
| for hardware type:               |    tf      |     tf-gpu      |
|----------------------------------|------------|-----------------|
| cpu-only                         |    yes     |   no (~tf-like) |
| gpu with cuda+cudnn installed    |    yes     |   yes           |
| gpu without cuda+cudnn installed |    yes     |   no (~tf-like) |

Edit: Confirmed the no answers on a cpu-only system and the gpu without cuda+cudnn installed (by removing CUDA+CuDNN env variables).

~tf-like means even though the library is tensorflow-gpu, it would behave like tensorflow library.

burglarhobbit
  • 1,860
  • 2
  • 17
  • 32
  • Can I get a source for this? Coz my situation seems to contradict the information as I can run `tensorflow-gpu` on a system with cpu (with no gpu) – Rohan Pooniwala Oct 03 '18 at 12:55
  • What's the `tensorflow-gpu` version you're testing this on? I tested `tensorflow-gpu` on 1.4.0 and the latest one, both on a `cpu-only`. None of them worked, as expected. – burglarhobbit Oct 03 '18 at 14:08
  • @RohanPooniwala Please do a pip/pip3 freeze and grep tensorflow. I think you must have a version conflict with multiple installs. – burglarhobbit Oct 03 '18 at 17:14
  • Sorry for late reply, had been busy with some stuff.. Also it turned out my environment had CUDA installed in it (some how, I have no idea why) and that's why it was working on my laptop without the GPU... Also `pip freeze | grep tensorflow` gives `tensorflow-gpu==1.11.0` – Rohan Pooniwala Oct 05 '18 at 12:55
  • 1
    @RohanPooniwala So this corroborates with my answer. GPU with cuda+cudnn installed. All it would do is skip the gpu if not found and resume it on cpu. Try running the "nvidia-smi" command and check gpu properties of your laptop. Just in case. – burglarhobbit Oct 05 '18 at 15:49
  • 1
    Yes, GPU with CUDA+cudnn installed without an actual GPU in the system works.. It would be great if you can update your answer and mention it! – Rohan Pooniwala Oct 06 '18 at 16:15
  • @RohanPooniwala Done! – burglarhobbit Oct 07 '18 at 14:09
19

Just a quick (unnecessary?) note... from TensorFlow2.0 onwards these are not separated, and you simply install tensorflow (as this includes GPU support if you have an appropriate card/CUDA installed).

Oz_Ben
  • 229
  • 2
  • 8
  • 3
    @Ironkey The only reason that I thought it worth an answer is that the OP's question most probably a bit dated in that there is now no longer any difference on the install (as there's now only one version on the current stream). I appreciate that it's been two years, but there's a lot of references online to TensorFlow-GPU – Oz_Ben Oct 06 '20 at 23:40
  • It's from tensorflow==1.15.0 and onwards, except for tensorflow==2.0.0. tensorflow==2.0.0 does not support GPU. tensorflow==1.15.0 does. – Valentyn Jun 22 '21 at 19:55
4

tensorflow-gpu requires cuda/cudnn. tensorflow does not. pip doesn't install cuda for you (conda does), so pip install tensorflow-gpu won't work out of the box on most systems without a nvidia gpu.

user2653663
  • 2,818
  • 1
  • 18
  • 22
  • Yes I totally agree with you, But again, pip install tensorflow-gpu was run on system with CUDA enable device (My workstation with GTX1070). And then importing tensorflow was success and all my scripts ran on a system with no CUDA device (My laptop with no GPU) without a problem. – Rohan Pooniwala Oct 03 '18 at 10:30
  • 1
    @RohanPooniwala I just installed tensorflow-gpu via pip and got an error when I imported tensorflow. Do you happen to have anaconda with cuda hidden somewhere? – user2653663 Oct 03 '18 at 10:30
  • So like i mentioned in my previous comment, i installed it on my workstation (thus successful installation) and then used it on my laptop. – Rohan Pooniwala Oct 03 '18 at 10:33
  • Sorry i misread your previous comment. I installed everything when i was on my workstation. The Anaconda also resides on the pendrive, but the CUDA installation was done only on the workstation and tensorflow-gpu was installed using `pip` and not `conda`. – Rohan Pooniwala Oct 03 '18 at 10:52