In this guide, we’ll look at attaching the VSCode remote debugger to a Valohai execution.
Python Example
debugpy
is an implementation of the Debug Adapter Protocol for Python used with VS Code. You can install it as a Python package using pip
.
import debugpy
import numpy as np
import time
# Listen on port 5678
debugpy.listen(5678)
# The script is halted here, until a debugger is attached
debugpy.wait_for_client()
for x in range(1,20) :
print(f"Doing computation {x}")
data = np.random.random((50,50))
sum = np.sum(data)
time.sleep(2)
- step:
name: train
image: python:3.9
command:
- pip install numpy debugpy
- python train.py
Then launch a new Valohai execution with SSH debugging enabled. Follow the Remote Access (SSH) how-to guide for detailed instructions.
Connect from VS Code to a remote execution
Start by opening an SSH tunnel to the Valohai execution. You’ll get the IP of the machine from the Valohai execution logs.
ssh -i <PATH-TO-YOUR-PRIVATE-SSH-KEY> <IP-FROM-VALOHAI> -p 2222 -L5678:127.0.0.1:5678
Open the Run and Debug panel from VSCode and hit Run and Debug while you have your train.py
open. Make sure you select the Remote Attach debug configuration.
As soon as your debugger is attached, the code will continue from debugpy.wait_for_client()
and start hitting your breakpoints. When you hit a breakpoint, you’ll also be able to see your local variables and edit them on the fly.