Menu Close

Remotely use server GPU and deep learning development environment with local PyCharm and SSH

Remote data crunching machine

Step1: Setup SSH (if you did not install or use ssh before)

Note: In most cases, your machine should already be able to connect the server with ssh. Thus, this step may be not needed for you.

In order to be able to communicate with your local-machine, you need to install SSH on it. Open up a terminal on your stationary computer and get it:

sudo apt-get install ssh

Enable SSH X11-forwarding so that you can plot things, open the configuration file like this.

sudo vim /etc/ssh/sshd_config
X11Forwarding yes

Step2: Install GPU driver, Cuda, Cudnn (if you did not install)

Step3: Install Anaconda with Keras, Tensorflow, Pytorch on the server (if you did not install)

Set your local computer

Open up your laptop and connect it to the same local network as your stationary machine.

Step 4: PyCharm professional version IDE.https://www.jetbrains.com/pycharm/download/#section=mac

Step 5: Setup PyCharm

setup it by following the PyCharm tutorial of the remote connection to the server, which is shown as below:

PyCharm->Preference->Project: nameofyourproject->Project Interpreter:

This step is to assign what python running environment you would like to use in your server. For my case, I am using anaconda2/envs/py2, which contains python2.7+tensorflow, thus the interpreter is located at anaconda2/envs/py2/bin/python, where py2 represents the name of the conda environment.
This is to set up the server connection.
add the files mapping between local machine and remote server

PyCharm->Preference->Build, Execu….-> Deployment->Console:

It will be better if you can read the debug information always during running programs
You can set up environment variables used in the server if necessary. In my case, I don’t need to add anything but select the python interpreter you just created.

Run->Edit Configuration:

select the python file you want to run on the left panel and set up the local file path along with its remote path on the server and also select the interpreter you want to use.

Testing the setup

Now we should be all done, it’s time to test our setup. First open a terminal and make sure that you have at least one SHH channel connected your server. If you have had a connections open for a while, you may have to exit and restart them:

ssh [remote username here]@[remote Ip here]
you can do this by following in PyCharm:

Console

Then open the “Python Console” in the lower bar in PyCharm and type import tensorflow. if no error, it should tell your work is done well.

Running script

Let’s do some plotting, change your test.py file to this:

import tensorflow
import matplotlib.pyplot as plt
import numpy as np
print "Tensorflow Imported"
plt.plot(np.arange(100))
plt.show()

And then run it with your run configuration “Test”, you should get this plot.

https://medium.com/@erikhallstrm/work-remotely-with-pycharm-tensorflow-and-ssh-c60564be862d