prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  MAE can't handle MPS backend
  ## 🐛 Bug
  
  The currently, the mean absolute error can't handle the MPS backend. This is a simple fix and just requires casting to .float()
  
  ### To Reproduce
  
  This works:
  
  ```python
  import torchmetrics
  import torch
  
  a = torch.tensor([1, 2, 3]).to(torch.device("mps"))
  
  acc = torchmetrics.Accuracy().to(torch.device("mps"))
  acc.update(a, a)
  acc.compute()
  ```
  
  this also works:
  
  ```
  a = torch.tensor([1, 2, 3])
  
  mae = torchmetrics.MeanAbsoluteError()
  mae.update(a, a)
  mae.compute()
  
  ```
  
  but this crashes
  
  ```python
  a = torch.tensor([1, 2, 3]).to(torch.device("mps"))
  
  mae = torchmetrics.MeanAbsoluteError().to(torch.device("mps"))
  mae.update(a, a)
  mae.compute()
  ```
  
  ```
  ---------------------------------------------------------------------------
  TypeError                                 Traceback (most recent call last)
  Input In [12], in <module>
        1 a = torch.tensor([1, 2, 3]).to(torch.device("mps"))
        3 acc = torchmetrics.MeanAbsoluteError().to(torch.device("mps"))
  ----> 4 acc.update(a, a)
        5 acc.compute()
  
  File ~/miniforge3/lib/python3.9/site-packages/torchmetrics/metric.py:391, in Metric._wrap_update.<locals>.wrapped_func(*args, **kwargs)
      389 with torch.set_grad_enabled(self._enable_grad):
      390     try:
  --> 391         update(*args, **kwargs)
      392     except RuntimeError as err:
      393         if "Expected all tensors to be on" in str(err):
  
  File ~/miniforge3/lib/python3.9/site-packages/torchmetrics/regression/mae.py:63, in MeanAbsoluteError.update(self, preds, target)
       56 def update(self, preds: Tensor, target: Tensor) -> None:  # type: ignore
       57     """Update state with predictions and targets.
       58 
       59     Args:
       60         preds: Predictions from model
       61         target: Ground truth values
       62     """
  ---> 63     sum_abs_error, n_obs = _mean_absolute_error_update(preds, target)
       65     self.sum_abs_error += sum_abs_error
       66     self.total += n_obs
  
  File ~/miniforge3/lib/python3.9/site-packages/torchmetrics/functional/regression/mae.py:33, in _mean_absolute_error_update(preds, target)
       23 """Updates and returns variables required to compute Mean Absolute Error.
       24 
       25 Checks for same shape of input tensors.
     (...)
       29     target: Ground truth tensor
       30 """
       32 _check_same_shape(preds, target)
  ---> 33 sum_abs_error = torch.sum(torch.abs(preds - target))
       34 n_obs = target.numel()
       35 return sum_abs_error, n_obs
  
  TypeError: Operation 'abs_out_mps()' does not support input type 'int64' in MPS backend.
  ```
  
  
  ### Environment
  
  ```
  torch       : 1.12.1
  lightning   : 2022.9.8
  torchmetrics: 0.9.3
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `src/torchmetrics/functional/regression/mae.py`
  Content:
  ```
  1 # Copyright The PyTorch Lightning team.
  2 #
  3 # Licensed under the Apache License, Version 2.0 (the "License");
  4 # you may not use this file except in compliance with the License.
  5 # You may obtain a copy of the License at
  6 #
  7 #     http://www.apache.org/licenses/LICENSE-2.0
  8 #
  9 # Unless required by applicable law or agreed to in writing, software
  10 # distributed under the License is distributed on an "AS IS" BASIS,
  11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 # See the License for the specific language governing permissions and
  13 # limitations under the License.
  14 from typing import Tuple
  15 
  16 import torch
  17 from torch import Tensor
  18 
  19 from torchmetrics.utilities.checks import _check_same_shape
  20 
  21 
  22 def _mean_absolute_error_update(preds: Tensor, target: Tensor) -> Tuple[Tensor, int]:
  23     """Updates and returns variables required to compute Mean Absolute Error.
  24 
  25     Checks for same shape of input tensors.
  26 
  27     Args:
  28         preds: Predicted tensor
  29         target: Ground truth tensor
  30     """
  31 
  32     _check_same_shape(preds, target)
  33     sum_abs_error = torch.sum(torch.abs(preds - target))
  34     n_obs = target.numel()
  35     return sum_abs_error, n_obs
  36 
  37 
  38 def _mean_absolute_error_compute(sum_abs_error: Tensor, n_obs: int) -> Tensor:
  39     """Computes Mean Absolute Error.
  40 
  41     Args:
  42         sum_abs_error: Sum of absolute value of errors over all observations
  43         n_obs: Number of predictions or observations
  44 
  45     Example:
  46         >>> preds = torch.tensor([0., 1, 2, 3])
  47         >>> target = torch.tensor([0., 1, 2, 2])
  48         >>> sum_abs_error, n_obs = _mean_absolute_error_update(preds, target)
  49         >>> _mean_absolute_error_compute(sum_abs_error, n_obs)
  50         tensor(0.2500)
  51     """
  52 
  53     return sum_abs_error / n_obs
  54 
  55 
  56 def mean_absolute_error(preds: Tensor, target: Tensor) -> Tensor:
  57     """Computes mean absolute error.
  58 
  59     Args:
  60         preds: estimated labels
  61         target: ground truth labels
  62 
  63     Return:
  64         Tensor with MAE
  65 
  66     Example:
  67         >>> from torchmetrics.functional import mean_absolute_error
  68         >>> x = torch.tensor([0., 1, 2, 3])
  69         >>> y = torch.tensor([0., 1, 2, 2])
  70         >>> mean_absolute_error(x, y)
  71         tensor(0.2500)
  72     """
  73     sum_abs_error, n_obs = _mean_absolute_error_update(preds, target)
  74     return _mean_absolute_error_compute(sum_abs_error, n_obs)
  75
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/src/torchmetrics/functional/regression/mae.py b/src/torchmetrics/functional/regression/mae.py
  --- a/src/torchmetrics/functional/regression/mae.py
  +++ b/src/torchmetrics/functional/regression/mae.py
  @@ -28,8 +28,9 @@
           preds: Predicted tensor
           target: Ground truth tensor
       """
  -
       _check_same_shape(preds, target)
  +    preds = preds if preds.is_floating_point else preds.float()
  +    target = target if target.is_floating_point else target.float()
       sum_abs_error = torch.sum(torch.abs(preds - target))
       n_obs = target.numel()
       return sum_abs_error, n_obs
  
verification_info: {"golden_diff": "diff --git a/src/torchmetrics/functional/regression/mae.py b/src/torchmetrics/functional/regression/mae.py\n--- a/src/torchmetrics/functional/regression/mae.py\n+++ b/src/torchmetrics/functional/regression/mae.py\n@@ -28,8 +28,9 @@\n         preds: Predicted tensor\n         target: Ground truth tensor\n     \"\"\"\n-\n     _check_same_shape(preds, target)\n+    preds = preds if preds.is_floating_point else preds.float()\n+    target = target if target.is_floating_point else target.float()\n     sum_abs_error = torch.sum(torch.abs(preds - target))\n     n_obs = target.numel()\n     return sum_abs_error, n_obs\n", "issue": "MAE can't handle MPS backend\n## \ud83d\udc1b Bug\r\n\r\nThe currently, the mean absolute error can't handle the MPS backend. This is a simple fix and just requires casting to .float()\r\n\r\n### To Reproduce\r\n\r\nThis works:\r\n\r\n```python\r\nimport torchmetrics\r\nimport torch\r\n\r\na = torch.tensor([1, 2, 3]).to(torch.device(\"mps\"))\r\n\r\nacc = torchmetrics.Accuracy().to(torch.device(\"mps\"))\r\nacc.update(a, a)\r\nacc.compute()\r\n```\r\n\r\nthis also works:\r\n\r\n```\r\na = torch.tensor([1, 2, 3])\r\n\r\nmae = torchmetrics.MeanAbsoluteError()\r\nmae.update(a, a)\r\nmae.compute()\r\n\r\n```\r\n\r\nbut this crashes\r\n\r\n```python\r\na = torch.tensor([1, 2, 3]).to(torch.device(\"mps\"))\r\n\r\nmae = torchmetrics.MeanAbsoluteError().to(torch.device(\"mps\"))\r\nmae.update(a, a)\r\nmae.compute()\r\n```\r\n\r\n```\r\n---------------------------------------------------------------------------\r\nTypeError                                 Traceback (most recent call last)\r\nInput In [12], in <module>\r\n      1 a = torch.tensor([1, 2, 3]).to(torch.device(\"mps\"))\r\n      3 acc = torchmetrics.MeanAbsoluteError().to(torch.device(\"mps\"))\r\n----> 4 acc.update(a, a)\r\n      5 acc.compute()\r\n\r\nFile ~/miniforge3/lib/python3.9/site-packages/torchmetrics/metric.py:391, in Metric._wrap_update.<locals>.wrapped_func(*args, **kwargs)\r\n    389 with torch.set_grad_enabled(self._enable_grad):\r\n    390     try:\r\n--> 391         update(*args, **kwargs)\r\n    392     except RuntimeError as err:\r\n    393         if \"Expected all tensors to be on\" in str(err):\r\n\r\nFile ~/miniforge3/lib/python3.9/site-packages/torchmetrics/regression/mae.py:63, in MeanAbsoluteError.update(self, preds, target)\r\n     56 def update(self, preds: Tensor, target: Tensor) -> None:  # type: ignore\r\n     57     \"\"\"Update state with predictions and targets.\r\n     58 \r\n     59     Args:\r\n     60         preds: Predictions from model\r\n     61         target: Ground truth values\r\n     62     \"\"\"\r\n---> 63     sum_abs_error, n_obs = _mean_absolute_error_update(preds, target)\r\n     65     self.sum_abs_error += sum_abs_error\r\n     66     self.total += n_obs\r\n\r\nFile ~/miniforge3/lib/python3.9/site-packages/torchmetrics/functional/regression/mae.py:33, in _mean_absolute_error_update(preds, target)\r\n     23 \"\"\"Updates and returns variables required to compute Mean Absolute Error.\r\n     24 \r\n     25 Checks for same shape of input tensors.\r\n   (...)\r\n     29     target: Ground truth tensor\r\n     30 \"\"\"\r\n     32 _check_same_shape(preds, target)\r\n---> 33 sum_abs_error = torch.sum(torch.abs(preds - target))\r\n     34 n_obs = target.numel()\r\n     35 return sum_abs_error, n_obs\r\n\r\nTypeError: Operation 'abs_out_mps()' does not support input type 'int64' in MPS backend.\r\n```\r\n\r\n\r\n### Environment\r\n\r\n```\r\ntorch       : 1.12.1\r\nlightning   : 2022.9.8\r\ntorchmetrics: 0.9.3\r\n```\r\n\n", "before_files": [{"content": "# Copyright The PyTorch Lightning team.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\nfrom typing import Tuple\n\nimport torch\nfrom torch import Tensor\n\nfrom torchmetrics.utilities.checks import _check_same_shape\n\n\ndef _mean_absolute_error_update(preds: Tensor, target: Tensor) -> Tuple[Tensor, int]:\n    \"\"\"Updates and returns variables required to compute Mean Absolute Error.\n\n    Checks for same shape of input tensors.\n\n    Args:\n        preds: Predicted tensor\n        target: Ground truth tensor\n    \"\"\"\n\n    _check_same_shape(preds, target)\n    sum_abs_error = torch.sum(torch.abs(preds - target))\n    n_obs = target.numel()\n    return sum_abs_error, n_obs\n\n\ndef _mean_absolute_error_compute(sum_abs_error: Tensor, n_obs: int) -> Tensor:\n    \"\"\"Computes Mean Absolute Error.\n\n    Args:\n        sum_abs_error: Sum of absolute value of errors over all observations\n        n_obs: Number of predictions or observations\n\n    Example:\n        >>> preds = torch.tensor([0., 1, 2, 3])\n        >>> target = torch.tensor([0., 1, 2, 2])\n        >>> sum_abs_error, n_obs = _mean_absolute_error_update(preds, target)\n        >>> _mean_absolute_error_compute(sum_abs_error, n_obs)\n        tensor(0.2500)\n    \"\"\"\n\n    return sum_abs_error / n_obs\n\n\ndef mean_absolute_error(preds: Tensor, target: Tensor) -> Tensor:\n    \"\"\"Computes mean absolute error.\n\n    Args:\n        preds: estimated labels\n        target: ground truth labels\n\n    Return:\n        Tensor with MAE\n\n    Example:\n        >>> from torchmetrics.functional import mean_absolute_error\n        >>> x = torch.tensor([0., 1, 2, 3])\n        >>> y = torch.tensor([0., 1, 2, 2])\n        >>> mean_absolute_error(x, y)\n        tensor(0.2500)\n    \"\"\"\n    sum_abs_error, n_obs = _mean_absolute_error_update(preds, target)\n    return _mean_absolute_error_compute(sum_abs_error, n_obs)\n", "path": "src/torchmetrics/functional/regression/mae.py"}], "after_files": [{"content": "# Copyright The PyTorch Lightning team.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#     http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\nfrom typing import Tuple\n\nimport torch\nfrom torch import Tensor\n\nfrom torchmetrics.utilities.checks import _check_same_shape\n\n\ndef _mean_absolute_error_update(preds: Tensor, target: Tensor) -> Tuple[Tensor, int]:\n    \"\"\"Updates and returns variables required to compute Mean Absolute Error.\n\n    Checks for same shape of input tensors.\n\n    Args:\n        preds: Predicted tensor\n        target: Ground truth tensor\n    \"\"\"\n    _check_same_shape(preds, target)\n    preds = preds if preds.is_floating_point else preds.float()\n    target = target if target.is_floating_point else target.float()\n    sum_abs_error = torch.sum(torch.abs(preds - target))\n    n_obs = target.numel()\n    return sum_abs_error, n_obs\n\n\ndef _mean_absolute_error_compute(sum_abs_error: Tensor, n_obs: int) -> Tensor:\n    \"\"\"Computes Mean Absolute Error.\n\n    Args:\n        sum_abs_error: Sum of absolute value of errors over all observations\n        n_obs: Number of predictions or observations\n\n    Example:\n        >>> preds = torch.tensor([0., 1, 2, 3])\n        >>> target = torch.tensor([0., 1, 2, 2])\n        >>> sum_abs_error, n_obs = _mean_absolute_error_update(preds, target)\n        >>> _mean_absolute_error_compute(sum_abs_error, n_obs)\n        tensor(0.2500)\n    \"\"\"\n\n    return sum_abs_error / n_obs\n\n\ndef mean_absolute_error(preds: Tensor, target: Tensor) -> Tensor:\n    \"\"\"Computes mean absolute error.\n\n    Args:\n        preds: estimated labels\n        target: ground truth labels\n\n    Return:\n        Tensor with MAE\n\n    Example:\n        >>> from torchmetrics.functional import mean_absolute_error\n        >>> x = torch.tensor([0., 1, 2, 3])\n        >>> y = torch.tensor([0., 1, 2, 2])\n        >>> mean_absolute_error(x, y)\n        tensor(0.2500)\n    \"\"\"\n    sum_abs_error, n_obs = _mean_absolute_error_update(preds, target)\n    return _mean_absolute_error_compute(sum_abs_error, n_obs)\n", "path": "src/torchmetrics/functional/regression/mae.py"}]}