The Ray Distributed Debugger is a VSCode extension designed to streamline the debugging process for Ray open source users, offering interactive debugging experience with Visual Studio Code and Ray >= 2.9.1. The Ray Debugger enables you to:
Break into Remote Tasks: Set breakpoints anywhere in your Ray cluster. When your code hits the breakpoints, it will pause execution and allow you to connect with VSCode for debugging.
Post-Mortem Debugging: When Ray tasks fail with unhandled exceptions, Ray automatically freezes the failing task and waits for the Ray Debugger to attach, allowing you to investigate to inspect the state of the program at the time of the error.
Say goodbye to the complexities of debugging distributed systems. Ray Distributed Debugger empowers you to debug Ray applications more efficiently, saving you time and effort in your development workflow.
Ready to revolutionize your debugging experience? Complete the form below and dive into seamless debugging with Ray Debugger in VSCode!
Visual Studio Code.
ray[default] >= 2.9.1.
debugpy >= 1.8.0.
Setup Environment: Create a new virtual environment and install dependencies.
1conda create -n myenv python=3.9
2conda activate myenv
3pip install "ray[default]" debugpy
Start a Ray Cluster: Run ray start --head to start a Ray Cluster.
1ray start --head
Register Clusters: Add the Ray cluster IP:PORT to the Cluster list. The default IP:PORT is 127.0.0.1:8265, and you may change it when starting a new cluster. Make sure the IP and port are accessible from your current machine.
Create a Ray Task: Create a file job.py with the following snippet. Add the RAY_DEBUG environment variable to enable Ray Debugger and add breakpoint() in the ray task.
1import ray
2import sys
3
4# Add RAY_DEBUG environment variable to enable Ray Debugger
5ray.init(runtime_env={
6 "env_vars": {"RAY_DEBUG": "1"},
7})
8
9@ray.remote
10def my_task(x):
11 y = x * x
12 breakpoint() # Add a breakpoint in the ray task
13 return y
14
15@ray.remote
16def post_mortem(x):
17 x += 1
18 raise Exception("An exception is raised")
19 return x
20
21if len(sys.argv) == 1:
22 ray.get(my_task.remote(10))
23else:
24 ray.get(post_mortem.remote(10))
Setup Debugger Local Folder: Ray Debugger needs to know the absolute path to the folder you submitted job.py. Use pwd command to get the submission path, and set the cluster's local folder to the path. For each cluster, you can set the local folder by clicking on the ⚙️ icon on the cluster item.
Run Your Ray Application: Start running your Ray application.
1python job.py
Attach to Paused Tasks:
The task will enter a paused state once the breakpoint is hit.
The terminal will clearly indicate when a task is paused and waiting for the debugger to attach.
The paused tasks will be listed in the Ray Debugger extension.
Click on a paused task to attach the VSCode debugger.
Use the VSCode Debugger: Debug your Ray application just as you would when developing locally.
Continuing from the previous section, let's delve into Post-Mortem debugging. This feature becomes essential when Ray tasks encounter unhandled exceptions. In such cases, Ray automatically freezes the failing task, awaiting attachment by the Ray Debugger. This functionality empowers you to thoroughly investigate and inspect the program's state at the time of the error.
Run a Ray Task Raised Exception: Run the same job.py created above with an additional argument raise-exception.
1python job.py raise-exception
Attach to Paused Tasks:
The task will be frozen once the exception is thrown.
The terminal will clearly indicate when a task is paused and waiting for the debugger to attach.
The paused tasks will be listed in the Ray Debugger extension.
Click on a paused task to attach the VSCode debugger.
Use the VSCode Debugger: Debug your Ray application just as you would when developing locally.
Join #ray-debugger channel on the Ray slack channel to get help
Access Anyscale today to see how companies using Anyscale and Ray benefit from rapid time-to-market and faster iterations across the entire AI lifecycle.