Add support for MacOS Apple Metal "mps" backend
See original GitHub issueSystem Info
MacOS, M1 architecture, Python 3.10, Pytorch 1.12 nightly, Transformers latest (4.19.2)
Who can help?
No response
Information
- The official example scripts
- My own modified scripts
Tasks
- An officially supported task in the
examples
folder (such as GLUE/SQuAD, …) - My own task or dataset (give details below)
Reproduction
Try to set backend to newly released “mps” backend (Apple Metal) in Pytorch.
from transformers import pipeline
classifier = pipeline("sentiment-analysis")
classifier.device = "mps"
classifier("We are very sad to mps backend is not supporter in Transformers.")
Expected behavior
Transformers should run on the GPU.
Instead, an error is thrown.
File ~/miniforge3/envs/pytorch-nightly/lib/python3.10/site-packages/transformers/pipelines/base.py:826, in Pipeline.device_placement(self)
824 yield
825 else:
--> 826 if self.device.type == "cuda":
827 torch.cuda.set_device(self.device)
829 yield
AttributeError: 'str' object has no attribute 'type'
Issue Analytics
- State:
- Created a year ago
- Reactions:7
- Comments:10 (5 by maintainers)
Top Results From Across the Web
Accelerated PyTorch training on Mac - Metal - Apple Developer
PyTorch uses the new Metal Performance Shaders (MPS) backend for GPU training ... The MPS backend support is part of the PyTorch 1.12...
Read more >Accelerated PyTorch Training on Mac - Hugging Face
Apple's Metal Performance Shaders (MPS) as a backend for PyTorch enables this and can be used via the new "mps" device. This will...
Read more >Setting up PyTorch on Mac M1 GPUs (Apple Metal / MPS)
The new MPS backend extends the PyTorch ecosystem and provides existing scripts capabilities to setup and run operations on GPU.
Read more >Installing and running pytorch on M1 GPUs (Apple metal/MPS)
Hey everyone! In this article I'll help you install pytorch for GPU acceleration on Apple's M1 chips. Let's crunch some tensors on Apple...
Read more >Enable Training on Apple Silicon Processors in PyTorch
... of this year, PyTorch added experimental support for the Apple Silicon processors through the Metal Performance Shaders (MPS) backend.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, you can now do:
Not sure how/when TF is going to add support, but we’ll figure out a way to enable this cross library too afterwards.
Unfortunately, as evidenced in the output, the PyTorch MPS backend is still very much broken. Even a lot of basic operations do not work correctly. For example:
So, it’s unlikely that you can use it yet, until the Torch maintainers shake out some bugs.