code: def test_require_backward_memory_leak():
      tensors = [o for o in gc.get_objects() if torch.is_tensor(o)]
      num_global_tensors = len(tensors)
      del tensors
  
      # Using clone resolves memory leak.
      for i in range(10):
          x = torch.tensor(0.0)
          require_backward(x)
          x._pyro_backward.process(x.clone())
  
      tensors = [o for o in gc.get_objects() if torch.is_tensor(o)]
      assert len(tensors) <= 5 + num_global_tensors
      del tensors
  
      # Using [...] creates memory leak.
      for i in range(10):
          x = torch.tensor(0.0)
          require_backward(x)
          x._pyro_backward.process(x[...])
  
      tensors = [o for o in gc.get_objects() if torch.is_tensor(o)]
      assert len(tensors) >= 15 + num_global_tensors
  
file_path: pyro/tests/ops/einsum/test_adjoint.py
imports: import gc
  import itertools
  import pytest
  import torch
  from pyro.ops.einsum import contract
  from pyro.ops.einsum.adjoint import require_backward
  from tests.common import assert_equal
label_desc: Use image node_id 3 for calling a global function with example usage: test_require_backward_memory_leak() without return types