简体   繁体   中英

Tensorflow with an older GPU version installed

I'm working on a shared machine with GPUs. It used to have only one version of tensorflow working tensorflow-gpu==0.12.0rc1 but recently it also has the most recent non-gpu version as well

tensorflow==1.0.1
tensorflow-gpu==0.12.0rc1

My code does not use the GPU devices anymore. I tried importing the old version only import tensorflow-gpu as tf or requiring tensorflow-gpu to be the old version:

import pkg_resources
pkg_resources.require("tensorflow-gpu==0.12.0rc1")
import tensorflow as tf

but it goes back to only using the CPU devices.

Is there any way to "hide" the newest tensorflow version from my python script or force it to use the gpu version in any way?

I do not have sudo privileges and it is time consuming to go through admin channels.

You can hide it by setting up a virtual environment in your home (no sudo needed). You don't specify your python version, so I'll assume you already have virtualenv installed (it comes with recent versions), otherwise install it (again, no sudo needed - see https://stackoverflow.com/a/5177027/524436 ).

Then, with

# create directory to store environments in
mkdir -p ~/virtualenvs
cd ~/virtualenvs

# create virtual environment for tensorflow
# --no-site-packages hides the global packages like the CPU TF
virtualenv --no-site-packages tensorflow

# activate the virtual environment
source tensorflow/bin/activate

You get a clean environment where you can install packages for python

# install what you want - tensorflow, matplotlib, ...
pip install matplotlib

The "activate" line is only changing the current shell session, so if you open a new shell you need to do source ~/virtualenvs/tensorflow/bin/activate to activate it. There are also wrappers to virtualenv that reduce the amount of typing needed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM