How to Use torch_directml GPU with Transformers.Trainer for Fine-Tuning?

Hello,

I’m trying to use a torch_directml device (GPU) for fine-tuning with the Transformers.Trainer from the Hugging Face library. However, I’ve noticed that the Trainer automatically switches to the CPU if neither a CUDA nor SMD device is available.

Even when I explicitly move the model to the DML device, it gets reverted to the CPU during training.

Is there a way to configure the Trainer to use a torch_directml device for fine-tuning? Any help or guidance would be much appreciated.

Thanks in advance!

1 Like