class_docstr: The internal computation class template.
  A metric implementation should overwrite `update()` and `compute()`. These two
  APIs focus on the actual mathematical meaning of the metric, without detailed
  knowledge of model output and task information.
  
  Args:
      my_rank (int): the rank of this trainer.
      batch_size (int): batch size used by this trainer.
      n_tasks (int): the number tasks this communication object will have to compute.
      window_size (int): the window size for the window metric.
      compute_on_all_ranks (bool): whether to compute metrics on all ranks. This is
          necessary if the non-leader rank wants to consume the metrics results.
      should_validate_update (bool): whether to check the inputs of `update()` and
          skip the update if the inputs are invalid. Invalid inputs include the case
          where all examples have 0 weights for a batch.
      process_group (Optional[ProcessGroup]): the process group used for the
          communication. Will use the default process group if not specified.
class_docstr_tok: ["The","internal","computation","class","template",".","A","metric","implementation","should","overwrite","`","update","(",")","`","and","`","compute","(",")","`",".","These","two","APIs","focus","on","the","actual","mathematical","meaning","of","the","metric",",","without","detailed","knowledge","of","model","output","and","task","information",".","Args",":","my_rank","(","int",")",":","the","rank","of","this","trainer",".","batch_size","(","int",")",":","batch","size","used","by","this","trainer",".","n_tasks","(","int",")",":","the","number","tasks","this","communication","object","will","have","to","compute",".","window_size","(","int",")",":","the","window","size","for","the","window","metric",".","compute_on_all_ranks","(","bool",")",":","whether","to","compute","metrics","on","all","ranks",".","This","is","necessary","if","the","non-leader","rank","wants","to","consume","the","metrics","results",".","should_validate_update","(","bool",")",":","whether","to","check","the","inputs","of","`","update","(",")","`","and","skip","the","update","if","the","inputs","are","invalid",".","Invalid","inputs","include","the","case","where","all","examples","have","0","weights","for","a","batch",".","process_group","(","Optional","[","ProcessGroup","]",")",":","the","process","group","used","for","the","communication",".","Will","use","the","default","process","group","if","not","specified","."]
code: def reset(self) -> None:
      super().reset()
      if self._batch_window_buffers is not None:
          self._batch_window_buffers = {
              name: WindowBuffer(
                  max_size=self._window_size,
                  max_buffer_count=MAX_BUFFER_COUNT,
              )
              for name in self._batch_window_buffers
          }
  
imports: import abc
  import itertools
  import math
  from collections import defaultdict, deque
  from dataclasses import dataclass
  from enum import Enum
  from typing import Any, Callable, cast, Deque, Dict, Iterator, List, Mapping, Optional, Sequence, Set, Tuple, Type, TypeVar, Union
  import torch
  import torch.distributed
  import torch.nn
  from torch.profiler import record_function
  from torchmetrics import Metric
  from torchrec.distributed.types import get_tensor_size_bytes
  from torchrec.metrics.metrics_config import RecComputeMode, RecTaskInfo
  from torchrec.metrics.metrics_namespace import compose_metric_key, MetricNameBase, MetricNamespaceBase, MetricPrefix
label_desc: Use image node_id 11 for calling the RecMetricComputation obj's underlying member method code with example usage: obj.reset() without return types