vscode-dev-containers icon indicating copy to clipboard operation
vscode-dev-containers copied to clipboard

Specifying specific GPUs for the devcontainer.

Open bjajoh opened this issue 2 years ago • 5 comments

Hi,

I encountered an issue while trying to run two devcontainers on the same system (4 GPUs) and tried to allocate 2 GPUs to each.

This works and does exactly what I want: docker run --gpus '"device=2,3"' nvidia/cuda:9.0-base nvidia-smi

This also works as documented for the devcontainer:

"runArgs": [
	"--gpus",
	"device=2"
],

However when trying to use two specific GPUs, it fails.

"runArgs": [
	"--gpus",
	"device=2,3"
],

I think this might be due to the way docker is expecting this device string in case of multiple GPUs.

bjajoh avatar May 14 '23 11:05 bjajoh

@bjajoh I haven't tried this myself, but I wonder if adding some escaped quoted to your runArgs would work? If docker run is expecting quotes around the device=2,3 value, then you should be able to put those quotes in the runArgs array item. Something like the following might work:

"runArgs": [
	"--gpus",
	"'\"device=2,3\"'"
],

jkeech avatar May 15 '23 18:05 jkeech

@jkeech It sadly dows not work: invalid argument "'\"device=2,3\"'" for "--gpus" flag: parse error on line 1, column 2: bare " in non-quoted-field Do you have any other idea how to solve this?

bjajoh avatar May 16 '23 07:05 bjajoh

There's probably some amount of nested escaping of the quotes in the devcontainer.json that needs to happen to end up with the docker process spawn args having the desired quotes. I would play around with different levels of quoting and quote escaping in the runArgs value.

jkeech avatar May 16 '23 15:05 jkeech

Also encountering this issue. Alternative might be to set the env variable NVIDIA_VISIBLE_DEVICES instead of passing through --gpus. Although it would be nice to be able to know how escaping the quote would work

https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/user-guide.html#gpu-enumeration

	"containerEnv": {
		"NVIDIA_VISIBLE_DEVICES": "0,1"
	},
	"runArgs": [
		"--runtime=nvidia"
	]

ryxli avatar Jun 04 '23 20:06 ryxli

@ryxli It actually works! Thank you so much!

bjajoh avatar Jun 10 '23 08:06 bjajoh