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

Specifying specific GPUs for the devcontainer. #1741

Open
bjajoh opened this issue May 14, 2023 · 5 comments
Open

Specifying specific GPUs for the devcontainer. #1741

bjajoh opened this issue May 14, 2023 · 5 comments

Comments

@bjajoh
Copy link

bjajoh commented May 14, 2023

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.

@jkeech
Copy link
Member

jkeech commented May 15, 2023

@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\"'"
],

@bjajoh
Copy link
Author

bjajoh commented May 16, 2023

@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?

@jkeech
Copy link
Member

jkeech commented May 16, 2023

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.

@ryxli
Copy link

ryxli commented Jun 4, 2023

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

@bjajoh
Copy link
Author

bjajoh commented Jun 10, 2023

@ryxli It actually works! Thank you so much!

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

No branches or pull requests

3 participants