Model.to(‘cuda:0’) gets stuck - pytorch

I'm using:
python 3.8.10
torch 1.11.0+cu113
And:
NVIDIA-SMI 470.103.01 Driver Version: 470.103.01 CUDA Version: 11.4
Ubuntu 20.04.4 LTS
I can run the following commands via jupyter notebook with not error:
out = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
mX = mX.to(out)
When I try to run those commands from pycharm (with same virtual environment), nothing happens and it gets stuck.
I looked here:
Pytorch .to('cuda') or .cuda() doesn't work and just get stuck
and didn't found any answer.
Why I can use to('cuda') from jupyter notebook and not from pycharm ?
What do I need to do in order to run from pycharm ?

Related

Deeplab v2 in Google Colab: Implementation of Caffe lib fails

Here is the Google Colab notebook dropped on github
As explained in the notebook, my purpose is to to experiment Deeplab v2 with Caffe (not with Tensorflow -With Tensorflow lib, I've managed to run an implementation of Deeplab in Google Colab).
Python does not fetch the link to the lib. As you'll notice in notebook, instruction import caffe throws an error when executed.
I have also tried straight forward install of the package using !apt install caffe-cuda in a different notebook but this does not work and everywhere I read like here, it suggests to build Caffe from source.
OS: Ubuntu 18.04.5 LTS
Python: Python 3.7.12
Cuda: Cuda compilation tools, release 11.1, V11.1.105
openCV: 4.1.2

RuntimeError: CuDNN error: CUDNN_STATUS_SUCCESS

I am running code that UI downloaded from github. It is supposed to be working (I saw that other people managed to activate it). When I try to run it I get the following error message:
RuntimeError: CuDNN error: CUDNN_STATUS_SUCCESS
The code uses pytorch 0.4.1. I have cuda installed.
When I run the command cat /usr/local/cuda/version.txt
I get the answer:
CUDA Version 10.0.130
When I run the command conda list -n <my env name>
I see:
cudatoolkit ver 9.0
cudnn ver 7.6.5
And now, my question:
What should I do to avoid this error?
Do I need to use pip install for a more recent version of cudnn? If so, which one?
I also faced the same issue. In my case, the PyTorch version was 0.4.1, and the Cuda version was 9.0. I solved the issue by adding this piece of code:
torch.backends.cudnn.benchmark = True
try this
if torch.cuda.is_available():
device = torch.device("cuda")
print("working on gpu")
else:
device = torch.device("cpu")
print("working on cpu")

cuda runtime error (3) : initialization error at /pytorch/aten/src/THC/THCGeneral.cpp:51

I start to run TensorFlow application on terminal. At the same time, when I start Pytorch application on another terminal I get error
THCudaCheck FAIL file=/pytorch/aten/src/THC/THCGeneral.cpp line=51 error=3 : initialization error
terminate called after throwing an instance of 'std::runtime_error'
what(): cuda runtime error (3) : initialization error at /pytorch /aten/src/THC/THCGeneral.cpp:51
Both Pytorch TensorFlow and running on different virtualenvs
My Environment
-Ubuntu 18.04
-GPU GeForce GTX 1060
-Pytorch env (torch==1.1.0, torchvision==0.2.0)
-Tensorflow env (tensorflow-gpu==1.15.0)
Pytorch application was running smoothly before starting TensorFlow application
I stop the TensorFlow application and check
>>> torch.cuda.device_count()
0
>>> torch.cuda.is_available()
False
But error not goes back
I had the same problem with pytorch training script crashing, after waking up the Ubuntu from sleep mode. Torch was not able to detect the GPU. It seems that the Cuda driver has a problem restoring the active context after the wakeup.
Rebooting the system fixed the issue.
I was running pytorch in "conda env".

Using TensorFlow through Jupyter (Python 3)

Apologies in advance, I think the issue is quite perplexing!
I would like to use TensorFlow through Jupyter, with a Python3 kernel.
However the command import tensorflow as tf returns the error: ImportError: No module named tensorflow when either Python2 or Python3 is specified as the Jupyter kernel.
I have Python 2 and Python 3 installed on my Mac and can access both
versions through Terminal.
I installed TensorFlow for Python 3, however I can only access it via Python 2 on the Terminal.
As such, this question is really two-fold:
I want to get TensorFlow working with Python3
...which should lead to TensorFlow working with Jupyter on the Python3 terminal.
I had the same problem and solved it using the tutorial Using a virtualenv in an IPython notebook. I'll walk you through the steps I took.
I am using Anaconda, and I installed a new environment tensorflow using these instructions at tensorflow.org. After that, here is how I got tensorflow to work in a Jupyter notebook:
Open Terminal
Run source activate tensorflow. You should now see (tensorflow) at the beginning of the prompt.
Now that we are in the tensorflow environment, we want to install ipython and jupyter in this environment: Run
conda install ipython
and
conda install jupyter
Now follow the instructions in the tutorial linked above. I'll repeat them here with a bit more information added. First run
ipython kernelspec install-self --user
The result for me was Installed kernelspec python3 in /Users/charliebrummitt/Library/Jupyter/kernels/python3
Run the following:
mkdir -p ~/.ipython/kernels
Then run the following with <kernel_name> replaced by a name of your choice (I chose tfkernel) and replace the first path (i.e., ~/.local/share/jupyter/kernels/pythonX) by the path generated in step 4:
mv ~/.local/share/jupyter/kernels/pythonX ~/.ipython/kernels/<kernel_name>
Now you'll see a new kernel if you open a Jupyter notebook and select Kernel -> Change kernel from the menu. But the new kernel will have the same name as your previous kernel (for me it was called Python 3). To give your new kernel a unique name, run in Terminal
cd ~/.ipython/kernels/tfkernel/
and then run vim kernel.json to edit the file kernel.json so that you replace the value of "display_name" from the default (Python 3) to a new name (I chose to call it "tfkernel"). Save and exit vim by typing :wq while in command mode.
Open a new Jupyter notebook and type import tensorflow as tf. If you didn't get ImportError then you are ready to go!

Getting IPython QtConsole and Notebook to work (Canopy installation) Python 3.X

I am using Pyscripter right now but also want to use iPython because it can edit Cython code, which
I want to practice since there is a debugger there.
I recently installed it with Canopy and the black prompt screen works but when I run the notebook it just shows a command prompt and does nothing and when I run the QtConsole (I am guessing it is that white screen with the [In] and [Out] stuff) I get an error (See picture).
Update: Installed QTConsole through Anaconda, QTConsole works but with Python 2.7, no notebook.

Resources