prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  ClasswiseWrapper yields different results 
  ## 🐛 Bug
  
  Using `JaccardIndex` with  `ClasswiseWrapper` results in different values than without `ClasswiseWrapper`. 
  
  ### To Reproduce
  
  Steps to reproduce the behavior...
  
  Run the code snippet. 
  
  #### Code sample
  
  ```python
  from torchmetrics import ClasswiseWrapper, JaccardIndex
  import torch 
  
  target = torch.randint(0, 2, (10, 25, 25))
  preds = [ torch.randint(0, 2, (10, 25, 25)) for i in range (3)]
  jaccard_single = JaccardIndex(num_classes=2, average=None)
  class_wrapper = ClasswiseWrapper(
          JaccardIndex(num_classes=2, average=None),
          labels=["class1", "class2"]
      )
  
  for p in preds:
      print("Metric ",jaccard_single(p,target))    
      print("Wraped metric ",class_wrapper(p,target))
  ```
  
  The code produces the following output: 
  
  ```
  Metric  tensor([0.3351, 0.3333])
  Wraped metric  {'jaccardindex_class1': tensor(0.3351), 'jaccardindex_class2': tensor(0.3333)}
  Metric  tensor([0.3293, 0.3357])
  Wraped metric  {'jaccardindex_class1': tensor(0.3322), 'jaccardindex_class2': tensor(0.3345)}
  Metric  tensor([0.3424, 0.3435])
  Wraped metric  {'jaccardindex_class1': tensor(0.3356), 'jaccardindex_class2': tensor(0.3375)}
  ```
  
  ### Expected behavior
  
  I would expect that the wrapped metric outputs the same values as the simple `JaccardIndex`. 
  
  ### Environment
  
  - TorchMetrics version (and how you installed TM, e.g. `conda`, `pip`, build from source): 
   Installed version 0.9.2 using pip 
  - Python & PyTorch Version (e.g., 1.0):
   Tested with Python 3.8.14 and pytorch 1.3.1
  - Any other relevant information such as OS (e.g., Linux):
  
  ### Additional context
  
  <!-- Add any other context about the problem here. -->
  
  
  --- 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/wrappers/classwise.py`
  Content:
  ```
  1 from typing import Any, Dict, List, Optional
  2 
  3 from torch import Tensor
  4 
  5 from torchmetrics import Metric
  6 
  7 
  8 class ClasswiseWrapper(Metric):
  9     """Wrapper class for altering the output of classification metrics that returns multiple values to include
  10     label information.
  11 
  12     Args:
  13         metric: base metric that should be wrapped. It is assumed that the metric outputs a single
  14             tensor that is split along the first dimension.
  15         labels: list of strings indicating the different classes.
  16 
  17     Example:
  18         >>> import torch
  19         >>> _ = torch.manual_seed(42)
  20         >>> from torchmetrics import Accuracy, ClasswiseWrapper
  21         >>> metric = ClasswiseWrapper(Accuracy(num_classes=3, average=None))
  22         >>> preds = torch.randn(10, 3).softmax(dim=-1)
  23         >>> target = torch.randint(3, (10,))
  24         >>> metric(preds, target)
  25         {'accuracy_0': tensor(0.5000), 'accuracy_1': tensor(0.7500), 'accuracy_2': tensor(0.)}
  26 
  27     Example (labels as list of strings):
  28         >>> import torch
  29         >>> from torchmetrics import Accuracy, ClasswiseWrapper
  30         >>> metric = ClasswiseWrapper(
  31         ...    Accuracy(num_classes=3, average=None),
  32         ...    labels=["horse", "fish", "dog"]
  33         ... )
  34         >>> preds = torch.randn(10, 3).softmax(dim=-1)
  35         >>> target = torch.randint(3, (10,))
  36         >>> metric(preds, target)
  37         {'accuracy_horse': tensor(0.3333), 'accuracy_fish': tensor(0.6667), 'accuracy_dog': tensor(0.)}
  38 
  39     Example (in metric collection):
  40         >>> import torch
  41         >>> from torchmetrics import Accuracy, ClasswiseWrapper, MetricCollection, Recall
  42         >>> labels = ["horse", "fish", "dog"]
  43         >>> metric = MetricCollection(
  44         ...     {'accuracy': ClasswiseWrapper(Accuracy(num_classes=3, average=None), labels),
  45         ...     'recall': ClasswiseWrapper(Recall(num_classes=3, average=None), labels)}
  46         ... )
  47         >>> preds = torch.randn(10, 3).softmax(dim=-1)
  48         >>> target = torch.randint(3, (10,))
  49         >>> metric(preds, target)  # doctest: +NORMALIZE_WHITESPACE
  50         {'accuracy_horse': tensor(0.), 'accuracy_fish': tensor(0.3333), 'accuracy_dog': tensor(0.4000),
  51         'recall_horse': tensor(0.), 'recall_fish': tensor(0.3333), 'recall_dog': tensor(0.4000)}
  52     """
  53 
  54     def __init__(self, metric: Metric, labels: Optional[List[str]] = None) -> None:
  55         super().__init__()
  56         if not isinstance(metric, Metric):
  57             raise ValueError(f"Expected argument `metric` to be an instance of `torchmetrics.Metric` but got {metric}")
  58         if labels is not None and not (isinstance(labels, list) and all(isinstance(lab, str) for lab in labels)):
  59             raise ValueError(f"Expected argument `labels` to either be `None` or a list of strings but got {labels}")
  60         self.metric = metric
  61         self.labels = labels
  62 
  63     def _convert(self, x: Tensor) -> Dict[str, Any]:
  64         name = self.metric.__class__.__name__.lower()
  65         if self.labels is None:
  66             return {f"{name}_{i}": val for i, val in enumerate(x)}
  67         return {f"{name}_{lab}": val for lab, val in zip(self.labels, x)}
  68 
  69     def update(self, *args: Any, **kwargs: Any) -> None:
  70         self.metric.update(*args, **kwargs)
  71 
  72     def compute(self) -> Dict[str, Tensor]:
  73         return self._convert(self.metric.compute())
  74
  ```
  --- 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/wrappers/classwise.py b/src/torchmetrics/wrappers/classwise.py
  --- a/src/torchmetrics/wrappers/classwise.py
  +++ b/src/torchmetrics/wrappers/classwise.py
  @@ -51,6 +51,8 @@
           'recall_horse': tensor(0.), 'recall_fish': tensor(0.3333), 'recall_dog': tensor(0.4000)}
       """
   
  +    full_state_update: Optional[bool] = True
  +
       def __init__(self, metric: Metric, labels: Optional[List[str]] = None) -> None:
           super().__init__()
           if not isinstance(metric, Metric):
  @@ -71,3 +73,6 @@
   
       def compute(self) -> Dict[str, Tensor]:
           return self._convert(self.metric.compute())
  +
  +    def reset(self) -> None:
  +        self.metric.reset()
  
verification_info: {"golden_diff": "diff --git a/src/torchmetrics/wrappers/classwise.py b/src/torchmetrics/wrappers/classwise.py\n--- a/src/torchmetrics/wrappers/classwise.py\n+++ b/src/torchmetrics/wrappers/classwise.py\n@@ -51,6 +51,8 @@\n         'recall_horse': tensor(0.), 'recall_fish': tensor(0.3333), 'recall_dog': tensor(0.4000)}\n     \"\"\"\n \n+    full_state_update: Optional[bool] = True\n+\n     def __init__(self, metric: Metric, labels: Optional[List[str]] = None) -> None:\n         super().__init__()\n         if not isinstance(metric, Metric):\n@@ -71,3 +73,6 @@\n \n     def compute(self) -> Dict[str, Tensor]:\n         return self._convert(self.metric.compute())\n+\n+    def reset(self) -> None:\n+        self.metric.reset()\n", "issue": "ClasswiseWrapper yields different results \n## \ud83d\udc1b Bug\r\n\r\nUsing `JaccardIndex` with  `ClasswiseWrapper` results in different values than without `ClasswiseWrapper`. \r\n\r\n### To Reproduce\r\n\r\nSteps to reproduce the behavior...\r\n\r\nRun the code snippet. \r\n\r\n#### Code sample\r\n\r\n```python\r\nfrom torchmetrics import ClasswiseWrapper, JaccardIndex\r\nimport torch \r\n\r\ntarget = torch.randint(0, 2, (10, 25, 25))\r\npreds = [ torch.randint(0, 2, (10, 25, 25)) for i in range (3)]\r\njaccard_single = JaccardIndex(num_classes=2, average=None)\r\nclass_wrapper = ClasswiseWrapper(\r\n        JaccardIndex(num_classes=2, average=None),\r\n        labels=[\"class1\", \"class2\"]\r\n    )\r\n\r\nfor p in preds:\r\n    print(\"Metric \",jaccard_single(p,target))    \r\n    print(\"Wraped metric \",class_wrapper(p,target))\r\n```\r\n\r\nThe code produces the following output: \r\n\r\n```\r\nMetric  tensor([0.3351, 0.3333])\r\nWraped metric  {'jaccardindex_class1': tensor(0.3351), 'jaccardindex_class2': tensor(0.3333)}\r\nMetric  tensor([0.3293, 0.3357])\r\nWraped metric  {'jaccardindex_class1': tensor(0.3322), 'jaccardindex_class2': tensor(0.3345)}\r\nMetric  tensor([0.3424, 0.3435])\r\nWraped metric  {'jaccardindex_class1': tensor(0.3356), 'jaccardindex_class2': tensor(0.3375)}\r\n```\r\n\r\n### Expected behavior\r\n\r\nI would expect that the wrapped metric outputs the same values as the simple `JaccardIndex`. \r\n\r\n### Environment\r\n\r\n- TorchMetrics version (and how you installed TM, e.g. `conda`, `pip`, build from source): \r\n Installed version 0.9.2 using pip \r\n- Python & PyTorch Version (e.g., 1.0):\r\n Tested with Python 3.8.14 and pytorch 1.3.1\r\n- Any other relevant information such as OS (e.g., Linux):\r\n\r\n### Additional context\r\n\r\n<!-- Add any other context about the problem here. -->\r\n\n", "before_files": [{"content": "from typing import Any, Dict, List, Optional\n\nfrom torch import Tensor\n\nfrom torchmetrics import Metric\n\n\nclass ClasswiseWrapper(Metric):\n    \"\"\"Wrapper class for altering the output of classification metrics that returns multiple values to include\n    label information.\n\n    Args:\n        metric: base metric that should be wrapped. It is assumed that the metric outputs a single\n            tensor that is split along the first dimension.\n        labels: list of strings indicating the different classes.\n\n    Example:\n        >>> import torch\n        >>> _ = torch.manual_seed(42)\n        >>> from torchmetrics import Accuracy, ClasswiseWrapper\n        >>> metric = ClasswiseWrapper(Accuracy(num_classes=3, average=None))\n        >>> preds = torch.randn(10, 3).softmax(dim=-1)\n        >>> target = torch.randint(3, (10,))\n        >>> metric(preds, target)\n        {'accuracy_0': tensor(0.5000), 'accuracy_1': tensor(0.7500), 'accuracy_2': tensor(0.)}\n\n    Example (labels as list of strings):\n        >>> import torch\n        >>> from torchmetrics import Accuracy, ClasswiseWrapper\n        >>> metric = ClasswiseWrapper(\n        ...    Accuracy(num_classes=3, average=None),\n        ...    labels=[\"horse\", \"fish\", \"dog\"]\n        ... )\n        >>> preds = torch.randn(10, 3).softmax(dim=-1)\n        >>> target = torch.randint(3, (10,))\n        >>> metric(preds, target)\n        {'accuracy_horse': tensor(0.3333), 'accuracy_fish': tensor(0.6667), 'accuracy_dog': tensor(0.)}\n\n    Example (in metric collection):\n        >>> import torch\n        >>> from torchmetrics import Accuracy, ClasswiseWrapper, MetricCollection, Recall\n        >>> labels = [\"horse\", \"fish\", \"dog\"]\n        >>> metric = MetricCollection(\n        ...     {'accuracy': ClasswiseWrapper(Accuracy(num_classes=3, average=None), labels),\n        ...     'recall': ClasswiseWrapper(Recall(num_classes=3, average=None), labels)}\n        ... )\n        >>> preds = torch.randn(10, 3).softmax(dim=-1)\n        >>> target = torch.randint(3, (10,))\n        >>> metric(preds, target)  # doctest: +NORMALIZE_WHITESPACE\n        {'accuracy_horse': tensor(0.), 'accuracy_fish': tensor(0.3333), 'accuracy_dog': tensor(0.4000),\n        'recall_horse': tensor(0.), 'recall_fish': tensor(0.3333), 'recall_dog': tensor(0.4000)}\n    \"\"\"\n\n    def __init__(self, metric: Metric, labels: Optional[List[str]] = None) -> None:\n        super().__init__()\n        if not isinstance(metric, Metric):\n            raise ValueError(f\"Expected argument `metric` to be an instance of `torchmetrics.Metric` but got {metric}\")\n        if labels is not None and not (isinstance(labels, list) and all(isinstance(lab, str) for lab in labels)):\n            raise ValueError(f\"Expected argument `labels` to either be `None` or a list of strings but got {labels}\")\n        self.metric = metric\n        self.labels = labels\n\n    def _convert(self, x: Tensor) -> Dict[str, Any]:\n        name = self.metric.__class__.__name__.lower()\n        if self.labels is None:\n            return {f\"{name}_{i}\": val for i, val in enumerate(x)}\n        return {f\"{name}_{lab}\": val for lab, val in zip(self.labels, x)}\n\n    def update(self, *args: Any, **kwargs: Any) -> None:\n        self.metric.update(*args, **kwargs)\n\n    def compute(self) -> Dict[str, Tensor]:\n        return self._convert(self.metric.compute())\n", "path": "src/torchmetrics/wrappers/classwise.py"}], "after_files": [{"content": "from typing import Any, Dict, List, Optional\n\nfrom torch import Tensor\n\nfrom torchmetrics import Metric\n\n\nclass ClasswiseWrapper(Metric):\n    \"\"\"Wrapper class for altering the output of classification metrics that returns multiple values to include\n    label information.\n\n    Args:\n        metric: base metric that should be wrapped. It is assumed that the metric outputs a single\n            tensor that is split along the first dimension.\n        labels: list of strings indicating the different classes.\n\n    Example:\n        >>> import torch\n        >>> _ = torch.manual_seed(42)\n        >>> from torchmetrics import Accuracy, ClasswiseWrapper\n        >>> metric = ClasswiseWrapper(Accuracy(num_classes=3, average=None))\n        >>> preds = torch.randn(10, 3).softmax(dim=-1)\n        >>> target = torch.randint(3, (10,))\n        >>> metric(preds, target)\n        {'accuracy_0': tensor(0.5000), 'accuracy_1': tensor(0.7500), 'accuracy_2': tensor(0.)}\n\n    Example (labels as list of strings):\n        >>> import torch\n        >>> from torchmetrics import Accuracy, ClasswiseWrapper\n        >>> metric = ClasswiseWrapper(\n        ...    Accuracy(num_classes=3, average=None),\n        ...    labels=[\"horse\", \"fish\", \"dog\"]\n        ... )\n        >>> preds = torch.randn(10, 3).softmax(dim=-1)\n        >>> target = torch.randint(3, (10,))\n        >>> metric(preds, target)\n        {'accuracy_horse': tensor(0.3333), 'accuracy_fish': tensor(0.6667), 'accuracy_dog': tensor(0.)}\n\n    Example (in metric collection):\n        >>> import torch\n        >>> from torchmetrics import Accuracy, ClasswiseWrapper, MetricCollection, Recall\n        >>> labels = [\"horse\", \"fish\", \"dog\"]\n        >>> metric = MetricCollection(\n        ...     {'accuracy': ClasswiseWrapper(Accuracy(num_classes=3, average=None), labels),\n        ...     'recall': ClasswiseWrapper(Recall(num_classes=3, average=None), labels)}\n        ... )\n        >>> preds = torch.randn(10, 3).softmax(dim=-1)\n        >>> target = torch.randint(3, (10,))\n        >>> metric(preds, target)  # doctest: +NORMALIZE_WHITESPACE\n        {'accuracy_horse': tensor(0.), 'accuracy_fish': tensor(0.3333), 'accuracy_dog': tensor(0.4000),\n        'recall_horse': tensor(0.), 'recall_fish': tensor(0.3333), 'recall_dog': tensor(0.4000)}\n    \"\"\"\n\n    full_state_update: Optional[bool] = True\n\n    def __init__(self, metric: Metric, labels: Optional[List[str]] = None) -> None:\n        super().__init__()\n        if not isinstance(metric, Metric):\n            raise ValueError(f\"Expected argument `metric` to be an instance of `torchmetrics.Metric` but got {metric}\")\n        if labels is not None and not (isinstance(labels, list) and all(isinstance(lab, str) for lab in labels)):\n            raise ValueError(f\"Expected argument `labels` to either be `None` or a list of strings but got {labels}\")\n        self.metric = metric\n        self.labels = labels\n\n    def _convert(self, x: Tensor) -> Dict[str, Any]:\n        name = self.metric.__class__.__name__.lower()\n        if self.labels is None:\n            return {f\"{name}_{i}\": val for i, val in enumerate(x)}\n        return {f\"{name}_{lab}\": val for lab, val in zip(self.labels, x)}\n\n    def update(self, *args: Any, **kwargs: Any) -> None:\n        self.metric.update(*args, **kwargs)\n\n    def compute(self) -> Dict[str, Tensor]:\n        return self._convert(self.metric.compute())\n\n    def reset(self) -> None:\n        self.metric.reset()\n", "path": "src/torchmetrics/wrappers/classwise.py"}]}