Repository navigation
Closed
Description
I'm trying to experiment with DS/1gpu and it's not respecting CUDA_VISIBLE_DEVICES
I run the script as:
CUDA_VISIBLE_DEVICES=1 deepspeed --num_gpus=1 ./finetune_trainer.py ...
but it runs on GPU 0 ignoring CUDA_VISIBLE_DEVICES=1
Then I tried to use deepspeed launcher flags as explained here: https://www.deepspeed.ai/getting-started/#resource-configuration-multi-node and encountered multiple issues there:
- I think the
--hostfilecl arg in the example are in the wrong place, shouldn't they be right afterdeepspeedand not in the client's args? that is instead of:
deepspeed <client_entry.py> <client args> \
--deepspeed --deepspeed_config ds_config.json --hostfile=myhostfile
deepspeed --hostfile=myhostfile <client_entry.py> <client args> \
--deepspeed --deepspeed_config ds_config.json
This is a launcher arg and not client arg.
- it can't handle hostfile with 1 entry:
$ cat hostfile
worker-1 slots=2
$ deepspeed --hostfile hostfile ./finetune_trainer.py ...
Traceback (most recent call last):
File "/home/stas/anaconda3/envs/main-38/bin/deepspeed", line 7, in <module>
exec(compile(f.read(), __file__, 'exec'))
File "/mnt/nvme1/code/github/00optimize/DeepSpeed/bin/deepspeed", line 6, in <module>
main()
File "/mnt/nvme1/code/github/00optimize/DeepSpeed/deepspeed/launcher/runner.py", line 259, in main
resource_pool = fetch_hostfile(args.hostfile)
File "/mnt/nvme1/code/github/00optimize/DeepSpeed/deepspeed/launcher/runner.py", line 133, in fetch_hostfile
raise err
File "/mnt/nvme1/code/github/00optimize/DeepSpeed/deepspeed/launcher/runner.py", line 127, in fetch_hostfile
hostname, slots = line.split()
ValueError: not enough values to unpack (expected 2, got 0)
- it can't handle exclusion or inclusions w/o the hostfile (misleading docs)
Copy-n-pasting from docs - very last code example:
$ deepspeed --exclude="worker-1:0" ./finetune_trainer.py
Traceback (most recent call last):
File "/home/stas/anaconda3/envs/main-38/bin/deepspeed", line 7, in <module>
exec(compile(f.read(), __file__, 'exec'))
File "/mnt/nvme1/code/github/00optimize/DeepSpeed/bin/deepspeed", line 6, in <module>
main()
File "/mnt/nvme1/code/github/00optimize/DeepSpeed/deepspeed/launcher/runner.py", line 272, in main
active_resources = parse_inclusion_exclusion(resource_pool,
File "/mnt/nvme1/code/github/00optimize/DeepSpeed/deepspeed/launcher/runner.py", line 240, in parse_inclusion_exclusion
return parse_resource_filter(active_resources,
File "/mnt/nvme1/code/github/00optimize/DeepSpeed/deepspeed/launcher/runner.py", line 187, in parse_resource_filter
raise ValueError("Hostname '{}' not found in hostfile".format(hostname))
ValueError: Hostname 'worker-1' not found in hostfile
I think the docs are wrong/misleading - they suggest:
You can instead include or exclude specific resources using the --include and --exclude flags. For example, to use all available resources except GPU 0 on node worker-2 and GPUs 0 and 1 on worker-3:
- but they don't specify that the hostfile is actually needed.
- and the error message is misleading since what
hostfileis it talking about? I haven't passed it any hostfiles in this experiment and if it found it in the current dir, that hostfile does haveworker-1in it - seecat hostfileearlier. So it should not just say "in hostfile" butin /path/to/hostfile - I think in this particular situation it should say: "hostfile hasn't been provided and it's required"
- this is not the right solution since it tries to ssh to worker-1
subprocess.CalledProcessError: Command '['ssh worker-1 hostname -I']' returned non-zero exit status 255.
So how does one configure deepspeed to use a specific GPU on a single node?
Thank you!
Reacted by eval, barriery and Wai Kei
Reacted by Sangmin Woo
Metadata
Metadata
Assignees
Labels
No labels
Activity
jeffra commentedon Jan 14, 2021
Thanks for reporting this @stas00. There are a few different things going on here, let me try and address all of them here (if I miss one please let me know haha).
If you do not provide the deepspeed launcher with a hostfile (via
-H/--hostfile) it will only launch processes within that local node. We will try to discover all the available GPUs on the box viatorch.cuda.device_count(), see here for more details on this logic. Going forward the local node would be referred to aslocalhost.The deepspeed launcher was primarily written to simplify multi-node training in interactive training environments. It supports arbitrary inclusion/exclusion of gpus/nodes. For example, I may want to exclude just the 3rd gpu on node 5 (maybe it has ECC errors) out of a total of 128 gpus and 32 nodes. This would be achieved via
deepspeed --exclude worker-5:3 train.py.In order to support this arbitrary inclusion/exclusion our launcher sets the appropriate
CUDA_VISIBLE_DEVICESat process launch time on each node. This means that if the user sets their ownCUDA_VISIBLE_DEVICESon the launching node it's not clear if they want to set this value on the local node or all nodes. We should update our docs to make this more clear though.If you wanted to do something like
CUDA_VISIBLE_DEVICES=1 deepspeed --num_gpus=1 ./finetune_trainer.py ...I would recommend running this asdeepspeed --include localhost:1 ./finetune_trainer.py ....Now if you wanted to use a
hostfileto define your node list (even just 1 node) you can do that like you have. However, after seeing your ValueError stack trace I think you may have a trailing new-line at the end of the file. It seems our code was not tested with this case and it causes it to crash. I've submitted a PR to handle this case gracefully (see #669).I think maybe one of the key missing pieces in our doc is our decision to reference the local node as
localhostif no hostfile is given. So in the case ofdeepspeed --exclude="worker-1:0" ./finetune_trainer.pyif you added your abovehostfileI think it should work the way you want.stas00 commentedon Jan 15, 2021
As I don't have access to any clusters as of yet, I'm happy to just focus on the direct necessity of being able to specify which gpu to run on.
Yes, that worked! Awesome!
Could we please document that or I could make a PR to add it to the launcher doc if it will save your time.
BTW, I tried first:
as I had it already in the script and it crashed with:
So ideally the launcher should detect such situation and tell the user to not set
CUDA_VISIBLE_DEVICES.I also tried to add a
hostfilewithlocalhost slots=2and it tries to ssh to it.I'd say documenting:
as a way to run a specific single GPU on a local host is all that is needed.
You're spot on! I used
nanoand it can't help but leave extraneous new lines. I fixed that and it worked, but your PR is definitely a goodness. Not really needing at the moment but I'd add skipping commented out lines too.And as I mentioned in OP item 1. I think the --hostfile cl arg in the documentation example is in the wrong place
[doc] launcher
[doc] launcher (#868)
merge changes from deepspeed master (#24)
Merge Changes from DS Master (#30)
skpig commentedon Feb 10, 2022
@jeffra Thanks.
--include local:3can setCUDA_VISIBLE_DEVICES=3properly. However, theenginereturned bydeepspeed.initializeis on the wrong device.Here is my code:
And I launch the code above with
deepspeed --include="localhost:3" train.py --deepspeed --deepspeed_config config.jsonI'm willing to run the model on device 3, but the engine is on device 0.
stas00 commentedon Feb 10, 2022
@skpig, if I may recommend opening a new Issue - it'd help with tracking and making sure your bug report doesn't fall between the cracks - as this Issue has been closed.
skpig commentedon Feb 11, 2022
@stas00 Thank you for your advice. I have already opened a new issue #1761.
DS deepspeedai#4993 deepspeedai#662 : autotune single node hostfile b…
oushu1zhangxiangxuan1 commentedon Jan 23, 2024
I fixed #4993 of Autotune hostfile not found bug in PR #4996, can this help you?
DS deepspeedai#4993 deepspeedai#662 : autotune single node hostfile b…
DS #4993 #662 : autotune single node hostfile bugfix (#4996)
DS deepspeedai#4993 deepspeedai#662 : autotune single node hostfile b…
DS deepspeedai#4993 deepspeedai#662 : autotune single node hostfile b…