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 Microsoft 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 the 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.

VS Code for the Web provides you with a full-featured development environment for building your machine learning projects, all from the browser and without required installations or dependencies. And by connecting your Azure Machine Learning compute instance, you get the rich and integrated development experience VS Code offers, enhanced by the power of Azure Machine Learning.

Launch VS Code for the Web with one select from the Azure Machine Learning studio, and seamlessly continue your work.

Sign in to Azure Machine Learning studio and follow the steps to launch a VS Code (Web) browser tab, connected to your Azure Machine Learning compute instance.

You can create the connection from either the Notebooks or Compute section of Azure Machine Learning studio.

  • Notebooks

    1. Select the Notebooks tab.

    2. In the Notebooks tab, select the file you want to edit.

    3. If the compute instance is stopped, select Start compute and wait until it's running.

      Screenshot shows how to start compute if it's stopped.

    4. Select Editors > Edit in VS Code (Web).

    Screenshot of how to connect to Compute Instance VS Code (Web) Azure Machine Learning Notebook.

  • Compute

    1. Select the Compute tab
    2. If the compute instance you wish to use is stopped, select it and then select Start.
    3. Once the compute instance is running, in the Applications column, select VS Code (Web).

    Screenshot of how to connect to Compute Instance VS Code Azure Machine Learning studio.

If you don't see these options, make sure you've enabled the Connect compute instances to Visual Studio Code for the Web preview feature, as shown in the Prerequisites section.

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).