Alessandro Gaballo
Alessandro Gaballo

Reputation: 770

Vscode - Python Debugger: unrecognized arguments

I'm trying to debug some Python code I have which I can run with no problem by typing the following in bash:

CUDA_VISIBLE_DEVICES=0 \
python test_multi.py \
--experiment_name 128_shortcut1_inject1_none \
--test_atts Eyeglasses \
--test_ints -1.0

I've created this json config file for VScode:

{
    "version": "0.2.0",
    "configurations": [

        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "<absolute_path>/test_multi.py",
            "console": "integratedTerminal",
            "env": [{ "name":"CUDA_VISIBLE_DEVICES", "value":0}],
            "args": ["--experiment_name 128_shortcut1_inject1_none", "--test_atts Eyeglasses", "--test_ints -1"]
        }
    ]
}

but I keep getting
test_multi.py: error: unrecognized arguments: --experiment_name 128_shortcut1_inject1_none --test_atts Eyeglasses --test_ints -1

Upvotes: 5

Views: 8054

Answers (4)

Grzegorz Wilczyński
Grzegorz Wilczyński

Reputation: 71

OK, so previous answers didn't work for me (my VSCode version is 1.85.2). To be more precise

"env": {"name":"CUDA_VISIBLE_DEVICES", "value":"1"}

approach was the only one that got past any VSCode errors but still it didn't work (tf.config.experimental.list_physical_devices("GPU") listed all of my GPUs).

But this did the trick (when I wanted to use GPU with associated number of 1, but it works the same if I wanted GPU with number 0):

"env": {"CUDA_VISIBLE_DEVICES": "1"}

Hope it helps!

Upvotes: 1

Robin Li
Robin Li

Reputation: 91

The way Brett shows didn't work with my case. I want to use the Number "1" GPU for debugging, so I added "env": {"CUDA_VISIBLE_DEVICES":"1"}, to the launcher.json file.

Upvotes: 9

Bochjamin
Bochjamin

Reputation: 75

I was looking at this thread to see how I could use CUDA_VISIBLE_DEVICES in env and the way you wrote it down, here:

"env": [{ "name":"CUDA_VISIBLE_DEVICES", "value":0}]

, didn't work for me. I had to correct it to:

"env": {"name":"CUDA_VISIBLE_DEVICES", "value":"0"}

I imagine the []- brackets are only expected when you have more then one entry?

Upvotes: 2

Brett Cannon
Brett Cannon

Reputation: 16100

Your use of args is slightly off; you need to treat each part of your arguments as their own string when they are to be passed in as individual things. The following should fix it:

{
    "version": "0.2.0",
    "configurations": [

        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "<absolute_path>/test_multi.py",
            "console": "integratedTerminal",
            "env": [{ "name":"CUDA_VISIBLE_DEVICES", "value":0}],
            "args": ["--experiment_name", "128_shortcut1_inject1_none", "--test_atts", "Eyeglasses", "--test_ints", "-1"]
        }
    ]
}

Upvotes: 7

Related Questions