In this guide, we’ll look at attaching the VSCode remote debugger to a Valohai execution.
Sample code
For this example, we'll use the following simple example code:
import numpy as np
import time
for x in range(1,20) :
print(f"Doing computation {x}")
data = np.random.random((50,50))
sum = np.sum(data)
time.sleep(2)
And the corresponding valohai.yaml file:
- step:
name: train
image: python:3.9
command:
- pip install numpy
- python train.py
Use debugpy
Import debugpy and set it to listen on port 5678.
import debugpy
import numpy as np
import time
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)
Now update the valohai.yaml
file to install debugpy in your Valohai execution.
- step:
name: train
image: python:3.9
command:
- pip install numpy debugpy
- python train.py
Commit your changes and push them to your Git repository.
Then launch a new Valohai execution with SSH debugging enabled. Follow the Remote access (SSH) how-to guide for detailed instructions.
Connect from VSCode to a remote execution
Start by opening an SSH tunnel to the Valohai execution. You'll get the IP of the machine from the Vlaohai 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.
Comments
0 comments
Please sign in to leave a comment.