code: def test_retain_graph():
      x = mx.nd.ones((2, 2))
      dx = mx.nd.zeros((2, 2))
      mark_variables([x], [dx], grad_reqs="add")
      with record():
          y = x + 1
          y.backward(retain_graph=False)
      assert (dx.asnumpy() == 1).all()
  
      dx[:] = 0
      with record():
          y = x + 1
          y.backward(retain_graph=True)
          y.backward(retain_graph=False)
      assert (dx.asnumpy() == 2).all()
  
      # The following sequence should throw an exception. We discard the expected
      # stderr stack trace output for this operation to keep the test logs clean.
      with discard_stderr():
          try:
              with record():
                  y = x + 1
                  y.backward()
                  y.backward()
          except Exception:
              return
  
      raise AssertionError(
          "differentiating the same graph twice without retain_graph should fail"
      )
  
imports: import functools
  import mxnet.ndarray
  from mxnet.ndarray import zeros_like
  from mxnet.autograd import *
  from mxnet.test_utils import *
  from common import xfail_when_nonstandard_decimal_separator
  from mxnet.test_utils import environment
  import pytest
label_desc: Use image node_id 11 for calling a global function with example usage: test_retain_graph() without return types