# Trainer.train() hangs with multiple GPUs (but GPUs show activity)

**URL:** <https://discuss.huggingface.co/t/trainer-train-hangs-with-multiple-gpus-but-gpus-show-activity/81763>\
**Category:** Beginners\
**Created:** [April 15, 2024, 3:32am UTC](https://discuss.huggingface.co/t/trainer-train-hangs-with-multiple-gpus-but-gpus-show-activity/81763 "2024-04-15T03:32:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![grillbikecheerfully](https://avatars.discourse-cdn.com/v4/letter/g/ce73a5/32.png) [@grillbikecheerfully](https://discuss.huggingface.co/u/grillbikecheerfully)\
**Post date:** [April 15, 2024, 3:32am UTC](https://discuss.huggingface.co/t/trainer-train-hangs-with-multiple-gpus-but-gpus-show-activity/81763/1 "2024-04-15T03:32:05Z")

</div>

I’m going through the huggingface tutorials and going through the [“Training a causal language model from scratch”](https://huggingface.co/learn/nlp-course/chapter7/6) sections.

That page says “If you have access to a machine with multiple GPUs, try to run the code there. The `Trainer` automatically manages multiple machines, and this can speed up training tremendously.”

I’m working on a machine with 8 GPUs, and unfortunately, it doesn’t seem to work for me. When I set the CUDA\_VISIBLE\_DEVICES environment variable to “0”, it works perfectly fine on one GPU. However, if I don’t set that environment variable, or set it to more than 1 GPU, the following happens

- All the relevant GPUs specified in CUDA\_VISIBLE\_DEVICES seem to fire at 100% utitlization
- The tqdm progress bar in my script doesn’t move, even after hours (it moves quite quickly with one GPU)

So it seems like the jobs are correctly _sent_ to the GPUs (I imagine…) but the central process isn’t… receiving the answers?

I assume there’s some additional config I need, but I can’t for the life of me find anythig in the docs that says what. I tried to run accelerate config on the command line, but no good.

Also, when I print `trainer.args.parallel_mode` right before training, I get `ParallelMode.NOT_DISTRIBUTED`.

Thanks a million for the help!!

---

<div class="post-metadata">

**Author:** ![LetsHugItOut](https://avatars.discourse-cdn.com/v4/letter/l/278dde/32.png) [@LetsHugItOut](https://discuss.huggingface.co/u/LetsHugItOut)\
**Post date:** [October 30, 2024, 5:18pm UTC](https://discuss.huggingface.co/t/trainer-train-hangs-with-multiple-gpus-but-gpus-show-activity/81763/2 "2024-10-30T17:18:35Z")

</div>

Did you find an answer?

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [October 30, 2024, 11:45pm UTC](https://discuss.huggingface.co/t/trainer-train-hangs-with-multiple-gpus-but-gpus-show-activity/81763/3 "2024-10-30T23:45:14Z")

</div>

There seem to be many problems that occur with trainers when using multiple GPUs.  
[https://discuss.huggingface.co/search?q=multi%20gpu%20trainer%20order%3Alatest](https://discuss.huggingface.co/search?q=multi%20gpu%20trainer%20order%3Alatest)

---

<div class="post-metadata">

**Author:** ![grillbikecheerfully](https://avatars.discourse-cdn.com/v4/letter/g/ce73a5/32.png) [@grillbikecheerfully](https://discuss.huggingface.co/u/grillbikecheerfully)\
**Post date:** [October 31, 2024, 1:13am UTC](https://discuss.huggingface.co/t/trainer-train-hangs-with-multiple-gpus-but-gpus-show-activity/81763/4 "2024-10-31T01:13:40Z")

</div>

Unfortunately I never did - apologies ☹ I ended up moving to another server with 8 GPUs, and it magically work, so I can only assume it was something to do with the way the 8 GPUs were set up on the first machine.

---

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [October 31, 2024, 1:38am UTC](https://discuss.huggingface.co/t/trainer-train-hangs-with-multiple-gpus-but-gpus-show-activity/81763/5 "2024-10-31T01:38:39Z")

</div>

Is this the kind of hardware problem? Anyway, I guess there was a workaround.

> **[Solving DDP deadlock with multiple GPUs and AMD CPUs](https://medium.com/@amitparekh/solving-ddp-deadlock-with-multiple-gpus-and-amd-cpus-442186632034)**
>
> If using DDP is causing deadlocks and you feel like you’ve tried everything, it might be caused by IOMMU.
