Skip to content
This repository has been archived by the owner on Aug 2, 2023. It is now read-only.

Unable to debug an OpenAI baselines pipeline task #1058

Closed
davidhopper2003 opened this issue Nov 29, 2018 · 4 comments
Closed

Unable to debug an OpenAI baselines pipeline task #1058

davidhopper2003 opened this issue Nov 29, 2018 · 4 comments

Comments

@davidhopper2003
Copy link

I used VSCode to debug the PPO2 algorithm in the project OpenAI baselines. Lines 57-58 of the file baselines/common/vec_env/subproc_vec_env.py uses the pipeline to receive data. When debugging to line 58:

observation_space, action_space = self.remotes[0].recv()

the program has no response and the debugging process cannot continue (As shown below).

ppo2_debug_1
ppo2_debug_2
ppo2_debug_3

My configuration file .vscode/launch.json is shown as follows:

{

    // Use IntelliSense to learn about possible attributes.

    // Hover to view descriptions of existing attributes.

    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387

    "version": "0.2.0",

    "configurations": [

        {

            "name": "Python: Module",

            "type": "python",

            "request": "launch",

            "module": "baselines.run",

            "console": "integratedTerminal",

            "args": [

                "--alg",

                "ppo2",

                "--env",

                "PongNoFrameskip-v4",

                "--num_timesteps",

                "2e7",

                "--save_path",

                "~/models/pong_20M_ppo2"

            ],

        },

        {

            "name": "Python: Current File (Integrated Terminal)",

            "type": "python",

            "request": "launch",

            "program": "${workspaceFolder}/baselines/run.py",

            "console": "integratedTerminal", 

            "args": [

                "--alg",

                "ppo2",

                "--env",

                "PongNoFrameskip-v4",

                "--num_timesteps",

                "2e7",

                "--save_path",

                "~/models/pong_20M_ppo2"

            ],

        }

    ]

}

When I used the command line

python -m baselines.run --alg=ppo2 --env=PongNoFrameskip-v4 --num_timesteps=2e7 --save_path=~/models/pong_20M_ppo2

to run the program in a terminal, there is no problem.

Any helpful suggestions will be highly appreciated. Thank you.

@brettcannon brettcannon changed the title Unable to debug a pipeline task with VSCode Unable to debug an OpenAI baselines pipeline task Nov 29, 2018
@brettcannon brettcannon transferred this issue from microsoft/vscode-python Nov 29, 2018
@karthiknadig
Copy link
Member

@davidhopper2003 Can you add "subProcess": true to the launch arguments, and see if that helps?

@davidhopper2003
Copy link
Author

@karthiknadig Thanks for your advice. I've tried it but it doesn't work.
launch_modify
ppo2_debug_4
ppo2_debug_5

@karthiknadig
Copy link
Member

I think this might be due to multiprocessing using fork. That should be addressed by this issue #943.
You could try set multiprocessing.set_start_method('spawn') before using it.

@davidhopper2003
Copy link
Author

@karthiknadig
This method does work. Great! You're awesome. Thank you very much. Here is my modifications in the file baselines/common/vec_env/subproc_vec_env.py:

Modification 1: Line 1-3

import numpy as np
from multiprocessing import Process, Pipe
from . import VecEnv, CloudpickleWrapper

to

import numpy as np
import multiprocessing
from multiprocessing import Process, Pipe
from . import VecEnv, CloudpickleWrapper

Modification 2: Line 48-50

self.remotes, self.work_remotes = zip(*[Pipe() for _ in range(nenvs)])
self.ps = [Process(target=worker, args=(work_remote, remote, CloudpickleWrapper(env_fn)))
                for (work_remote, remote, env_fn) in zip(self.work_remotes, self.remotes, env_fns)]

to

self.remotes, self.work_remotes = zip(*[Pipe() for _ in range(nenvs)])

# Set the multi-process startup method to 'spawn` instead of `fork` to support VSCode debugging.
multiprocessing.set_start_method('spawn')

self.ps = [Process(target=worker, args=(work_remote, remote, CloudpickleWrapper(env_fn)))
                for (work_remote, remote, env_fn) in zip(self.work_remotes, self.remotes, env_fns)]

ppo2_debug_6

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants