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

Remove .double from perplexity_compute #206

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

peter-tk-tran
Copy link

Summary:
MPS requires F32 but .double casts the output back to F64 which causes it to fail

Example:

import torch
from torcheval.metrics.text import Perplexity

device = torch.device("mps")
logits = torch.Tensor([[[1, 9], [2, 3]]]).to(device)
labels = torch.Tensor([[0, 1]]).int().to(device)

perplexity = Perplexity().to(torch.float32).to(device)
perplexity.update(logits, labels)
print(perplexity.compute())
  File "/Users/petertran/torcheval/torcheval/metrics/text/perplexity.py", line 121, in compute
    return _perplexity_compute(self.sum_log_probs, self.num_total)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/petertran/torcheval/torcheval/metrics/functional/text/perplexity.py", line 117, in _perplexity_compute
    return torch.exp(sum_log_probs / num_total).double()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: Cannot convert a MPS Tensor to float64 dtype as the MPS framework doesn't support float64. Please use float32 instead.

MPS requires F32 but `.double` casts the output back to F64 which
causes it to fail
@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants