prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  `log_dict` is missing `prefix` parameter that is mentioned in docs
  ## 🐛 Bug
  
  [`MetricCollection` documentation](https://pytorch-lightning.readthedocs.io/en/1.2.0/extensions/metrics.html#metriccollection) mentions using `self.log_dict(self.train_metrics, on_step=True, on_epoch=False, prefix='train')`. The `prefix` parameter doesn't seem to be present in `log_dict` function header.
  
  
  ### Expected behavior
  
  `prefix` is most likely usable in this context, so this feature should be implemented. If not - the documentation should be fixed.
  
  ### Environment
  
   - Lightning Version: 1.2.0
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `torchmetrics/collections.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 
  15 from copy import deepcopy
  16 from typing import Any, Dict, List, Tuple, Union
  17 
  18 from torch import nn
  19 
  20 from torchmetrics.metric import Metric
  21 
  22 
  23 class MetricCollection(nn.ModuleDict):
  24     """
  25     MetricCollection class can be used to chain metrics that have the same
  26     call pattern into one single class.
  27 
  28     Args:
  29         metrics: One of the following
  30 
  31             * list or tuple: if metrics are passed in as a list, will use the
  32               metrics class name as key for output dict. Therefore, two metrics
  33               of the same class cannot be chained this way.
  34 
  35             * dict: if metrics are passed in as a dict, will use each key in the
  36               dict as key for output dict. Use this format if you want to chain
  37               together multiple of the same metric with different parameters.
  38 
  39     Example (input as list):
  40         >>> import torch
  41         >>> from torchmetrics import MetricCollection, Accuracy, Precision, Recall
  42         >>> target = torch.tensor([0, 2, 0, 2, 0, 1, 0, 2])
  43         >>> preds = torch.tensor([2, 1, 2, 0, 1, 2, 2, 2])
  44         >>> metrics = MetricCollection([Accuracy(),
  45         ...                             Precision(num_classes=3, average='macro'),
  46         ...                             Recall(num_classes=3, average='macro')])
  47         >>> metrics(preds, target)
  48         {'Accuracy': tensor(0.1250), 'Precision': tensor(0.0667), 'Recall': tensor(0.1111)}
  49 
  50     Example (input as dict):
  51         >>> metrics = MetricCollection({'micro_recall': Recall(num_classes=3, average='micro'),
  52         ...                             'macro_recall': Recall(num_classes=3, average='macro')})
  53         >>> same_metric = metrics.clone()
  54         >>> metrics(preds, target)
  55         {'micro_recall': tensor(0.1250), 'macro_recall': tensor(0.1111)}
  56         >>> same_metric(preds, target)
  57         {'micro_recall': tensor(0.1250), 'macro_recall': tensor(0.1111)}
  58         >>> metrics.persistent()
  59 
  60     """
  61 
  62     def __init__(self, metrics: Union[List[Metric], Tuple[Metric], Dict[str, Metric]]):
  63         super().__init__()
  64         if isinstance(metrics, dict):
  65             # Check all values are metrics
  66             for name, metric in metrics.items():
  67                 if not isinstance(metric, Metric):
  68                     raise ValueError(
  69                         f"Value {metric} belonging to key {name}"
  70                         " is not an instance of `pl.metrics.Metric`"
  71                     )
  72                 self[name] = metric
  73         elif isinstance(metrics, (tuple, list)):
  74             for metric in metrics:
  75                 if not isinstance(metric, Metric):
  76                     raise ValueError(
  77                         f"Input {metric} to `MetricCollection` is not a instance"
  78                         " of `pl.metrics.Metric`"
  79                     )
  80                 name = metric.__class__.__name__
  81                 if name in self:
  82                     raise ValueError(f"Encountered two metrics both named {name}")
  83                 self[name] = metric
  84         else:
  85             raise ValueError("Unknown input to MetricCollection.")
  86 
  87     def forward(self, *args, **kwargs) -> Dict[str, Any]:  # pylint: disable=E0202
  88         """
  89         Iteratively call forward for each metric. Positional arguments (args) will
  90         be passed to every metric in the collection, while keyword arguments (kwargs)
  91         will be filtered based on the signature of the individual metric.
  92         """
  93         return {k: m(*args, **m._filter_kwargs(**kwargs)) for k, m in self.items()}
  94 
  95     def update(self, *args, **kwargs):  # pylint: disable=E0202
  96         """
  97         Iteratively call update for each metric. Positional arguments (args) will
  98         be passed to every metric in the collection, while keyword arguments (kwargs)
  99         will be filtered based on the signature of the individual metric.
  100         """
  101         for _, m in self.items():
  102             m_kwargs = m._filter_kwargs(**kwargs)
  103             m.update(*args, **m_kwargs)
  104 
  105     def compute(self) -> Dict[str, Any]:
  106         return {k: m.compute() for k, m in self.items()}
  107 
  108     def reset(self):
  109         """ Iteratively call reset for each metric """
  110         for _, m in self.items():
  111             m.reset()
  112 
  113     def clone(self):
  114         """ Make a copy of the metric collection """
  115         return deepcopy(self)
  116 
  117     def persistent(self, mode: bool = True):
  118         """Method for post-init to change if metric states should be saved to
  119         its state_dict
  120         """
  121         for _, m in self.items():
  122             m.persistent(mode)
  123
  ```
  --- 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/torchmetrics/collections.py b/torchmetrics/collections.py
  --- a/torchmetrics/collections.py
  +++ b/torchmetrics/collections.py
  @@ -13,7 +13,7 @@
   # limitations under the License.
   
   from copy import deepcopy
  -from typing import Any, Dict, List, Tuple, Union
  +from typing import Any, Dict, List, Optional, Tuple, Union
   
   from torch import nn
   
  @@ -36,6 +36,8 @@
                 dict as key for output dict. Use this format if you want to chain
                 together multiple of the same metric with different parameters.
   
  +        prefix: a string to append in front of the keys of the output dict
  +
       Example (input as list):
           >>> import torch
           >>> from torchmetrics import MetricCollection, Accuracy, Precision, Recall
  @@ -58,8 +60,11 @@
           >>> metrics.persistent()
   
       """
  -
  -    def __init__(self, metrics: Union[List[Metric], Tuple[Metric], Dict[str, Metric]]):
  +    def __init__(
  +            self,
  +            metrics: Union[List[Metric], Tuple[Metric], Dict[str, Metric]],
  +            prefix: Optional[str] = None
  +    ):
           super().__init__()
           if isinstance(metrics, dict):
               # Check all values are metrics
  @@ -84,13 +89,15 @@
           else:
               raise ValueError("Unknown input to MetricCollection.")
   
  +        self.prefix = self._check_prefix_arg(prefix)
  +
       def forward(self, *args, **kwargs) -> Dict[str, Any]:  # pylint: disable=E0202
           """
           Iteratively call forward for each metric. Positional arguments (args) will
           be passed to every metric in the collection, while keyword arguments (kwargs)
           will be filtered based on the signature of the individual metric.
           """
  -        return {k: m(*args, **m._filter_kwargs(**kwargs)) for k, m in self.items()}
  +        return {self._set_prefix(k): m(*args, **m._filter_kwargs(**kwargs)) for k, m in self.items()}
   
       def update(self, *args, **kwargs):  # pylint: disable=E0202
           """
  @@ -103,20 +110,36 @@
               m.update(*args, **m_kwargs)
   
       def compute(self) -> Dict[str, Any]:
  -        return {k: m.compute() for k, m in self.items()}
  +        return {self._set_prefix(k): m.compute() for k, m in self.items()}
   
  -    def reset(self):
  +    def reset(self) -> None:
           """ Iteratively call reset for each metric """
           for _, m in self.items():
               m.reset()
   
  -    def clone(self):
  -        """ Make a copy of the metric collection """
  -        return deepcopy(self)
  +    def clone(self, prefix: Optional[str] = None) -> 'MetricCollection':
  +        """ Make a copy of the metric collection
  +        Args:
  +            prefix: a string to append in front of the metric keys
  +        """
  +        mc = deepcopy(self)
  +        mc.prefix = self._check_prefix_arg(prefix)
  +        return mc
   
  -    def persistent(self, mode: bool = True):
  +    def persistent(self, mode: bool = True) -> None:
           """Method for post-init to change if metric states should be saved to
           its state_dict
           """
           for _, m in self.items():
               m.persistent(mode)
  +
  +    def _set_prefix(self, k: str) -> str:
  +        return k if self.prefix is None else self.prefix + k
  +
  +    def _check_prefix_arg(self, prefix: str) -> Optional[str]:
  +        if prefix is not None:
  +            if isinstance(prefix, str):
  +                return prefix
  +            else:
  +                raise ValueError('Expected input `prefix` to be a string')
  +        return None
  
verification_info: {"golden_diff": "diff --git a/torchmetrics/collections.py b/torchmetrics/collections.py\n--- a/torchmetrics/collections.py\n+++ b/torchmetrics/collections.py\n@@ -13,7 +13,7 @@\n # limitations under the License.\n \n from copy import deepcopy\n-from typing import Any, Dict, List, Tuple, Union\n+from typing import Any, Dict, List, Optional, Tuple, Union\n \n from torch import nn\n \n@@ -36,6 +36,8 @@\n               dict as key for output dict. Use this format if you want to chain\n               together multiple of the same metric with different parameters.\n \n+        prefix: a string to append in front of the keys of the output dict\n+\n     Example (input as list):\n         >>> import torch\n         >>> from torchmetrics import MetricCollection, Accuracy, Precision, Recall\n@@ -58,8 +60,11 @@\n         >>> metrics.persistent()\n \n     \"\"\"\n-\n-    def __init__(self, metrics: Union[List[Metric], Tuple[Metric], Dict[str, Metric]]):\n+    def __init__(\n+            self,\n+            metrics: Union[List[Metric], Tuple[Metric], Dict[str, Metric]],\n+            prefix: Optional[str] = None\n+    ):\n         super().__init__()\n         if isinstance(metrics, dict):\n             # Check all values are metrics\n@@ -84,13 +89,15 @@\n         else:\n             raise ValueError(\"Unknown input to MetricCollection.\")\n \n+        self.prefix = self._check_prefix_arg(prefix)\n+\n     def forward(self, *args, **kwargs) -> Dict[str, Any]:  # pylint: disable=E0202\n         \"\"\"\n         Iteratively call forward for each metric. Positional arguments (args) will\n         be passed to every metric in the collection, while keyword arguments (kwargs)\n         will be filtered based on the signature of the individual metric.\n         \"\"\"\n-        return {k: m(*args, **m._filter_kwargs(**kwargs)) for k, m in self.items()}\n+        return {self._set_prefix(k): m(*args, **m._filter_kwargs(**kwargs)) for k, m in self.items()}\n \n     def update(self, *args, **kwargs):  # pylint: disable=E0202\n         \"\"\"\n@@ -103,20 +110,36 @@\n             m.update(*args, **m_kwargs)\n \n     def compute(self) -> Dict[str, Any]:\n-        return {k: m.compute() for k, m in self.items()}\n+        return {self._set_prefix(k): m.compute() for k, m in self.items()}\n \n-    def reset(self):\n+    def reset(self) -> None:\n         \"\"\" Iteratively call reset for each metric \"\"\"\n         for _, m in self.items():\n             m.reset()\n \n-    def clone(self):\n-        \"\"\" Make a copy of the metric collection \"\"\"\n-        return deepcopy(self)\n+    def clone(self, prefix: Optional[str] = None) -> 'MetricCollection':\n+        \"\"\" Make a copy of the metric collection\n+        Args:\n+            prefix: a string to append in front of the metric keys\n+        \"\"\"\n+        mc = deepcopy(self)\n+        mc.prefix = self._check_prefix_arg(prefix)\n+        return mc\n \n-    def persistent(self, mode: bool = True):\n+    def persistent(self, mode: bool = True) -> None:\n         \"\"\"Method for post-init to change if metric states should be saved to\n         its state_dict\n         \"\"\"\n         for _, m in self.items():\n             m.persistent(mode)\n+\n+    def _set_prefix(self, k: str) -> str:\n+        return k if self.prefix is None else self.prefix + k\n+\n+    def _check_prefix_arg(self, prefix: str) -> Optional[str]:\n+        if prefix is not None:\n+            if isinstance(prefix, str):\n+                return prefix\n+            else:\n+                raise ValueError('Expected input `prefix` to be a string')\n+        return None\n", "issue": "`log_dict` is missing `prefix` parameter that is mentioned in docs\n## \ud83d\udc1b Bug\r\n\r\n[`MetricCollection` documentation](https://pytorch-lightning.readthedocs.io/en/1.2.0/extensions/metrics.html#metriccollection) mentions using `self.log_dict(self.train_metrics, on_step=True, on_epoch=False, prefix='train')`. The `prefix` parameter doesn't seem to be present in `log_dict` function header.\r\n\r\n\r\n### Expected behavior\r\n\r\n`prefix` is most likely usable in this context, so this feature should be implemented. If not - the documentation should be fixed.\r\n\r\n### Environment\r\n\r\n - Lightning Version: 1.2.0\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.\n\nfrom copy import deepcopy\nfrom typing import Any, Dict, List, Tuple, Union\n\nfrom torch import nn\n\nfrom torchmetrics.metric import Metric\n\n\nclass MetricCollection(nn.ModuleDict):\n    \"\"\"\n    MetricCollection class can be used to chain metrics that have the same\n    call pattern into one single class.\n\n    Args:\n        metrics: One of the following\n\n            * list or tuple: if metrics are passed in as a list, will use the\n              metrics class name as key for output dict. Therefore, two metrics\n              of the same class cannot be chained this way.\n\n            * dict: if metrics are passed in as a dict, will use each key in the\n              dict as key for output dict. Use this format if you want to chain\n              together multiple of the same metric with different parameters.\n\n    Example (input as list):\n        >>> import torch\n        >>> from torchmetrics import MetricCollection, Accuracy, Precision, Recall\n        >>> target = torch.tensor([0, 2, 0, 2, 0, 1, 0, 2])\n        >>> preds = torch.tensor([2, 1, 2, 0, 1, 2, 2, 2])\n        >>> metrics = MetricCollection([Accuracy(),\n        ...                             Precision(num_classes=3, average='macro'),\n        ...                             Recall(num_classes=3, average='macro')])\n        >>> metrics(preds, target)\n        {'Accuracy': tensor(0.1250), 'Precision': tensor(0.0667), 'Recall': tensor(0.1111)}\n\n    Example (input as dict):\n        >>> metrics = MetricCollection({'micro_recall': Recall(num_classes=3, average='micro'),\n        ...                             'macro_recall': Recall(num_classes=3, average='macro')})\n        >>> same_metric = metrics.clone()\n        >>> metrics(preds, target)\n        {'micro_recall': tensor(0.1250), 'macro_recall': tensor(0.1111)}\n        >>> same_metric(preds, target)\n        {'micro_recall': tensor(0.1250), 'macro_recall': tensor(0.1111)}\n        >>> metrics.persistent()\n\n    \"\"\"\n\n    def __init__(self, metrics: Union[List[Metric], Tuple[Metric], Dict[str, Metric]]):\n        super().__init__()\n        if isinstance(metrics, dict):\n            # Check all values are metrics\n            for name, metric in metrics.items():\n                if not isinstance(metric, Metric):\n                    raise ValueError(\n                        f\"Value {metric} belonging to key {name}\"\n                        \" is not an instance of `pl.metrics.Metric`\"\n                    )\n                self[name] = metric\n        elif isinstance(metrics, (tuple, list)):\n            for metric in metrics:\n                if not isinstance(metric, Metric):\n                    raise ValueError(\n                        f\"Input {metric} to `MetricCollection` is not a instance\"\n                        \" of `pl.metrics.Metric`\"\n                    )\n                name = metric.__class__.__name__\n                if name in self:\n                    raise ValueError(f\"Encountered two metrics both named {name}\")\n                self[name] = metric\n        else:\n            raise ValueError(\"Unknown input to MetricCollection.\")\n\n    def forward(self, *args, **kwargs) -> Dict[str, Any]:  # pylint: disable=E0202\n        \"\"\"\n        Iteratively call forward for each metric. Positional arguments (args) will\n        be passed to every metric in the collection, while keyword arguments (kwargs)\n        will be filtered based on the signature of the individual metric.\n        \"\"\"\n        return {k: m(*args, **m._filter_kwargs(**kwargs)) for k, m in self.items()}\n\n    def update(self, *args, **kwargs):  # pylint: disable=E0202\n        \"\"\"\n        Iteratively call update for each metric. Positional arguments (args) will\n        be passed to every metric in the collection, while keyword arguments (kwargs)\n        will be filtered based on the signature of the individual metric.\n        \"\"\"\n        for _, m in self.items():\n            m_kwargs = m._filter_kwargs(**kwargs)\n            m.update(*args, **m_kwargs)\n\n    def compute(self) -> Dict[str, Any]:\n        return {k: m.compute() for k, m in self.items()}\n\n    def reset(self):\n        \"\"\" Iteratively call reset for each metric \"\"\"\n        for _, m in self.items():\n            m.reset()\n\n    def clone(self):\n        \"\"\" Make a copy of the metric collection \"\"\"\n        return deepcopy(self)\n\n    def persistent(self, mode: bool = True):\n        \"\"\"Method for post-init to change if metric states should be saved to\n        its state_dict\n        \"\"\"\n        for _, m in self.items():\n            m.persistent(mode)\n", "path": "torchmetrics/collections.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.\n\nfrom copy import deepcopy\nfrom typing import Any, Dict, List, Optional, Tuple, Union\n\nfrom torch import nn\n\nfrom torchmetrics.metric import Metric\n\n\nclass MetricCollection(nn.ModuleDict):\n    \"\"\"\n    MetricCollection class can be used to chain metrics that have the same\n    call pattern into one single class.\n\n    Args:\n        metrics: One of the following\n\n            * list or tuple: if metrics are passed in as a list, will use the\n              metrics class name as key for output dict. Therefore, two metrics\n              of the same class cannot be chained this way.\n\n            * dict: if metrics are passed in as a dict, will use each key in the\n              dict as key for output dict. Use this format if you want to chain\n              together multiple of the same metric with different parameters.\n\n        prefix: a string to append in front of the keys of the output dict\n\n    Example (input as list):\n        >>> import torch\n        >>> from torchmetrics import MetricCollection, Accuracy, Precision, Recall\n        >>> target = torch.tensor([0, 2, 0, 2, 0, 1, 0, 2])\n        >>> preds = torch.tensor([2, 1, 2, 0, 1, 2, 2, 2])\n        >>> metrics = MetricCollection([Accuracy(),\n        ...                             Precision(num_classes=3, average='macro'),\n        ...                             Recall(num_classes=3, average='macro')])\n        >>> metrics(preds, target)\n        {'Accuracy': tensor(0.1250), 'Precision': tensor(0.0667), 'Recall': tensor(0.1111)}\n\n    Example (input as dict):\n        >>> metrics = MetricCollection({'micro_recall': Recall(num_classes=3, average='micro'),\n        ...                             'macro_recall': Recall(num_classes=3, average='macro')})\n        >>> same_metric = metrics.clone()\n        >>> metrics(preds, target)\n        {'micro_recall': tensor(0.1250), 'macro_recall': tensor(0.1111)}\n        >>> same_metric(preds, target)\n        {'micro_recall': tensor(0.1250), 'macro_recall': tensor(0.1111)}\n        >>> metrics.persistent()\n\n    \"\"\"\n    def __init__(\n            self,\n            metrics: Union[List[Metric], Tuple[Metric], Dict[str, Metric]],\n            prefix: Optional[str] = None\n    ):\n        super().__init__()\n        if isinstance(metrics, dict):\n            # Check all values are metrics\n            for name, metric in metrics.items():\n                if not isinstance(metric, Metric):\n                    raise ValueError(\n                        f\"Value {metric} belonging to key {name}\"\n                        \" is not an instance of `pl.metrics.Metric`\"\n                    )\n                self[name] = metric\n        elif isinstance(metrics, (tuple, list)):\n            for metric in metrics:\n                if not isinstance(metric, Metric):\n                    raise ValueError(\n                        f\"Input {metric} to `MetricCollection` is not a instance\"\n                        \" of `pl.metrics.Metric`\"\n                    )\n                name = metric.__class__.__name__\n                if name in self:\n                    raise ValueError(f\"Encountered two metrics both named {name}\")\n                self[name] = metric\n        else:\n            raise ValueError(\"Unknown input to MetricCollection.\")\n\n        self.prefix = self._check_prefix_arg(prefix)\n\n    def forward(self, *args, **kwargs) -> Dict[str, Any]:  # pylint: disable=E0202\n        \"\"\"\n        Iteratively call forward for each metric. Positional arguments (args) will\n        be passed to every metric in the collection, while keyword arguments (kwargs)\n        will be filtered based on the signature of the individual metric.\n        \"\"\"\n        return {self._set_prefix(k): m(*args, **m._filter_kwargs(**kwargs)) for k, m in self.items()}\n\n    def update(self, *args, **kwargs):  # pylint: disable=E0202\n        \"\"\"\n        Iteratively call update for each metric. Positional arguments (args) will\n        be passed to every metric in the collection, while keyword arguments (kwargs)\n        will be filtered based on the signature of the individual metric.\n        \"\"\"\n        for _, m in self.items():\n            m_kwargs = m._filter_kwargs(**kwargs)\n            m.update(*args, **m_kwargs)\n\n    def compute(self) -> Dict[str, Any]:\n        return {self._set_prefix(k): m.compute() for k, m in self.items()}\n\n    def reset(self) -> None:\n        \"\"\" Iteratively call reset for each metric \"\"\"\n        for _, m in self.items():\n            m.reset()\n\n    def clone(self, prefix: Optional[str] = None) -> 'MetricCollection':\n        \"\"\" Make a copy of the metric collection\n        Args:\n            prefix: a string to append in front of the metric keys\n        \"\"\"\n        mc = deepcopy(self)\n        mc.prefix = self._check_prefix_arg(prefix)\n        return mc\n\n    def persistent(self, mode: bool = True) -> None:\n        \"\"\"Method for post-init to change if metric states should be saved to\n        its state_dict\n        \"\"\"\n        for _, m in self.items():\n            m.persistent(mode)\n\n    def _set_prefix(self, k: str) -> str:\n        return k if self.prefix is None else self.prefix + k\n\n    def _check_prefix_arg(self, prefix: str) -> Optional[str]:\n        if prefix is not None:\n            if isinstance(prefix, str):\n                return prefix\n            else:\n                raise ValueError('Expected input `prefix` to be a string')\n        return None\n", "path": "torchmetrics/collections.py"}]}