Updated on 2026-08-04 GMT+08:00

Connecting to a Notebook Instance Through VS Code with One Click

Prerequisites

  • The notebook instance with remote SSH enabled is running. For details, see Creating a Notebook Instance.
  • You have downloaded the key file of the instance to a following local directory or its subdirectory based on your operating system:

    Windows: C:\Users\{{user}}

    Mac/Linux: /Users/{{user}}

Connecting VS Code to a Notebook Instance

  1. Log in to the ModelArts console and perform the following operations as required:

    • New console: Choose Model Build > Notebook.
    • Old console: Choose Development Space > Notebook.

  2. Choose More > Access VS Code in the Operation column. A dialog box is displayed, asking you whether to open Visual Studio Code. Click Access Environment in the Operation column. In the Access Method dialog box, choose the Local tab and click Access on the right of Access VS Code.
  3. If you have installed VS Code, click Access VS Code. The Visual Studio Code page is displayed.

    If VS Code has not been installed, click Windows or another OS as required to download and install VS Code. For details about how to install VS Code, see Connecting to a Notebook Instance Through VS Code.

    Figure 1 Downloading and Installing VS Code

  4. If the ModelArts VS Code extension has not been installed, click Install and Open. If you have installed the extension, perform 5.

    Figure 2 Installing the VS Code extension

    The installation takes about 1 to 2 minutes. After the installation is complete, a dialog box is displayed in the lower right corner. Then, click Reload Window and Open.

    This section uses VS Code 1.86 as an example. The Reload Window and Open dialog box may not be displayed when you install other versions of VS Code. In this case, perform 5.

    Figure 3 Reload Window and Open

    In the displayed dialog box, select Don't ask again for this extension and click Open.

    Figure 4 Selecting Don't ask again for this extension and clicking Open

  5. Remotely connect to a notebook instance.

    Before the remote connection is executed, the system automatically searches for the key file by name in the following directories: C:\Users\{{user}}\.ssh or downloads (Windows), or /Users/{{user}}/.ss or downloads (Mac/Linux).

    • If the key is found, use it to open a new window and remotely connect to an instance.
      Figure 5 Remotely connecting to a notebook instance
    • If the key file is not found, a dialog box is displayed. Select the correct key as prompted.

      The key file name cannot contain Chinese characters.

      Figure 6 Selecting a key file
      If an incorrect key is selected, a message will be displayed. Then, select the correct key as prompted.
      Figure 7 Selecting the correct key file

    When the information shown in the following figure is displayed, the instance is accessed.

    Figure 8 Connection successful

    The following error message indicates that accessing the instance failed. In this case, close the dialog box and view the output logs in the OUTPUT window. Then, check the FAQs and locate the cause.

    Figure 9 Connection failed

Debugging Code Remotely

  1. On the VS Code page, upload local code to the cloud development environment.
    1. Choose File > OpenFolder, select the path to be opened, and click OK.
      Figure 10 Open Folder
      Figure 11 Selecting a file path

    1. In the displayed directory structure on the left of the IDE, drag the code and files you want to upload to the corresponding folders. Then, the code is uploaded to the cloud development environment.
    2. Open the code file to be debugged in VS Code. Before running the code, click the default Python version in the lower left part and select a version as required.
      Figure 12 Selecting a Python version

  2. Click the execution button to run the code. The code output is shown in the TERMINAL tab.
    • If a training job takes a long time to execute, run the job at the backend using the nohup command. This prevents the disconnection of an SSH session or a network failure from affecting job execution. The following shows an example nohup command:
      nohup your_train_job.sh > output.log 2>&1  &  tail -f  output.log
    • To debug the code, perform the following operations:
      1. Choose Run > Run and Debug on the left.
      2. Select the default Python code file.
      3. Click on the left of the code to set breakpoints.
      4. Debug the code according to the debug procedure which is displayed above the code, and the debug information is displayed on the left of the page.