| Ray Debug Tutorial
|
| ==================
|
|
|
| Last updated: 04/23/2025
|
|
|
|
|
| .. _wuxibin89: https:
|
|
|
| Author: `Ao Shen <https:
|
|
|
| How to debug?
|
| ---------------------
|
|
|
|
|
| Ray Distributed Debugger VSCode Extension (Recommended)
|
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
| 1. Starting with Ray 2.39, Anyscale has introduced the `Ray Distributed Debugger <https:
|
|
|
| .. image:: https:
|
| :alt: Ray Distributed Debugger VSCode extension screenshot
|
|
|
| 2. Prerequisites.
|
|
|
| Ensure the following are installed (see the extension README for more detail):
|
|
|
| - Visual Studio Code
|
| - `ray[default]` >= 2.9.1
|
| - `debugpy` >= 1.8.0
|
|
|
| .. image:: https:
|
| :alt: VSCode with Ray prerequisites
|
|
|
| 3. Environment Variables.
|
|
|
| To enable post‑mortem debugging, set:
|
|
|
| .. code-block:: bash
|
|
|
| export RAY_DEBUG_POST_MORTEM=1
|
|
|
| .. admonition:: Note
|
| :class: important
|
|
|
| Be sure to remove any legacy flags before starting Ray:
|
|
|
| - `RAY_DEBUG=legacy`
|
| - `--ray-debugger-external`
|
|
|
| 4. Configuring BreakpointsSet up breakpoint() in your code, and submit job to cluster. Then the extension will show the breakpoint information.
|
|
|
|
|
| 1. Insert `breakpoint()` calls into your remote functions.
|
| 2. Submit your job to the cluster.
|
|
|
| The extension will detect active breakpoints and display them in VSCode.
|
|
|
| **Note:** Breakpoints are only supported inside functions decorated with `@ray.remote`.
|
|
|
| 5. Launching the Debugger.
|
|
|
| Run your job directly from the command line (do not use a `launch.json`):
|
|
|
| .. code-block:: bash
|
|
|
| python job.py
|
|
|
| 6. Attaching to a Breakpoint.
|
|
|
| Once the process hits the first `breakpoint()`, click the Ray Distributed Debugger icon in the VSCode sidebar to attach the debugger.
|
|
|
| .. image:: https:
|
| :alt: Attaching VSCode debugger to Ray process
|
|
|
| 7. Debugging With Multiple breakpoint().
|
|
|
| For each subsequent task, first disconnect the current debugger session, then click the extension icon again to attach to the next breakpoint.
|
|
|
| .. image:: https:
|
| :alt: Disconnecting and reconnecting the debugger
|
|
|
| Legacy Ray Debugger
|
| ~~~~~~~~~~~~~~~~~~~
|
| 1. Ray has a builtin legacy `debugger <https:
|
|
|
| .. code-block:: bash
|
|
|
| # start head node
|
| RAY_DEBUG=legacy ray start --head --dashboard-host=0.0.0.0 --ray-debugger-external
|
| # start worker node
|
| RAY_DEBUG=legacy ray start --address='10.124.46.192:6379' --ray-debugger-external
|
|
|
| 2. Set up breakpoint in your code, and submit job to cluster. Then run ``ray debug`` to wait breakpoint:
|
|
|
| .. image:: https:
|
|
|
|
|