class_docstr: A wrapper class that can help keeping track of a metric or metric collection over time.
  
  The wrapper implements the standard ``.update()``, ``.compute()``, ``.reset()`` methods that just
  calls corresponding method of the currently tracked metric. However, the following additional methods are
  provided:
  
      -``MetricTracker.n_steps``: number of metrics being tracked
      -``MetricTracker.increment()``: initialize a new metric for being tracked
      -``MetricTracker.compute_all()``: get the metric value for all steps
      -``MetricTracker.best_metric()``: returns the best value
  
  Out of the box, this wrapper class fully supports that the base metric being tracked is a single `Metric`, a
  `MetricCollection` or another `MetricWrapper` wrapped around a metric. However, multiple layers of nesting, such
  as using a `Metric` inside a `MetricWrapper` inside a `MetricCollection` is not fully supported, especially the
  `.best_metric` method that cannot auto compute the best metric and index for such nested structures.
  
  Args:
      metric: instance of a ``torchmetrics.Metric`` or ``torchmetrics.MetricCollection``
          to keep track of at each timestep.
      maximize: either single bool or list of bool indicating if higher metric values are
          better (``True``) or lower is better (``False``).
  
  Example (single metric):
      >>> from torchmetrics.wrappers import MetricTracker
      >>> from torchmetrics.classification import MulticlassAccuracy
      >>> _ = torch.manual_seed(42)
      >>> tracker = MetricTracker(MulticlassAccuracy(num_classes=10, average='micro'))
      >>> for epoch in range(5):
      ...     tracker.increment()
      ...     for batch_idx in range(5):
      ...         preds, target = torch.randint(10, (100,)), torch.randint(10, (100,))
      ...         tracker.update(preds, target)
      ...     print(f"current acc={tracker.compute()}")
      current acc=0.1120000034570694
      current acc=0.08799999952316284
      current acc=0.12600000202655792
      current acc=0.07999999821186066
      current acc=0.10199999809265137
      >>> best_acc, which_epoch = tracker.best_metric(return_step=True)
      >>> best_acc  # doctest: +ELLIPSIS
      0.1260...
      >>> which_epoch
      2
      >>> tracker.compute_all()
      tensor([0.1120, 0.0880, 0.1260, 0.0800, 0.1020])
  
  Example (multiple metrics using MetricCollection):
      >>> from torchmetrics.wrappers import MetricTracker
      >>> from torchmetrics import MetricCollection
      >>> from torchmetrics.regression import MeanSquaredError, ExplainedVariance
      >>> _ = torch.manual_seed(42)
      >>> tracker = MetricTracker(MetricCollection([MeanSquaredError(), ExplainedVariance()]), maximize=[False, True])
      >>> for epoch in range(5):
      ...     tracker.increment()
      ...     for batch_idx in range(5):
      ...         preds, target = torch.randn(100), torch.randn(100)
      ...         tracker.update(preds, target)
      ...     print(f"current stats={tracker.compute()}")  # doctest: +NORMALIZE_WHITESPACE
      current stats={'MeanSquaredError': tensor(1.8218), 'ExplainedVariance': tensor(-0.8969)}
      current stats={'MeanSquaredError': tensor(2.0268), 'ExplainedVariance': tensor(-1.0206)}
      current stats={'MeanSquaredError': tensor(1.9491), 'ExplainedVariance': tensor(-0.8298)}
      current stats={'MeanSquaredError': tensor(1.9800), 'ExplainedVariance': tensor(-0.9199)}
      current stats={'MeanSquaredError': tensor(2.2481), 'ExplainedVariance': tensor(-1.1622)}
      >>> from pprint import pprint
      >>> best_res, which_epoch = tracker.best_metric(return_step=True)
      >>> pprint(best_res)  # doctest: +ELLIPSIS
      {'ExplainedVariance': -0.829...,
       'MeanSquaredError': 1.821...}
      >>> which_epoch
      {'MeanSquaredError': 0, 'ExplainedVariance': 2}
      >>> pprint(tracker.compute_all())
      {'ExplainedVariance': tensor([-0.8969, -1.0206, -0.8298, -0.9199, -1.1622]),
       'MeanSquaredError': tensor([1.8218, 2.0268, 1.9491, 1.9800, 2.2481])}
class_docstr_tok: ["A","wrapper","class","that","can","help","keeping","track","of","a","metric","or","metric","collection","over","time",".","The","wrapper","implements","the","standard","``",".update","(",")","``",",","``",".compute","(",")","``",",","``",".reset","(",")","``","methods","that","just","calls","corresponding","method","of","the","currently","tracked","metric",".","However",",","the","following","additional","methods","are","provided",":","-","``","MetricTracker.n_steps","``",":","number","of","metrics","being","tracked","-","``","MetricTracker.increment","(",")","``",":","initialize","a","new","metric","for","being","tracked","-","``","MetricTracker.compute_all","(",")","``",":","get","the","metric","value","for","all","steps","-","``","MetricTracker.best_metric","(",")","``",":","returns","the","best","value","Out","of","the","box",",","this","wrapper","class","fully","supports","that","the","base","metric","being","tracked","is","a","single","`","Metric","`",",","a","`","MetricCollection","`","or","another","`","MetricWrapper","`","wrapped","around","a","metric",".","However",",","multiple","layers","of","nesting",",","such","as","using","a","`","Metric","`","inside","a","`","MetricWrapper","`","inside","a","`","MetricCollection","`","is","not","fully","supported",",","especially","the","`",".best_metric","`","method","that","can","not","auto","compute","the","best","metric","and","index","for","such","nested","structures",".","Args",":","metric",":","instance","of","a","``","torchmetrics.Metric","``","or","``","torchmetrics.MetricCollection","``","to","keep","track","of","at","each","timestep",".","maximize",":","either","single","bool","or","list","of","bool","indicating","if","higher","metric","values","are","better","(","``","True","``",")","or","lower","is","better","(","``","False","``",")",".","Example","(","single","metric",")",":",">",">",">","from","torchmetrics.wrappers","import","MetricTracker",">",">",">","from","torchmetrics.classification","import","MulticlassAccuracy",">",">",">","_","=","torch.manual_seed","(","42",")",">",">",">","tracker","=","MetricTracker","(","MulticlassAccuracy","(","num_classes=10",",","average='micro","'",")",")",">",">",">","for","epoch","in","range","(","5",")",":","...","tracker.increment","(",")","...","for","batch_idx","in","range","(","5",")",":","...","preds",",","target","=","torch.randint","(","10",",","(","100",",",")",")",",","torch.randint","(","10",",","(","100",",",")",")","...","tracker.update","(","preds",",","target",")","...","print","(","f","''","current","acc=","{","tracker.compute","(",")","}","''",")","current","acc=0.1120000034570694","current","acc=0.08799999952316284","current","acc=0.12600000202655792","current","acc=0.07999999821186066","current","acc=0.10199999809265137",">",">",">","best_acc",",","which_epoch","=","tracker.best_metric","(","return_step=True",")",">",">",">","best_acc","#","doctest",":","+ELLIPSIS","0.1260","...",">",">",">","which_epoch","2",">",">",">","tracker.compute_all","(",")","tensor","(","[","0.1120",",","0.0880",",","0.1260",",","0.0800",",","0.1020","]",")","Example","(","multiple","metrics","using","MetricCollection",")",":",">",">",">","from","torchmetrics.wrappers","import","MetricTracker",">",">",">","from","torchmetrics","import","MetricCollection",">",">",">","from","torchmetrics.regression","import","MeanSquaredError",",","ExplainedVariance",">",">",">","_","=","torch.manual_seed","(","42",")",">",">",">","tracker","=","MetricTracker","(","MetricCollection","(","[","MeanSquaredError","(",")",",","ExplainedVariance","(",")","]",")",",","maximize=","[","False",",","True","]",")",">",">",">","for","epoch","in","range","(","5",")",":","...","tracker.increment","(",")","...","for","batch_idx","in","range","(","5",")",":","...","preds",",","target","=","torch.randn","(","100",")",",","torch.randn","(","100",")","...","tracker.update","(","preds",",","target",")","...","print","(","f","''","current","stats=","{","tracker.compute","(",")","}","''",")","#","doctest",":","+NORMALIZE_WHITESPACE","current","stats=","{","'MeanSquaredError","'",":","tensor","(","1.8218",")",",","'ExplainedVariance","'",":","tensor","(","-0.8969",")","}","current","stats=","{","'MeanSquaredError","'",":","tensor","(","2.0268",")",",","'ExplainedVariance","'",":","tensor","(","-1.0206",")","}","current","stats=","{","'MeanSquaredError","'",":","tensor","(","1.9491",")",",","'ExplainedVariance","'",":","tensor","(","-0.8298",")","}","current","stats=","{","'MeanSquaredError","'",":","tensor","(","1.9800",")",",","'ExplainedVariance","'",":","tensor","(","-0.9199",")","}","current","stats=","{","'MeanSquaredError","'",":","tensor","(","2.2481",")",",","'ExplainedVariance","'",":","tensor","(","-1.1622",")","}",">",">",">","from","pprint","import","pprint",">",">",">","best_res",",","which_epoch","=","tracker.best_metric","(","return_step=True",")",">",">",">","pprint","(","best_res",")","#","doctest",":","+ELLIPSIS","{","'ExplainedVariance","'",":","-0.829","...",",","'MeanSquaredError","'",":","1.821","...","}",">",">",">","which_epoch","{","'MeanSquaredError","'",":","0",",","'ExplainedVariance","'",":","2","}",">",">",">","pprint","(","tracker.compute_all","(",")",")","{","'ExplainedVariance","'",":","tensor","(","[","-0.8969",",","-1.0206",",","-0.8298",",","-0.9199",",","-1.1622","]",")",",","'MeanSquaredError","'",":","tensor","(","[","1.8218",",","2.0268",",","1.9491",",","1.9800",",","2.2481","]",")","}"]
docstr: Compute the metric value for all tracked metrics.
  
  Return:
      By default will try stacking the results from all increments into a single tensor if the tracked base
      object is a single metric. If a metric collection is provided a dict of stacked tensors will be returned.
      If the stacking process fails a list of the computed results will be returned.
  
  Raises:
      ValueError:
          If `self.increment` have not been called before this method is called.
docstr_tok: ["Compute","the","metric","value","for","all","tracked","metrics",".","Return",":","By","default","will","try","stacking","the","results","from","all","increments","into","a","single","tensor","if","the","tracked","base","object","is","a","single","metric",".","If","a","metric","collection","is","provided","a","dict","of","stacked","tensors","will","be","returned",".","If","the","stacking","process","fails","a","list","of","the","computed","results","will","be","returned",".","Raises",":","ValueError",":","If","`","self.increment","`","have","not","been","called","before","this","method","is","called","."]
code: def compute_all(self) -> Any:
      """Compute the metric value for all tracked metrics.
  
      Return:
          By default will try stacking the results from all increments into a single tensor if the tracked base
          object is a single metric. If a metric collection is provided a dict of stacked tensors will be returned.
          If the stacking process fails a list of the computed results will be returned.
  
      Raises:
          ValueError:
              If `self.increment` have not been called before this method is called.
  
      """
      self._check_for_increment("compute_all")
      # The i!=0 accounts for the self._base_metric should be ignored
      res = [
          metric.compute() for i, metric in enumerate(self) if i != 0
      ]
      try:
          if isinstance(res[0], dict):
              keys = res[0].keys()
              return {
                  k: torch.stack([r[k] for r in res], dim=0)
                  for k in keys
              }
          if isinstance(res[0], list):
              return torch.stack(
                  [torch.stack(r, dim=0) for r in res], 0
              )
          return torch.stack(res, dim=0)
      except (
          TypeError
      ):  # fallback solution to just return as it is if we cannot successfully stack
          return res
  
imports: from copy import deepcopy
  from typing import Any, Dict, List, Optional, Sequence, Tuple, Union
  import torch
  from torch import Tensor
  from torch.nn import ModuleList
  from torchmetrics.collections import MetricCollection
  from torchmetrics.metric import Metric
  from torchmetrics.utilities.imports import _MATPLOTLIB_AVAILABLE
  from torchmetrics.utilities.plot import _AX_TYPE, _PLOT_OUT_TYPE, plot_single_or_multi_val
  from torchmetrics.utilities.prints import rank_zero_warn
label_desc: Use image node_id 7 for calling the MetricTracker obj's underlying member method code with example usage: obj.compute_all() and returns: torch, unknown, torch, res