Skip to content

Vscode

This tutorial describes how to interface VSCode with an interactive SLURM job.

To successfully use VScode with interactive job, you will need to establish a two-stage tunnel - from your computer to the login node, and from the login node to the compute node - because you do not have direct access to the compute node itself without a job running.

Prerequisite Steps

  • you'll need to create a private ssh key on a login node on each cluster by running:

    ssh-keygen -b 521 -t ECDSA -C "$USER@$HOSTNAME"
    

  • Pick a number between 7000 and 8000 by running:

    echo $(( 7000 + RANDOM%1000 ))
    

Random Port Number

The command above will randomly generate a port number that you would need later. It should be unique for each individual on the cluster. If in the future you have issue with this port, just choose another and don't forget to change it in your configuration files.

  • On your computer, open up ~/.ssh/config and add the following lines, where $LOGIN is your username on the cluster and $PORTNUMBER is your VSCode port number that you have just generated:
Host galvani-login1 
  HostName 134.2.168.43 # login node 1
  User $LOGIN
  ForwardAgent yes

Host galvani-login2
  HostName 134.2.168.114 # login node 2 - default
  User $LOGIN
  ForwardAgent yes

Host mlc-galvani-vs
  User $LOGIN
  ProxyCommand ssh -o 'ForwardAgent yes' galvani "nc \$(squeue --me --name=vs --states=R -h -O NodeList) $PORTNUMBER"
  StrictHostKeyChecking no
  ForwardAgent yes

For Windows Users

If you are on Windows, use nc $(squeue --me --name=vs --states=R -h -O NodeList) $PORTNUMBER (without the backslash before $) and replace -o 'ForwardAgent=yes' with -A

This creates the quick commands needed to get VSCode to interface with the compute nodes.

  • On the Cluster Login nodes, create the following file as $WORK/vscode/allocate-galvani-vs.sh and replace $PORTNUMBER with your VSCode port number:
#!/bin/bash
#SBATCH --job-name="vs" # job-name will be used in ~/.ssh/config above
#SBATCH --partition=2080-galvani
#SBATCH --time=9:00:00 # walltime
#SBATCH --gpus=1 # for example request one default gpu
/usr/sbin/sshd -D -p $PORTNUMBER -f /dev/null -h ${HOME}/.ssh/id_ecdsa # uses the user key as the host key

Connect VSCode to the Compute Node running the Job

To connect VSCode on your machine to the compute node, first, run the following commands:

  • Connect to the appropriate login node using ssh galvani-login1 or ssh galvani-login2

  • Request compute resources while logged into the login node by submitting:

sbatch $WORK/vscode/allocate-galvani-vs.sh
This should allocate the node accordingly and set up the first stage of the two-stage tunnel.

  • Now connect to the second stage of the tunnel by running, on your machine:

ssh mlc-galvani-vs
This will start the necessary two-stage tunnel.

Now, connect the VSCode program to the remote server via the two-stage tunnel you've established.

In the current version of the documentation, you will probably find the (scroll down) "Forwarding A Port / Creating SSH Tunnel" section to be of use. Additional information about working with VSCode remote access on that page may also be helpful for some users.

Note

ML Cloud access procedures differ from that tutorial because, to access the ML Cloud's compute node as a remote resource, you must tunnel through the login node (creating a two-stage tunnel), while the VSCode documentation assumes you have direct access to that remote resource (a one-stage tunnel). However, once the two-stage tunnel is established, the rest of the operating procedures with VSCode should be similar to the documentation.


Last update: September 9, 2024
Created: September 9, 2024