We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Running Wrapper documentation code example does not render
Pointing out a documentation issue in the Running wrapper:

The code example does not render properly: 
![image](https://github.com/Lightning-AI/torchmetrics/assets/28459495/ecb30567-4b65-4bda-b3ff-0e6a66f4ff2d)

https://github.com/Lightning-AI/torchmetrics/blob/99d6d9d6ac4eb1b3398241df558604e70521e6b0/src/torchmetrics/wrappers/running.py#L46-L83

I assume this is because the first line after each `Example:` does not start with `>>>`?

--- 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/running.py`
Content:
```
1 # Copyright The 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 Any, Optional, Sequence, Union
15 
16 from torch import Tensor
17 
18 from torchmetrics.metric import Metric
19 from torchmetrics.utilities.imports import _MATPLOTLIB_AVAILABLE
20 from torchmetrics.utilities.plot import _AX_TYPE, _PLOT_OUT_TYPE
21 from torchmetrics.wrappers.abstract import WrapperMetric
22 
23 if not _MATPLOTLIB_AVAILABLE:
24     __doctest_skip__ = ["Running.plot"]
25 
26 
27 class Running(WrapperMetric):
28     """Running wrapper for metrics.
29 
30     Using this wrapper allows for calculating metrics over a running window of values, instead of the whole history of
31     values. This is beneficial when you want to get a better estimate of the metric during training and don't want to
32     wait for the whole training to finish to get epoch level estimates.
33 
34     The running window is defined by the `window` argument. The window is a fixed size and this wrapper will store a
35     duplicate of the underlying metric state for each value in the window. Thus memory usage will increase linearly
36     with window size. Use accordingly. Also note that the running only works with metrics that have the
37     `full_state_update` set to `False`.
38 
39     Importantly, the wrapper does not alter the value of the `forward` method of the underlying metric. Thus, forward
40     will still return the value on the current batch. To get the running value call `compute` instead.
41 
42     Args:
43         base_metric: The metric to wrap.
44         window: The size of the running window.
45 
46     Example:
47         # Single metric
48         >>> from torch import tensor
49         >>> from torchmetrics.wrappers import Running
50         >>> from torchmetrics.aggregation import SumMetric
51         >>> metric = Running(SumMetric(), window=3)
52         >>> for i in range(6):
53         ...     current_val = metric(tensor([i]))
54         ...     running_val = metric.compute()
55         ...     total_val = tensor(sum(list(range(i+1))))  # value we would get from `compute` without running
56         ...     print(f"{current_val=}, {running_val=}, {total_val=}")
57         current_val=tensor(0.), running_val=tensor(0.), total_val=tensor(0)
58         current_val=tensor(1.), running_val=tensor(1.), total_val=tensor(1)
59         current_val=tensor(2.), running_val=tensor(3.), total_val=tensor(3)
60         current_val=tensor(3.), running_val=tensor(6.), total_val=tensor(6)
61         current_val=tensor(4.), running_val=tensor(9.), total_val=tensor(10)
62         current_val=tensor(5.), running_val=tensor(12.), total_val=tensor(15)
63 
64     Example:
65         # Metric collection
66         >>> from torch import tensor
67         >>> from torchmetrics.wrappers import Running
68         >>> from torchmetrics import MetricCollection
69         >>> from torchmetrics.aggregation import SumMetric, MeanMetric
70         >>> # note that running is input to collection, not the other way
71         >>> metric = MetricCollection({"sum": Running(SumMetric(), 3), "mean": Running(MeanMetric(), 3)})
72         >>> for i in range(6):
73         ...     current_val = metric(tensor([i]))
74         ...     running_val = metric.compute()
75         ...     print(f"{current_val=}, {running_val=}")
76         current_val={'mean': tensor(0.), 'sum': tensor(0.)}, running_val={'mean': tensor(0.), 'sum': tensor(0.)}
77         current_val={'mean': tensor(1.), 'sum': tensor(1.)}, running_val={'mean': tensor(0.5000), 'sum': tensor(1.)}
78         current_val={'mean': tensor(2.), 'sum': tensor(2.)}, running_val={'mean': tensor(1.), 'sum': tensor(3.)}
79         current_val={'mean': tensor(3.), 'sum': tensor(3.)}, running_val={'mean': tensor(2.), 'sum': tensor(6.)}
80         current_val={'mean': tensor(4.), 'sum': tensor(4.)}, running_val={'mean': tensor(3.), 'sum': tensor(9.)}
81         current_val={'mean': tensor(5.), 'sum': tensor(5.)}, running_val={'mean': tensor(4.), 'sum': tensor(12.)}
82 
83     """
84 
85     def __init__(self, base_metric: Metric, window: int = 5) -> None:
86         super().__init__()
87         if not isinstance(base_metric, Metric):
88             raise ValueError(
89                 f"Expected argument `metric` to be an instance of `torchmetrics.Metric` but got {base_metric}"
90             )
91         if not (isinstance(window, int) and window > 0):
92             raise ValueError(f"Expected argument `window` to be a positive integer but got {window}")
93         self.base_metric = base_metric
94         self.window = window
95 
96         if base_metric.full_state_update is not False:
97             raise ValueError(
98                 f"Expected attribute `full_state_update` set to `False` but got {base_metric.full_state_update}"
99             )
100         self._num_vals_seen = 0
101 
102         for key in base_metric._defaults:
103             for i in range(window):
104                 self.add_state(
105                     name=key + f"_{i}", default=base_metric._defaults[key], dist_reduce_fx=base_metric._reductions[key]
106                 )
107 
108     def update(self, *args: Any, **kwargs: Any) -> None:
109         """Update the underlying metric and save state afterwards."""
110         val = self._num_vals_seen % self.window
111         self.base_metric.update(*args, **kwargs)
112         for key in self.base_metric._defaults:
113             setattr(self, key + f"_{val}", getattr(self.base_metric, key))
114         self.base_metric.reset()
115         self._num_vals_seen += 1
116 
117     def forward(self, *args: Any, **kwargs: Any) -> Any:
118         """Forward input to the underlying metric and save state afterwards."""
119         val = self._num_vals_seen % self.window
120         res = self.base_metric.forward(*args, **kwargs)
121         for key in self.base_metric._defaults:
122             setattr(self, key + f"_{val}", getattr(self.base_metric, key))
123         self.base_metric.reset()
124         self._num_vals_seen += 1
125         self._computed = None
126         return res
127 
128     def compute(self) -> Any:
129         """Compute the metric over the running window."""
130         for i in range(self.window):
131             self.base_metric._reduce_states({key: getattr(self, key + f"_{i}") for key in self.base_metric._defaults})
132         val = self.base_metric.compute()
133         self.base_metric.reset()
134         return val
135 
136     def reset(self) -> None:
137         """Reset metric."""
138         super().reset()
139         self._num_vals_seen = 0
140 
141     def plot(
142         self, val: Optional[Union[Tensor, Sequence[Tensor]]] = None, ax: Optional[_AX_TYPE] = None
143     ) -> _PLOT_OUT_TYPE:
144         """Plot a single or multiple values from the metric.
145 
146         Args:
147             val: Either a single result from calling `metric.forward` or `metric.compute` or a list of these results.
148                 If no value is provided, will automatically call `metric.compute` and plot that result.
149             ax: An matplotlib axis object. If provided will add plot to that axis
150 
151         Returns:
152             Figure and Axes object
153 
154         Raises:
155             ModuleNotFoundError:
156                 If `matplotlib` is not installed
157 
158         .. plot::
159             :scale: 75
160 
161             >>> # Example plotting a single value
162             >>> import torch
163             >>> from torchmetrics.wrappers import Running
164             >>> from torchmetrics.aggregation import SumMetric
165             >>> metric = Running(SumMetric(), 2)
166             >>> metric.update(torch.randn(20, 2))
167             >>> fig_, ax_ = metric.plot()
168 
169         .. plot::
170             :scale: 75
171 
172             >>> # Example plotting multiple values
173             >>> import torch
174             >>> from torchmetrics.wrappers import Running
175             >>> from torchmetrics.aggregation import SumMetric
176             >>> metric = Running(SumMetric(), 2)
177             >>> values = [ ]
178             >>> for _ in range(3):
179             ...     values.append(metric(torch.randn(20, 2)))
180             >>> fig_, ax_ = metric.plot(values)
181 
182         """
183         return self._plot(val, ax)
184
```
--- 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()

```

diff --git a/src/torchmetrics/wrappers/running.py b/src/torchmetrics/wrappers/running.py
--- a/src/torchmetrics/wrappers/running.py
+++ b/src/torchmetrics/wrappers/running.py
@@ -43,8 +43,7 @@
         base_metric: The metric to wrap.
         window: The size of the running window.
 
-    Example:
-        # Single metric
+    Example (single metric):
         >>> from torch import tensor
         >>> from torchmetrics.wrappers import Running
         >>> from torchmetrics.aggregation import SumMetric
@@ -61,8 +60,7 @@
         current_val=tensor(4.), running_val=tensor(9.), total_val=tensor(10)
         current_val=tensor(5.), running_val=tensor(12.), total_val=tensor(15)
 
-    Example:
-        # Metric collection
+    Example (metric collection):
         >>> from torch import tensor
         >>> from torchmetrics.wrappers import Running
         >>> from torchmetrics import MetricCollection

{"golden_diff": "diff --git a/src/torchmetrics/wrappers/running.py b/src/torchmetrics/wrappers/running.py\n--- a/src/torchmetrics/wrappers/running.py\n+++ b/src/torchmetrics/wrappers/running.py\n@@ -43,8 +43,7 @@\n         base_metric: The metric to wrap.\n         window: The size of the running window.\n \n-    Example:\n-        # Single metric\n+    Example (single metric):\n         >>> from torch import tensor\n         >>> from torchmetrics.wrappers import Running\n         >>> from torchmetrics.aggregation import SumMetric\n@@ -61,8 +60,7 @@\n         current_val=tensor(4.), running_val=tensor(9.), total_val=tensor(10)\n         current_val=tensor(5.), running_val=tensor(12.), total_val=tensor(15)\n \n-    Example:\n-        # Metric collection\n+    Example (metric collection):\n         >>> from torch import tensor\n         >>> from torchmetrics.wrappers import Running\n         >>> from torchmetrics import MetricCollection\n", "issue": "Running Wrapper documentation code example does not render\nPointing out a documentation issue in the Running wrapper:\r\n\r\nThe code example does not render properly: \r\n![image](https://github.com/Lightning-AI/torchmetrics/assets/28459495/ecb30567-4b65-4bda-b3ff-0e6a66f4ff2d)\r\n\r\nhttps://github.com/Lightning-AI/torchmetrics/blob/99d6d9d6ac4eb1b3398241df558604e70521e6b0/src/torchmetrics/wrappers/running.py#L46-L83\r\n\r\nI assume this is because the first line after each `Example:` does not start with `>>>`?\n", "before_files": [{"content": "# Copyright The 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 Any, Optional, Sequence, Union\n\nfrom torch import Tensor\n\nfrom torchmetrics.metric import Metric\nfrom torchmetrics.utilities.imports import _MATPLOTLIB_AVAILABLE\nfrom torchmetrics.utilities.plot import _AX_TYPE, _PLOT_OUT_TYPE\nfrom torchmetrics.wrappers.abstract import WrapperMetric\n\nif not _MATPLOTLIB_AVAILABLE:\n    __doctest_skip__ = [\"Running.plot\"]\n\n\nclass Running(WrapperMetric):\n    \"\"\"Running wrapper for metrics.\n\n    Using this wrapper allows for calculating metrics over a running window of values, instead of the whole history of\n    values. This is beneficial when you want to get a better estimate of the metric during training and don't want to\n    wait for the whole training to finish to get epoch level estimates.\n\n    The running window is defined by the `window` argument. The window is a fixed size and this wrapper will store a\n    duplicate of the underlying metric state for each value in the window. Thus memory usage will increase linearly\n    with window size. Use accordingly. Also note that the running only works with metrics that have the\n    `full_state_update` set to `False`.\n\n    Importantly, the wrapper does not alter the value of the `forward` method of the underlying metric. Thus, forward\n    will still return the value on the current batch. To get the running value call `compute` instead.\n\n    Args:\n        base_metric: The metric to wrap.\n        window: The size of the running window.\n\n    Example:\n        # Single metric\n        >>> from torch import tensor\n        >>> from torchmetrics.wrappers import Running\n        >>> from torchmetrics.aggregation import SumMetric\n        >>> metric = Running(SumMetric(), window=3)\n        >>> for i in range(6):\n        ...     current_val = metric(tensor([i]))\n        ...     running_val = metric.compute()\n        ...     total_val = tensor(sum(list(range(i+1))))  # value we would get from `compute` without running\n        ...     print(f\"{current_val=}, {running_val=}, {total_val=}\")\n        current_val=tensor(0.), running_val=tensor(0.), total_val=tensor(0)\n        current_val=tensor(1.), running_val=tensor(1.), total_val=tensor(1)\n        current_val=tensor(2.), running_val=tensor(3.), total_val=tensor(3)\n        current_val=tensor(3.), running_val=tensor(6.), total_val=tensor(6)\n        current_val=tensor(4.), running_val=tensor(9.), total_val=tensor(10)\n        current_val=tensor(5.), running_val=tensor(12.), total_val=tensor(15)\n\n    Example:\n        # Metric collection\n        >>> from torch import tensor\n        >>> from torchmetrics.wrappers import Running\n        >>> from torchmetrics import MetricCollection\n        >>> from torchmetrics.aggregation import SumMetric, MeanMetric\n        >>> # note that running is input to collection, not the other way\n        >>> metric = MetricCollection({\"sum\": Running(SumMetric(), 3), \"mean\": Running(MeanMetric(), 3)})\n        >>> for i in range(6):\n        ...     current_val = metric(tensor([i]))\n        ...     running_val = metric.compute()\n        ...     print(f\"{current_val=}, {running_val=}\")\n        current_val={'mean': tensor(0.), 'sum': tensor(0.)}, running_val={'mean': tensor(0.), 'sum': tensor(0.)}\n        current_val={'mean': tensor(1.), 'sum': tensor(1.)}, running_val={'mean': tensor(0.5000), 'sum': tensor(1.)}\n        current_val={'mean': tensor(2.), 'sum': tensor(2.)}, running_val={'mean': tensor(1.), 'sum': tensor(3.)}\n        current_val={'mean': tensor(3.), 'sum': tensor(3.)}, running_val={'mean': tensor(2.), 'sum': tensor(6.)}\n        current_val={'mean': tensor(4.), 'sum': tensor(4.)}, running_val={'mean': tensor(3.), 'sum': tensor(9.)}\n        current_val={'mean': tensor(5.), 'sum': tensor(5.)}, running_val={'mean': tensor(4.), 'sum': tensor(12.)}\n\n    \"\"\"\n\n    def __init__(self, base_metric: Metric, window: int = 5) -> None:\n        super().__init__()\n        if not isinstance(base_metric, Metric):\n            raise ValueError(\n                f\"Expected argument `metric` to be an instance of `torchmetrics.Metric` but got {base_metric}\"\n            )\n        if not (isinstance(window, int) and window > 0):\n            raise ValueError(f\"Expected argument `window` to be a positive integer but got {window}\")\n        self.base_metric = base_metric\n        self.window = window\n\n        if base_metric.full_state_update is not False:\n            raise ValueError(\n                f\"Expected attribute `full_state_update` set to `False` but got {base_metric.full_state_update}\"\n            )\n        self._num_vals_seen = 0\n\n        for key in base_metric._defaults:\n            for i in range(window):\n                self.add_state(\n                    name=key + f\"_{i}\", default=base_metric._defaults[key], dist_reduce_fx=base_metric._reductions[key]\n                )\n\n    def update(self, *args: Any, **kwargs: Any) -> None:\n        \"\"\"Update the underlying metric and save state afterwards.\"\"\"\n        val = self._num_vals_seen % self.window\n        self.base_metric.update(*args, **kwargs)\n        for key in self.base_metric._defaults:\n            setattr(self, key + f\"_{val}\", getattr(self.base_metric, key))\n        self.base_metric.reset()\n        self._num_vals_seen += 1\n\n    def forward(self, *args: Any, **kwargs: Any) -> Any:\n        \"\"\"Forward input to the underlying metric and save state afterwards.\"\"\"\n        val = self._num_vals_seen % self.window\n        res = self.base_metric.forward(*args, **kwargs)\n        for key in self.base_metric._defaults:\n            setattr(self, key + f\"_{val}\", getattr(self.base_metric, key))\n        self.base_metric.reset()\n        self._num_vals_seen += 1\n        self._computed = None\n        return res\n\n    def compute(self) -> Any:\n        \"\"\"Compute the metric over the running window.\"\"\"\n        for i in range(self.window):\n            self.base_metric._reduce_states({key: getattr(self, key + f\"_{i}\") for key in self.base_metric._defaults})\n        val = self.base_metric.compute()\n        self.base_metric.reset()\n        return val\n\n    def reset(self) -> None:\n        \"\"\"Reset metric.\"\"\"\n        super().reset()\n        self._num_vals_seen = 0\n\n    def plot(\n        self, val: Optional[Union[Tensor, Sequence[Tensor]]] = None, ax: Optional[_AX_TYPE] = None\n    ) -> _PLOT_OUT_TYPE:\n        \"\"\"Plot a single or multiple values from the metric.\n\n        Args:\n            val: Either a single result from calling `metric.forward` or `metric.compute` or a list of these results.\n                If no value is provided, will automatically call `metric.compute` and plot that result.\n            ax: An matplotlib axis object. If provided will add plot to that axis\n\n        Returns:\n            Figure and Axes object\n\n        Raises:\n            ModuleNotFoundError:\n                If `matplotlib` is not installed\n\n        .. plot::\n            :scale: 75\n\n            >>> # Example plotting a single value\n            >>> import torch\n            >>> from torchmetrics.wrappers import Running\n            >>> from torchmetrics.aggregation import SumMetric\n            >>> metric = Running(SumMetric(), 2)\n            >>> metric.update(torch.randn(20, 2))\n            >>> fig_, ax_ = metric.plot()\n\n        .. plot::\n            :scale: 75\n\n            >>> # Example plotting multiple values\n            >>> import torch\n            >>> from torchmetrics.wrappers import Running\n            >>> from torchmetrics.aggregation import SumMetric\n            >>> metric = Running(SumMetric(), 2)\n            >>> values = [ ]\n            >>> for _ in range(3):\n            ...     values.append(metric(torch.randn(20, 2)))\n            >>> fig_, ax_ = metric.plot(values)\n\n        \"\"\"\n        return self._plot(val, ax)\n", "path": "src/torchmetrics/wrappers/running.py"}], "after_files": [{"content": "# Copyright The 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 Any, Optional, Sequence, Union\n\nfrom torch import Tensor\n\nfrom torchmetrics.metric import Metric\nfrom torchmetrics.utilities.imports import _MATPLOTLIB_AVAILABLE\nfrom torchmetrics.utilities.plot import _AX_TYPE, _PLOT_OUT_TYPE\nfrom torchmetrics.wrappers.abstract import WrapperMetric\n\nif not _MATPLOTLIB_AVAILABLE:\n    __doctest_skip__ = [\"Running.plot\"]\n\n\nclass Running(WrapperMetric):\n    \"\"\"Running wrapper for metrics.\n\n    Using this wrapper allows for calculating metrics over a running window of values, instead of the whole history of\n    values. This is beneficial when you want to get a better estimate of the metric during training and don't want to\n    wait for the whole training to finish to get epoch level estimates.\n\n    The running window is defined by the `window` argument. The window is a fixed size and this wrapper will store a\n    duplicate of the underlying metric state for each value in the window. Thus memory usage will increase linearly\n    with window size. Use accordingly. Also note that the running only works with metrics that have the\n    `full_state_update` set to `False`.\n\n    Importantly, the wrapper does not alter the value of the `forward` method of the underlying metric. Thus, forward\n    will still return the value on the current batch. To get the running value call `compute` instead.\n\n    Args:\n        base_metric: The metric to wrap.\n        window: The size of the running window.\n\n    Example (single metric):\n        >>> from torch import tensor\n        >>> from torchmetrics.wrappers import Running\n        >>> from torchmetrics.aggregation import SumMetric\n        >>> metric = Running(SumMetric(), window=3)\n        >>> for i in range(6):\n        ...     current_val = metric(tensor([i]))\n        ...     running_val = metric.compute()\n        ...     total_val = tensor(sum(list(range(i+1))))  # value we would get from `compute` without running\n        ...     print(f\"{current_val=}, {running_val=}, {total_val=}\")\n        current_val=tensor(0.), running_val=tensor(0.), total_val=tensor(0)\n        current_val=tensor(1.), running_val=tensor(1.), total_val=tensor(1)\n        current_val=tensor(2.), running_val=tensor(3.), total_val=tensor(3)\n        current_val=tensor(3.), running_val=tensor(6.), total_val=tensor(6)\n        current_val=tensor(4.), running_val=tensor(9.), total_val=tensor(10)\n        current_val=tensor(5.), running_val=tensor(12.), total_val=tensor(15)\n\n    Example (metric collection):\n        >>> from torch import tensor\n        >>> from torchmetrics.wrappers import Running\n        >>> from torchmetrics import MetricCollection\n        >>> from torchmetrics.aggregation import SumMetric, MeanMetric\n        >>> # note that running is input to collection, not the other way\n        >>> metric = MetricCollection({\"sum\": Running(SumMetric(), 3), \"mean\": Running(MeanMetric(), 3)})\n        >>> for i in range(6):\n        ...     current_val = metric(tensor([i]))\n        ...     running_val = metric.compute()\n        ...     print(f\"{current_val=}, {running_val=}\")\n        current_val={'mean': tensor(0.), 'sum': tensor(0.)}, running_val={'mean': tensor(0.), 'sum': tensor(0.)}\n        current_val={'mean': tensor(1.), 'sum': tensor(1.)}, running_val={'mean': tensor(0.5000), 'sum': tensor(1.)}\n        current_val={'mean': tensor(2.), 'sum': tensor(2.)}, running_val={'mean': tensor(1.), 'sum': tensor(3.)}\n        current_val={'mean': tensor(3.), 'sum': tensor(3.)}, running_val={'mean': tensor(2.), 'sum': tensor(6.)}\n        current_val={'mean': tensor(4.), 'sum': tensor(4.)}, running_val={'mean': tensor(3.), 'sum': tensor(9.)}\n        current_val={'mean': tensor(5.), 'sum': tensor(5.)}, running_val={'mean': tensor(4.), 'sum': tensor(12.)}\n\n    \"\"\"\n\n    def __init__(self, base_metric: Metric, window: int = 5) -> None:\n        super().__init__()\n        if not isinstance(base_metric, Metric):\n            raise ValueError(\n                f\"Expected argument `metric` to be an instance of `torchmetrics.Metric` but got {base_metric}\"\n            )\n        if not (isinstance(window, int) and window > 0):\n            raise ValueError(f\"Expected argument `window` to be a positive integer but got {window}\")\n        self.base_metric = base_metric\n        self.window = window\n\n        if base_metric.full_state_update is not False:\n            raise ValueError(\n                f\"Expected attribute `full_state_update` set to `False` but got {base_metric.full_state_update}\"\n            )\n        self._num_vals_seen = 0\n\n        for key in base_metric._defaults:\n            for i in range(window):\n                self.add_state(\n                    name=key + f\"_{i}\", default=base_metric._defaults[key], dist_reduce_fx=base_metric._reductions[key]\n                )\n\n    def update(self, *args: Any, **kwargs: Any) -> None:\n        \"\"\"Update the underlying metric and save state afterwards.\"\"\"\n        val = self._num_vals_seen % self.window\n        self.base_metric.update(*args, **kwargs)\n        for key in self.base_metric._defaults:\n            setattr(self, key + f\"_{val}\", getattr(self.base_metric, key))\n        self.base_metric.reset()\n        self._num_vals_seen += 1\n\n    def forward(self, *args: Any, **kwargs: Any) -> Any:\n        \"\"\"Forward input to the underlying metric and save state afterwards.\"\"\"\n        val = self._num_vals_seen % self.window\n        res = self.base_metric.forward(*args, **kwargs)\n        for key in self.base_metric._defaults:\n            setattr(self, key + f\"_{val}\", getattr(self.base_metric, key))\n        self.base_metric.reset()\n        self._num_vals_seen += 1\n        self._computed = None\n        return res\n\n    def compute(self) -> Any:\n        \"\"\"Compute the metric over the running window.\"\"\"\n        for i in range(self.window):\n            self.base_metric._reduce_states({key: getattr(self, key + f\"_{i}\") for key in self.base_metric._defaults})\n        val = self.base_metric.compute()\n        self.base_metric.reset()\n        return val\n\n    def reset(self) -> None:\n        \"\"\"Reset metric.\"\"\"\n        super().reset()\n        self._num_vals_seen = 0\n\n    def plot(\n        self, val: Optional[Union[Tensor, Sequence[Tensor]]] = None, ax: Optional[_AX_TYPE] = None\n    ) -> _PLOT_OUT_TYPE:\n        \"\"\"Plot a single or multiple values from the metric.\n\n        Args:\n            val: Either a single result from calling `metric.forward` or `metric.compute` or a list of these results.\n                If no value is provided, will automatically call `metric.compute` and plot that result.\n            ax: An matplotlib axis object. If provided will add plot to that axis\n\n        Returns:\n            Figure and Axes object\n\n        Raises:\n            ModuleNotFoundError:\n                If `matplotlib` is not installed\n\n        .. plot::\n            :scale: 75\n\n            >>> # Example plotting a single value\n            >>> import torch\n            >>> from torchmetrics.wrappers import Running\n            >>> from torchmetrics.aggregation import SumMetric\n            >>> metric = Running(SumMetric(), 2)\n            >>> metric.update(torch.randn(20, 2))\n            >>> fig_, ax_ = metric.plot()\n\n        .. plot::\n            :scale: 75\n\n            >>> # Example plotting multiple values\n            >>> import torch\n            >>> from torchmetrics.wrappers import Running\n            >>> from torchmetrics.aggregation import SumMetric\n            >>> metric = Running(SumMetric(), 2)\n            >>> values = [ ]\n            >>> for _ in range(3):\n            ...     values.append(metric(torch.randn(20, 2)))\n            >>> fig_, ax_ = metric.plot(values)\n\n        \"\"\"\n        return self._plot(val, ax)\n", "path": "src/torchmetrics/wrappers/running.py"}]}