code: def max_memory_reserved(device: Union[Device, int] = None) -> int:
      r"""Return the maximum GPU memory managed by the caching allocator in bytes for a given device.
  
      By default, this returns the peak cached memory since the beginning of this
      program. :func:`~torch.cuda.reset_peak_memory_stats` can be used to reset
      the starting point in tracking this metric. For example, these two functions
      can measure the peak cached memory amount of each iteration in a training
      loop.
  
      Args:
          device (torch.device or int, optional): selected device. Returns
              statistic for the current device, given by :func:`~torch.cuda.current_device`,
              if :attr:`device` is ``None`` (default).
  
      .. note::
          See :ref:`cuda-memory-management` for more details about GPU memory
          management.
      """
      return memory_stats(device=device).get(
          "reserved_bytes.all.peak", 0
      )
  
imports: import collections
  import contextlib
  import ctypes
  import pickle
  import sys
  import warnings
  from inspect import signature
  from typing import Any, Dict, Optional, Tuple, Union
  import torch
  from torch import _C
  from torch.types import Device
  from .None import _get_device_index, _get_nvml_device_index, _lazy_init, is_initialized
  from ._memory_viz import memory, segments
  from ._utils import _dummy_type
label_desc: Use image node_id 16 for calling a global function with example usage: max_memory_reserved(device) and returns: memory_stats