class_docstr: Profiler that captures memory traces for allocation and deallocation of memory for
  tensors.
class_docstr_tok: ["Profiler","that","captures","memory","traces","for","allocation","and","deallocation","of","memory","for","tensors","."]
code: def __enter__(self):
      if not self._has_trace_plot:
          return
      self.enabled = True
      # TODO: This does not show the previous memory allocations
      # We could at least have a placeholder with how much
      # memory was allocated before
      torch.cuda.memory._record_memory_history(
          True,
          # keep 100,000 alloc/free events from before the snapshot
          trace_alloc_max_entries=100000,
          # record stack information for the trace events
          trace_alloc_record_context=True,
      )
  
imports: import logging
  import os
  import queue
  import socket
  import weakref
  from dataclasses import dataclass
  from pathlib import Path
  from typing import Any, List, Optional, Sequence, Tuple
  import torch.cuda.memory
  import torch.cuda.nvtx
  import torch.nn
  import torch.profiler
  import torch.utils.hooks
label_desc: Use image node_id 3 for calling the MemSnapshotsProfiler obj's underlying member method code with example usage: obj.__enter__() without return types