code: def reset_peak_memory_stats(device: torch.device) -> Optional[Memory]:
      """Safely resets CUDA peak memory statistics of device if it is
      a CUDA device.
  
      Notes: ``torch.cuda.reset_peak_memory_stats(device)`` will error
      if no CUDA memory has been allocated to the device.
  
      Args:
          device: A torch.device
  
      Returns:
          max_memory_allocated before resetting the statistics and
          memory_allocated, both in bytes
      """
      prev_max_memory = torch.cuda.max_memory_allocated(device)
      memory_allocated = torch.cuda.memory_allocated(device)
  
      if prev_max_memory != memory_allocated and prev_max_memory > 0:
          # raises RuntimeError if no previous allocation occurred
          torch.cuda.reset_peak_memory_stats(device)
          if (
              torch.cuda.max_memory_allocated(device)
              != memory_allocated
          ):
              return None
  
      return Memory(prev_max_memory, memory_allocated)
  
file_path: opacus/benchmarks/utils.py
imports: import glob
  import pickle
  from collections import namedtuple
  from typing import Any, Dict, List, Optional
  import numpy
  import pandas
  import torch
  from benchmarks.layers import LayerType
label_desc: Use image node_id 1 for calling a global function with example usage: reset_peak_memory_stats(device) and returns: Memory, None