Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report: MPS backend is working fine #187

Open
KanTakahiro opened this issue Jun 6, 2024 · 1 comment
Open

Report: MPS backend is working fine #187

KanTakahiro opened this issue Jun 6, 2024 · 1 comment

Comments

@KanTakahiro
Copy link

I just add some codes for using BERTScore on Apple Silicon and it works fine. I think MPS support should be add to the code base for Mac users' convenience.

I tested MPS backend by this:
score(candidates, references, lang="ja", device="mps")

Basically I added MPS detection code below every CUDA detection code.

in score.py:

    if device is None:
        device = "cuda" if torch.cuda.is_available() else "cpu"
        device = "mps" if torch.backends.mps.is_available() else "cpu"    # added to line 101
    model.to(device)
    device = "cuda" if torch.cuda.is_available() else "cpu"
    device = "mps" if torch.backends.mps.is_available() else "cpu"    # added to line 242
    model.to(device)

in scorer.py:

        if device is None:
            self.device = "cuda" if torch.cuda.is_available() else "cpu"
            self.device = "mps" if torch.backends.mps.is_available() else "cpu"    # added to line 74
        else:
            self.device = device

in utils.py:

    device = "mps" if torch.backends.mps.is_available() else "cpu"    # added to line 409 & 446 & 605

My environment:

Apple M1
macOS 14.5
Python 3.12
torch 2.3.0
bert-score 0.3.13
@carloalbertobono
Copy link

Very Nice, I can also confirm this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants