'How to disable ray for debugging
In my code I am using ray to manage multiple workers, but I've realised that even if I set the number of workers to 1 I still cannot use PyCharm to debug my code (this seems to be a known issue). What I would really like to be able to do is run the code in "debug mode", say, where I don't use ray at all. Currently all my workers are initialised with something like:
@ray.remote(num_gpus=0.25)
def worker_function():
...
and called from a main script with something like worker_function.remote(). So I guess I would like to somehow make the @ray.remote(...) optional. Is there a nice way to do something like this?
Solution 1:[1]
There are 2 possible ways to do this.
Initialize Ray in local mode. This will make all ray tasks and actors run serially in a single process allowing you to use your native debugger. Note that since your program is now serialized, it could behave in a subtly different way. Local mode is enabled in
ray.init(local_mode=True)If you're not tied to the pycharm debugger, Ray also provides a fairly large subset of pdb behavior on a real cluster via its own Ray Debugger.
You could do
@ray.remote(num_gpus=0.25)
def worker_function():
breakpoint()
...
to set a breakpoint in a remote function, then run the program via ray debug on the command line.
Solution 2:[2]
Hi @Henry Charlesworth!
I got the same situation while debugging different ray workers on PyCharm while trying to understand the https://github.com/YeWR/EfficientZero source code.
The EfficientZero algorithm launches several workers for different kinds of work loads (e.g. self-playing the atari game, implementing the replay buffer, reanalyzing experiences, etc...).
This is what I did to debug, for example, 2 of the different workers (in this example, the self-play worker and the replay buffer worker):
- Use pip for installing pydevd-pycharm into your project (the version at the time of writing this message was 221.5591.52)
pip install pydevd-pycharm~=221.5591.52
- Create a
Remote Debug Serverconfiguration for the self-play worker.
- Adapt the code of the self-play worker to connect to the new configuration on creation

- Create another
Remote Debug Serverconfiguration for the replay buffer worker.
- Adapt the code of the replay buffer worker to connect to the new configuration on creation

These are all the changes that you need to add to the code.
Now, you just need to start all the configurations in the right order:
- the remote debugger for the self-play worker
- the remote debugger for the replay buffer worker
- the main program
After doing this, you should see 3 tabs on the Debug section of Pycharm:
Now, by selecting any of those tabs, you could debug the 3 processes at the same time... for example, you can hit a breakpoint on the replay buffer worker...
while at the same time you are hitting another breakpoint on the self play worker...

And that's all... I hope that this can be as helpful to you as it was for me.
Best regards,
David
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Alex |
| Solution 2 | duxtinto |

