Convenient PyTorch and Tensorflow development on AIME GPU Servers

Development on a local machine is straight forward but how to use to the power of an AIME GPU server conveniently?

To be able to run your code with the full performance of the AIME GPU Servers, you first need to get the code and data to the storage of the remote machine. The most basic way to achieve this, is to copy your finished code and data to the remote machine.

While this works for single files, it might become inconvenient for projects containing multiple files and folders. To avoid copying files it is more convenient to remotely edit your code right on the machine. As our proposed solution this article describes the setup of a remote connection with the IDE Microsoft Visual Studio  Code on Linux, Windows 10 or macOS to edit code via SSH.

The classic way: How to copy files and data to your AIME GPU Server

To copy files from your local machine to a server via SSH you usually use secure copy by executing the following command:

scp -p <port> <source_file> <user_name>@<gateway>:<target_file>

The <port>, the <gateway> and the <user_name> you get from AIME via Email. Once done, you can start your AIME container with

mlc-open MyContainer

like explained in https://www.aime.info/blog/deep-learning-framework-container-management.

To access your code, put it into the /workspace directory contained in the users home directory, it is then directly accessible within the container and can be run with e.g.:

python3 sample.py

To avoid this repetitive task, it is also possible to edit your code directly on the AIME GPU server, in the following example explained with Microsoft Visual Studio Code.

The modern way: Using Visual Studio Code to remotely edit your code

Visual Studio Code is a source-code editor made by Microsoft for Windows, Linux and macOS. Features include support for debugging, syntax highlighting, intelligent code completion, snippets, code refactoring, and embedded Git. Users can change the theme, keyboard shortcuts, preferences, and install extensions that add additional functionality, e.g. editing code on remote machines via ssh. The following screenshot shows an example of a program stored on an AIME GPU Server ready to edit remotely:

Visual Studio Code on Linux

Install Microsoft Visual Studio Code with your Linux package manager and run it. Switch to the tab Extensions on the navigation bar on the left side of the window. Type ssh into the search field and install the extension SSH FS by clicking install next to it.

Now switch to the new appearing icon SSH FS in the navigation bar on the left.

Click add to make a new configuration for a ssh connection.

Type a preferred name for the configuration into the text field name and click save.

In the now appearing window type the gateway (f.i. gate0X.aime.info), the port and the user name you got from AIME by mail into the text fields Host and Port and Username. To type the passwort into the text field Password is optional. If left blank, a password prompt will show each time you try to connect. In the optional Text field Root you can specify the workspace folder on the remote machine. Once finished click Save to complete the configuration.

The new created configuration should now appear in the field CONFIGURATIONS on the left side. Click here on the Add as Workspace folder icon next to your configuration. If no password was saved in the configuration, a double password prompt will appear now.

It now automatically switches to the tab Explorer where the content of the remote workspace folder is shown. Here you're able to interact with the workspace folder of the remote machine in almost the same way like a local folder. While creating new files and folders or editing existing code is possible, deleting files doesn't work. To remotely run the code in Visual Studio Code doesn't work with all features right now. Thats why it is recommended to run it in the terminal as described in the penultimate paragraph. Once finished editing your code, remember to save all the related files.

Visual Studio Code on Windows 10

Download Microsoft Visual Studio Code from https://code.visualstudio.com , install it and run it.

Switch to the tab Extensions and enter ssh into the search bar on the top left of the window. Click Install next to the extension with name Remote - SSH. Now change to the tab Remote Explorer.

To establish a new ssh connection click on Add new (The +-sign) next to SSH TARGETS. Into the upcoming prompt enter the following command:

ssh -XY -p <port> <user_name>@<gateway>

The <port>, <user_name> and <gateway> you got from AIME by mail. The flag -XY activates X11 screen forwarding to your local screen, f.i. to show plots by matplotlib. Select a file where this configuration is to be saved. The new established connection should now appear under SSH TARGETS. To start it click on the button Connect to Host in New Window next to the connection. Enter the password you got from AIME via mail in the password prompt.

Now a new instance of Microsoft Visual Studio Code is running on the remote machine. If not preselected, switch to the tab Explorer. Click on Open Folder and select a desired folder on the remote machine as a workspace folder. Enter again the password in the upcoming password prompt.

Now you're able to interact with the workspace folder of the remote machine in almost the same way like a local folder. While creating new files and folders or editing existing code is possible, deleting files doesn't work. To remotely run the code in Visual Studio Code doesn't work without problems right now. Thats why it is recommended to run it in the terminal as described in as described in the penultimate section. Once finished editing your code, remember to save all the related files.

Visual Studio Code on macOS

Download Microsoft Visual Studio Code from https://code.visualstudio.com/docs/setup/mac , install it and run it.

Switch to the tab Extensions on the navigation bar on the left side of the window. Type ssh into the search field and install the extension SSH FS by clicking install next to it.

Now switch to the new appearing icon SSH FS in the navigation bar on the left.

Click add to make a new configuration for a ssh connection.

Type a preferred name for the configuration into the text field name and click save.

In the now appearing window type the gateway (f.i. gate0X.aime.info), the port and the user name you got from AIME by mail into the text fields Host and Port and Username. To type the passwort into the text field Password is optional. If left blank, a password prompt will show each time you try to connect. In the optional Text field Root you can specify the workspace folder on the remote machine. Once finished click Save to complete the configuration.

The new created configuration should now appear in the field CONFIGURATIONS on the left side. Click here on the Add as Workspace folder icon next to your configuration. If no password was saved in the configuration, a double password prompt will appear now.

It now automatically switches to the tab Explorer where the content of the remote workspace folder is shown. Here you're able to interact with the workspace folder of the remote machine in almost the same way like a local folder. You can create new files and folders, also editing existing code is possible. To remotely run the code in Visual Studio Code doesn't work with all features right now. Thats why it is recommended to run it in the terminal as described in the next section. Once finished editing your code, remember to save all the related files.

Running code on the remote machine

Running your code in the terminal gives you benefits like extra screen sessions and working with containers without too much configuration. To connect to the remote machine via ssh open the terminal and enter the following command

ssh -XY -p <port> <user_name>@<gateway>

with the same port, user name and gateway like above you got from AIME by mail. Add the flag -XY to forward the X11 screen to your local screen (f.i. to show plots by matplotlib) After fullfilling the password prompt you're connected to the remote machine via SSH. How to run code with a long runtime we see in the next section.

Screen session with AIME container

Code with a long runtime might require the possibility to close the terminal session (and the local client) without cancelling the running process. This can be achieved with the on the AIME servers preinstalled command line tool screen. To start a new screen session with the name <screen_name>, run the following command on the remote machine.

screen -S <screen_name>

Now open your AIME container with

mlc-open MyContainer

Navigate to your project folder in the workspace and run the code on the remote machine.

python3 spam.py

To detach the screen session from the terminal without killing the process press Ctrl+A followed by the key D. Now you can close the terminal and shutdown your local client while the process keeps running. To resume your screen session just establish a new ssh connection like explained above and run the command

screen -r

Navigating in a screen session works a little differently then in a common terminal sessions. F.i. To scroll in a screen session, you need to switch to the copy mode. This can be done by pressing Ctrl+A followed by Esc. Now you can scroll with the arrow keys or the mouse wheel. Press Esc again to leave the copy mode.