OpenNMT with "mps" instead of "cuda" on Mac os 12.6

After many research, I finally found a way of installing an access to the gpu from pytorch as mentioned on this page : https://towardsdatascience.com/installing-pytorch-on-apple-m1-chip-with-gpu-acceleration-3351dc44d67c in order to be able to use the GPU on my macbook. I now have a True return to the following : print(torch.backends.mps.is_built()) which

ensures that the current current PyTorch installation was built with MPS activated.

But once this is done, I don’t know where to go to change the torch.device as mentioned in the page :

To run PyTorch code on the GPU, use torch.device("mps") analogous to torch.device("cuda") on an Nvidia GPU.
When I try the training with the ende toy sample set, I still have the following error :

File “/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/torch/cuda/init.py”, line 350, in set_device
torch._C._cuda_setDevice(device)
^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: module ‘torch._C’ has no attribute ‘_cuda_setDevice’

I am navigating through the library files of python/…/onmt to locate the gpu_ranks and device_id, but I don’t know what to do.

Hopefully someone had the same problem and solved it.

Thank you