class_docstr: Hook that dumps the pytoch tensor in memory upon
  occurrence of an exception
class_docstr_tok: ["Hook","that","dumps","the","pytoch","tensor","in","memory","upon","occurrence","of","an","exception"]
code: def on_exception(self, task: "tasks.ClassyTask"):
      import gc
  
      iteration = task.local_iteration_num
      dump_name = f"memory_rank_{self.dist_rank}_dump_{iteration}.txt"
      with open(dump_name, "w") as f:
          for obj in gc.get_objects():
              try:
                  if self._is_pytorch(obj):
                      print(type(obj), obj.size(), file=f)
              except Exception:
                  pass
          print(torch.cuda.memory_summary(), file=f)
  
imports: import atexit
  import datetime
  import json
  import logging
  import time
  from typing import List, Optional
  import torch
  from classy_vision import meters, tasks
  from classy_vision.generic.distributed_util import get_rank, is_primary
  from classy_vision.hooks.classy_hook import ClassyHook
  from fairscale.nn.data_parallel import FullyShardedDataParallel
  from iopath.common.file_io import g_pathmgr
  from vissl.models.model_helpers import model_output_has_nan
  from vissl.utils.checkpoint import CheckpointWriter, is_checkpoint_phase
  from vissl.utils.env import get_machine_local_and_dist_rank
  from vissl.utils.io import save_file
  from vissl.utils.logger import log_gpu_stats
  from vissl.utils.perf_stats import PerfStats
label_desc: Use image node_id 2 for calling the DumpMemoryOnException obj's underlying member method code with example usage: obj.on_exception(task) without return types