# How to set gpu device for hugging trainer?

**URL:** <https://discuss.huggingface.co/t/how-to-set-gpu-device-for-hugging-trainer/8327>\
**Category:** 🤗Transformers\
**Created:** [July 13, 2021, 8:36pm UTC](https://discuss.huggingface.co/t/how-to-set-gpu-device-for-hugging-trainer/8327 "2021-07-13T20:36:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rabiulawal](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/rabiulawal/32/2271_2.png) [@rabiulawal](https://discuss.huggingface.co/u/rabiulawal)\
**Post date:** [July 13, 2021, 8:36pm UTC](https://discuss.huggingface.co/t/how-to-set-gpu-device-for-hugging-trainer/8327/1 "2021-07-13T20:36:09Z")

</div>

I am trying to set gpu device for HF trainer. By default it uses device:0. I want to use a custom device. I tried using `torch.cuda.set_device()`. It does not work.

---

<div class="post-metadata">

**Author:** ![mayank64ce](https://avatars.discourse-cdn.com/v4/letter/m/0ea827/32.png) [@mayank64ce](https://discuss.huggingface.co/u/mayank64ce)\
**Post date:** [September 16, 2024, 4:18pm UTC](https://discuss.huggingface.co/t/how-to-set-gpu-device-for-hugging-trainer/8327/2 "2024-09-16T16:18:18Z")

</div>

Did you figure this out ?
