Connect to an Azure Machine Learning compute instance in Visual Studio Code (preview)
In this article, you'll learn how to connect to an Azure Machine Learning compute instance using Visual Studio Code.
An Azure Machine Learning Compute Instance is a fully managed cloud-based workstation for data scientists and provides management and enterprise readiness capabilities for IT administrators.
There are two ways you can connect to a compute instance from Visual Studio Code:
- Remote Jupyter Notebook server. This option allows you to set a compute instance as a remote Jupyter Notebook server.
- Visual Studio Code remote development. Visual Studio Code remote development allows you to use a container, remote machine, or the Windows Subsystem for Linux (WSL) as a full-featured development environment.
Configure compute instance as remote notebook server
In order to configure a compute instance as a remote Jupyter Notebook server you'll need a few prerequisites:
- Azure Machine Learning Visual Studio Code extension. For more information, see the Azure Machine Learning Visual Studio Code Extension setup guide.
- Azure Machine Learning workspace. Use the Azure Machine Learning Visual Studio Code extension to create a new workspace if you don't already have one.
To connect to a compute instance:
Open a Jupyter Notebook in Visual Studio Code.
When the integrated notebook experience loads, select Jupyter Server.
Alternatively, you also use the command palette:
- Open the command palette by selecting View > Command Palette from the menu bar.
- Enter into the text box
Azure ML: Connect to Compute instance Jupyter server.
Azure ML Compute Instancesfrom the list of Jupyter server options.
Select your subscription from the list of subscriptions. If you have have previously configured your default Azure Machine Learning workspace, this step is skipped.
Select your workspace.
Select your compute instance from the list. If you don't have one, select Create new Azure ML Compute Instance and follow the prompts to create one.
For the changes to take effect, you have to reload Visual Studio Code.
Open a Jupyter Notebook and run a cell.
You MUST run a cell in order to establish the connection.
At this point, you can continue to run cells in your Jupyter notebook.
You can also work with Python script files (.py) containing Jupyter-like code cells. For more information, see the Visual Studio Code Python interactive documentation.
Configure compute instance remote development
For a full-featured remote development experience, you'll need a few prerequisites:
- Visual Studio Code Remote SSH extension.
- SSH-enabled compute instance. For more information, see the Create a compute instance guide.
On Windows platforms, you must install an OpenSSH compatible SSH client if one is not already present. PuTTY is not supported on Windows since the ssh command must be in the path.
Get the IP and SSH port for your compute instance
Go to the Azure Machine Learning studio at https://ml.azure.com/.
Select your workspace.
Click the Compute Instances tab.
In the Application URI column, click the SSH link of the compute instance you want to use as a remote compute.
In the dialog, take note of the IP Address and SSH port.
Save your private key to the ~/.ssh/ directory on your local computer; for instance, open an editor for a new file and paste the key in:
The private key will look somewhat like this:
-----BEGIN RSA PRIVATE KEY----- MIIEpAIBAAKCAQEAr99EPm0P4CaTPT2KtBt+kpN3rmsNNE5dS0vmGWxIXq4vAWXD ..... ewMtLnDgXWYJo0IyQ91ynOdxbFoVOuuGNdDoBykUZPQfeHDONy2Raw== -----END RSA PRIVATE KEY-----
Change permissions on file to make sure only you can read the file.
chmod 600 ~/.ssh/id_azmlcitest_rsa
Add instance as a host
Open the file
~/.ssh/config (Linux) or
C:\Users<username>.ssh\config (Windows) in an editor and add a new entry similar to the content below:
Host azmlci1 HostName 18.104.22.168 Port 50000 User azureuser IdentityFile ~/.ssh/id_azmlcitest_rsa
Here some details on the fields:
|Host||Use whatever shorthand you like for the compute instance|
|HostName||This is the IP address of the compute instance|
|Port||This is the port shown on the SSH dialog above|
|User||This needs to be
|IdentityFile||Should point to the file where you saved the private key|
Now, you should be able to ssh to your compute instance using the shorthand you used above,
Connect VS Code to the instance
Click the Remote-SSH icon from the Visual Studio Code activity bar to show your SSH configurations.
Right-click the SSH host configuration you just created.
Select Connect to Host in Current Window.
From here on, you are entirely working on the compute instance and you can now edit, debug, use git, use extensions, etc. -- just like you can with your local Visual Studio Code.
Now that you've set up Visual Studio Code Remote, you can use a compute instance as remote compute from Visual Studio Code to interactively debug your code.
Tutorial: Train your first ML model shows how to use a compute instance with an integrated notebook.