Connecting to a Notebook Instance Through VS Code Toolkit
This section describes how to use the ModelArts VS Code Toolkit plug-in to remotely connect to a notebook instance.
Prerequisites
You have downloaded and installed VS Code. For details, see Installing VS Code.
Step 1 Install the VS Code Plug-in
- Search for ModelArts-HuaweiCloud in the EXTENSIONS text box and click Install.
Figure 1 Installing the VS Code plug-in
- Wait for about 1 to 2 minutes.
Figure 2 Installation process
- After the installation is complete, check the message displayed in the lower right corner. If the ModelArts icon and remote SSH icon are displayed in the navigation pane on the left, the VS Code plug-in is installed.
Figure 3 Installation completion message
Figure 4 Installation completed
Step 2 Log In to the VS Code Plug-in
- In the local VS Code development environment, click and User Settings, and configure the login information.
Figure 6 Logging in to the plug-in
Enter the login information and click Log in.- Name: Custom username, which is displayed only on the VS Code page and is not associated with any Huawei Cloud account.
- AK and SK: Access key pair. To create a key pair, choose How Do I Obtain an Access Key?. , and click Create Access Key. For details, see
- Region: must be the same as that of the notebook instance to be remotely connected. Otherwise, the connection will fail.
- After the login, check the notebook instance list.
The list displays only notebook instances in the default workspace on the ModelArts console.
Figure 7 Login succeeded
Step 3 Create a Notebook Instance
- Create a notebook instance with remote SSH enabled, and download the key file to either of the following directories based on your OS:
macOS/Linux: Users/{{user}}
- A key pair is automatically downloaded after you create it. Securely store your key pair. If an existing key pair is lost, create a new one.
Create a notebook instance with remote SSH enabled. For details, see Creating a Notebook Instance.
Step 4 Access the Notebook Instance
- In the local VS Code development environment, right-click the instance name and choose Connect to Instance from the shortcut menu to start and connect to the notebook instance.
The notebook instance can either be running or stopped. If it is stopped, the VS Code plug-in starts the instance and then connects to it.
Figure 8 Connecting to a notebook instance
Alternatively, click the instance name. On the instance details page, click Connect. Then, the system automatically starts and connects to the notebook instance.Figure 9 Viewing details about a notebook instance
- When you connect to a notebook instance for the first time, the system prompts you in the lower right corner to configure the key file. In this case, select the local .pem key file and click OK.
Figure 10 Configuring the key file
- Wait for about 1 to 2 minutes until the notebook instance is accessed. After information similar to the following is displayed in the lower left corner of the VS Code environment, the connection is succeeded.
Figure 11 Connection succeeded
Debugging Code Remotely
- On the VS Code page, upload local code to the cloud development environment.
- Choose OK.
Figure 12 Open Folder
Figure 13 Selecting a file path
, select the path to be opened, and click
- 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.
- 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 14 Selecting a Python version
- Choose OK.
- Click the execution button to run the code. The code output is shown on the TERMINAL tab page.
- If a training job takes a long time to execute, run the job at the backend through 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:
- Choose on the left.
- Select the default Python code file.
- Click on the left of the code to set breakpoints.
- 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.
- If a training job takes a long time to execute, run the job at the backend through 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:
Related Operations
For details about uninstalling the VS Code plug-in, see Figure 15.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot