docstr: Test behavior with a Metric input
docstr_tok: ["Test","behavior","with","a","Metric","input"]
code: def test_get_tensor_size_bytes_map_with_metric_input(self) -> None:
      """Test behavior with a Metric input"""
  
      class WindowBuffer:
          def __init__(
              self, max_size: int, max_buffer_count: int
          ) -> None:
              self._max_size: int = max_size
              self._max_buffer_count: int = max_buffer_count
  
              self._buffers: Deque[torch.Tensor] = deque(
                  maxlen=max_buffer_count
              )
              self._used_sizes: Deque[int] = deque(
                  maxlen=max_buffer_count
              )
              self._window_used_size = 0
  
          def aggregate_state(
              self,
              window_state: torch.Tensor,
              curr_state: torch.Tensor,
              size: int,
          ) -> None:
              def remove(window_state: torch.Tensor) -> None:
                  window_state -= self._buffers.popleft()
                  self._window_used_size -= self._used_sizes.popleft()
  
              if len(self._buffers) == self._buffers.maxlen:
                  remove(window_state)
  
              self._buffers.append(curr_state)
              self._used_sizes.append(size)
              window_state += curr_state
              self._window_used_size += size
  
              while self._window_used_size > self._max_size:
                  remove(window_state)
  
          @property
          def buffers(self) -> Deque[torch.Tensor]:
              return self._buffers
  
      class RandomModule(torch.nn.Module):
          def __init__(self) -> None:
              super().__init__()
              self.window_buffer = WindowBuffer(2000, 1000)
              self.window_buffer.aggregate_state(
                  torch.rand(6, 7, 8), torch.rand(6, 7, 8), 5
              )
              self.x = torch.rand(1, 2)
              self.y = [torch.rand(4, 5), torch.rand(9, 10)]
  
      class RandomModuleList(torch.nn.Module):
          def __init__(self) -> None:
              super().__init__()
              self.metric_list = torch.nn.ModuleList(
                  [RandomModule(), RandomModule()]
              )
  
      inputs = RandomModuleList()
      tensor_map = get_tensor_size_bytes_map(inputs)
      self.assertEqual(
          len(tensor_map),
          2 * len(inputs.metric_list[0].window_buffer.buffers) + 6,
      )
      for metric in inputs.metric_list:
          self.assertTrue(metric.x in tensor_map)
          self.assertEqual(
              tensor_map[metric.x],
              metric.x.size().numel() * metric.x.element_size(),
          )
          self.assertTrue(metric.y[0] in tensor_map)
          self.assertEqual(
              tensor_map[metric.y[0]],
              metric.y[0].size().numel() * metric.y[0].element_size(),
          )
          self.assertTrue(metric.y[1] in tensor_map)
          self.assertEqual(
              tensor_map[metric.y[1]],
              metric.y[1].size().numel() * metric.y[1].element_size(),
          )
          while metric.window_buffer.buffers:
              z = metric.window_buffer.buffers.popleft()
              self.assertTrue(z in tensor_map)
              self.assertEqual(
                  tensor_map[z], z.size().numel() * z.element_size()
              )
  
imports: import time
  import unittest
  from collections import deque, namedtuple
  from dataclasses import dataclass
  from typing import cast, Deque, List
  import torch
  from torchtnt.utils.memory import get_tensor_size_bytes_map, measure_rss_deltas, RSSProfiler
label_desc: Use image node_id 8 for calling the MemoryTest obj's underlying member method code with example usage: obj.test_get_tensor_size_bytes_map_with_metric_input() and returns: self