skip to Main Content

I bought a new laptop and installed VS Code and Tensorflow on Windows. The TF Python script needs a conda virtual environment that can access Nvidia GPU card. I got the virtual environment working fine. I also got the TF Python scripts working in VS Code. However, when I use the same scripts in Jupyter notebook in VS Code, it cannot find the GPU. Both run the same virtual environment. The first screenshot shows it works in .py in VS Code:

enter image description here

Strangely, the same scripts in Jupyter notebook form cannot find the GPU. Please help.

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    It looks like a bug in VS Code. I was about to give up running TF on Windows with VS Code, and so installed Docker desktop app. Then it started to work. In other words, after I installed Docker desktop on the Windows, the VS Code and Jupyter notebook are able to use GPU.

    Thanks everyone who helped.


  2. One of these should either fix it or send you in the right direction.

    1. Set the CUDA_VISIBLE_DEVICES environment variable

      import os
      os.environ["CUDA_VISIBLE_DEVICES"] = "0"
      import tensorflow as tf
      # More tensorflow code here
      
    2. Manually set the GPU device with…

      with tf.device('/device:GPU:0'):
          # Your TensorFlow code here
      
    3. Make sure the Jupyter Notebook is using the same kernel as the command-line with !which python or !where python or !conda env list If it’s what you said in your question, you’re probably okay.

    4. Look at which version of TensorFlow you’ve got installed. If it’s pre-2.1, you’ll need tensorflow-gpu and not tensorflow. Again, you’re probably okay here, too.

    5. Many problems are fixed by manually restarting the Jupyter kernel.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search