code: def check_no_weakref(obj, path="", avoid_ids=None):
      """Attempts to check that an object has no weakrefs."""
      if avoid_ids is None:
          avoid_ids = {id(obj)}
  
      if isinstance(obj, weakref.ref):
          raise ValueError(f"Weakref found at {path}")
      elif isinstance(obj, dict):
          for k, v in obj.items():
              if id(v) not in avoid_ids:
                  check_no_weakref(v, path + f"[{k}]")
      elif isinstance(obj, (list, tuple)):
          for i, v in enumerate(obj):
              if id(v) not in avoid_ids:
                  check_no_weakref(v, path + f"[{i}]")
      elif hasattr(obj, "__dict__"):
          check_no_weakref(obj.__dict__, path)
  
file_path: pyro/pyro/contrib/util.py
imports: import weakref
  from collections import OrderedDict
  import torch
  import pyro
label_desc: Use image node_id 11 for calling a global function with example usage: check_no_weakref(obj, path, avoid_ids) without return types