0

I want to run my code run on gpu in windows 10, like for google colab, we can just change the runtime option which is pretty easy to do to shift to gpu. Is there a possibility to do the same for jupyter notebook in windows.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
RShiny_Noob
  • 47
  • 1
  • 6
  • Sounds like you actually meant tensorflow? Not jupyter – OneCricketeer May 13 '21 at 15:01
  • @OneCricketeer Not tensorflow, I wanna use it for PyTorch – RShiny_Noob May 17 '21 at 04:16
  • I see. Regardless, Jupyter is running a Python kernel, so any code you write in it should run the same as on the host itself, so saying "running jupyter on gpu" isn't accurate – OneCricketeer May 17 '21 at 11:39
  • @OneCricketeer Yes it is running a python kernel as you said that's why it takes endless days to create a deep learning model. For the same above reason I wanted jupyter to run on gpu to decrease computing time. – RShiny_Noob May 24 '21 at 06:07
  • Like I said "jupyter" isn't what's running your gpu code, the kernel is, which would be IPython – OneCricketeer May 25 '21 at 11:49
  • @OneCricketeer Okay so is there a way to run IPython on local gpu? – RShiny_Noob May 26 '21 at 15:16
  • The below answer should work. If you're trying to use pytorch, maybe you can share the steps you've tried so far? And what isn't working? – OneCricketeer May 27 '21 at 12:08
  • @OneCricketeer In the below answer, I got stuck at step 7, that import statement is not working. – RShiny_Noob May 29 '21 at 17:55
  • As of tensorflow 2, you wouldn't use `tensorflow-gpu`. https://www.tensorflow.org/install/pip But I thought you wanted pytorch anyway? https://stackoverflow.com/questions/48152674/how-to-check-if-pytorch-is-using-the-gpu – OneCricketeer May 30 '21 at 13:26
  • 1
    You can check the following answer https://stackoverflow.com/questions/51002045/how-to-make-jupyter-notebook-to-run-on-gpu – E.Zolduoarrati Dec 03 '21 at 08:18

2 Answers2

1

You will actually need to use tensorflow-gpu to run your jupyter notebook on a gpu.

The best way to achieve this would be

  1. Install Anaconda on your system

  2. Download cuDNN & Cuda Toolkit 11.3 .

  3. Add cuDNN and Cuda Toolkit to your PATH.

  4. Create an environment in Anaconda

  5. pip install tensorflow-gpu

  6. pip install [jupyter-notebook/jupyterlab]

  7. Import tensorflow-gpu in your notebook

  8. Enjoy. You can now run your notebook on your GPU

Dharman
  • 30,962
  • 25
  • 85
  • 135
Veer Shah
  • 11
  • 1
  • Hey, I have a nvidia 940mx (compute capability - 5.0) on my system so should I download older version of both CuDNN and Cuda Toolkit OR It will work with the latest versions? Thanks. – RShiny_Noob May 17 '21 at 05:44
  • Hi, I'm not able to import tensorflow-gpu, it says syntax error. Although I can use "import tensorflow" but how do I make sure that whether jupyter is using gpu or not. – RShiny_Noob May 24 '21 at 10:05
0

Easy Direct way Create a new environment with TensorFlow-GPU and activate it whenever you want to run your code in GPU

Open Anaconda promote and Write

  1. Conda create --name tf_GPU tensorFlow-gpu

Now it's time to test if our code Run on GPU or CPU

  1. Conda activate tf_GPU --- (Activating the env)

  2. Jupyter notebook ----(Open notebook from the tf_GPU env)

if this Code gives you 1 this means you are runing on GPU

print("Num GPUs Available: ", len(tf.config.list_physical_devices('GPU')))

You can also use this code to make sure you run on GPU

tf.debugging.set_log_device_placement(True)

# Create some tensors
a = tf.constant([[1.0, 2.0, 3.0], [4.0, 5.0, 6.0]])
b = tf.constant([[1.0, 2.0], [3.0, 4.0], [5.0, 6.0]])
c = tf.matmul(a, b)

print(c)

Geting output like this means you using CPU not GPU

Executing op _EagerConst in device /job:localhost/replica:0/task:0/device:CPU:0
Executing op _EagerConst in device /job:localhost/replica:0/task:0/device:CPU:0
Executing op MatMul in device /job:localhost/replica:0/task:0/device:CPU:0
tf.Tensor(
[[22. 28.]
 [49. 64.]], shape=(2, 2), dtype=float32)
Mohamed Fathallah
  • 1,274
  • 1
  • 15
  • 17