Launch Visual Studio Code integrated with Azure Machine Learning (preview)

In this article, you learn how to launch Visual Studio Code remotely connected to an Azure Machine Learning compute instance. Use VS Code as your integrated development environment (IDE) with the power of Azure Machine Learning resources. Use VS Code in the browser with VS Code for the Web, or use the VS Code desktop application.

Important

This feature is currently in public preview. This preview version is provided without a service-level agreement, and we don't recommend it for production workloads. Certain features might not be supported or might have constrained capabilities.

For more information, see Supplemental Terms of Use for Azure Previews.

There are two ways you can connect to a compute instance from Visual Studio Code. We recommend the first approach.

  1. Use VS Code as your workspace's integrated development environment (IDE). This option provides you with a full-featured development environment for building your machine learning projects.

    • You can open VS Code from your workspace either in the browser VS Code for the Web or desktop application VS Code Desktop.
    • We recommend VS Code for the Web, as you can do all your machine learning work directly from the browser, and without any required installations or dependencies.
  2. Remote Jupyter Notebook server. This option allows you to set a compute instance as a remote Jupyter Notebook server. This option is only available in VS Code (Desktop).

Important

To connect to a compute instance behind a firewall, see Configure inbound and outbound network traffic.

Prerequisites

Before you get started, you need:

  1. An Azure Machine Learning workspace and compute instance. Complete Create resources you need to get started to create them both.

  2. Sign in to studio and select your workspace if it's not already open.

  3. In the Manage preview features panel, scroll down and enable Connect compute instances to Visual Studio Code for the Web.

    Screenshot shows how to enable the VS Code for the web preview.

Use VS Code as your workspace IDE

Use one of these options to connect VS Code to your compute instance and workspace files.

This option connects your current VS Code session to a remote compute instance. In order to connect to your compute instance from VS Code, you need to install the Azure Machine Learning Visual Studio Code extension. For more information, see the Azure Machine Learning Visual Studio Code Extension setup guide.

Azure Machine Learning Extension

  1. In VS Code, launch the Azure Machine Learning extension.
  2. Expand the Compute instances node in your extension.
  3. Right-click the compute instance you want to connect to and select Connect to Compute Instance.

Screenshot shows how to connect to compute instance.

Command Palette

  1. In VS Code, open the command palette by selecting View > Command Palette.
  2. Enter into the text box AzureML: Connect to Compute Instance.
  3. Select your subscription.
  4. Select your workspace.
  5. Select your compute instance or create a new one.

If you pick one of the click-out experiences, a new VS Code window is opened, and a connection attempt made to the remote compute instance. When attempting to make this connection, the following steps are taking place:

  1. Authorization. Some checks are performed to make sure the user attempting to make a connection is authorized to use the compute instance.
  2. VS Code Remote Server is installed on the compute instance.
  3. A WebSocket connection is established for real-time interaction.

Once the connection is established, it's persisted. A token is issued at the start of the session, which gets refreshed automatically to maintain the connection with your compute instance.

After you connect to your remote compute instance, use the editor to:

Remote Jupyter Notebook server

This option allows you to use a compute instance as a remote Jupyter Notebook server from Visual Studio Code (Desktop). This option connects only to the compute instance, not the rest of the workspace. You won't see your workspace files in VS Code when using this option.

In order to configure a compute instance as a remote Jupyter Notebook server, first install:

To connect to a compute instance:

  1. Open a Jupyter Notebook in Visual Studio Code.

  2. When the integrated notebook experience loads, choose Select Kernel.

    Screenshot shows how to select Jupyter Server.

    Alternatively, use the command palette:

    1. Select View > Command Palette from the menu bar to open the command palette.
    2. Enter into the text box AzureML: Connect to Compute instance Jupyter server.
  3. Choose Azure ML Compute Instances from the list of Jupyter server options.

  4. Select your subscription from the list of subscriptions. If you have previously configured your default Azure Machine Learning workspace, this step is skipped.

  5. Select your workspace.

  6. Select your compute instance from the list. If you don't have one, select Create new Azure Machine Learning Compute Instance and follow the prompts to create one.

  7. For the changes to take effect, you have to reload Visual Studio Code.

  8. Open a Jupyter Notebook and run a cell.

Important

You MUST run a cell in order to establish the connection.

At this point, you can continue to run cells in your Jupyter Notebook.

Tip

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.

Next steps

Now that you've launched Visual Studio Code remotely connected to a compute instance, you can prep your data, edit and debug your code, and submit training jobs with the Azure Machine Learning extension.

To learn more about how to make the most of VS Code integrated with Azure Machine Learning, see Work in VS Code remotely connected to a compute instance (preview).