5

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

4 Answers 4

9

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I also add multiple variables setting. env": {"PYTHONPATH":".", "CUDA_VISIBLE_DEVICES": "0"}
7

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"]
        }
    ]
}

Comments

2

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?

Comments

1

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!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.