code: def test_dropout_grad_dependency(p, seed, ctx, func_name):
      from nnabla._dropout_workaround import _get_dropout_mask
  
      # Test whether the memory clearance by grad_depends_on_inputs/outputs does
      # something bad during graph execution such as the clearance values which
      # is planned to be used. This test is performed by changing the
      # inputs/outputs of Dropout to intermediate variables in the same manner of
      # nbla_test_utils.py.
      atol_f = 1e-4
  
      with nn.context_scope(ctx):
          rng = np.random.RandomState(seed)
          init_x = rng.randn(2, 3, 4).astype(np.float32) * 2
          init_dy_for_grad = rng.randn(*init_x.shape).astype(
              init_x.dtype
          )
          init_dx = rng.randn(*init_x.shape).astype(init_x.dtype)
          init_for_dx2 = rng.randn(*init_x.shape).astype(init_x.dtype)
  
          # Graph construction
          x = nn.Variable.from_numpy_array(init_x).apply(need_grad=True)
          x_interm = F.identity(x)
          y_interm = F.dropout(x_interm, p, seed)
          y = F.identity(y_interm)
          dx_interm = nn.grad(y, x, grad_outputs=[init_dy_for_grad])[0]
          dx = F.identity(dx_interm)
          y_dx = (
              y + dx
          )  # replaceable with F.sink(y, dx, one_input_grad=False)
  
          # Execution
          x.g = init_dx  # Accumulation
          y_dx.forward(clear_no_need_grad=True)
          mask = _get_dropout_mask(
              x_interm
          ).d  # Store mask before the clear
          y_dx.backward(init_for_dx2, clear_buffer=True)
  
          # Reference
          ref_dx = (
              ref_dropout_double_backward(init_for_dx2, mask, p)
              + init_dx
          )
  
          # Test
          assert_allclose(
              x.g,
              ref_dx,
              atol=atol_f,
              err_msg="Wrong output values of double backward of "
              "Dropout by nn.grad.",
          )
  
file_path: nnabla/python/test/function/test_dropout.py
imports: from six.moves import range
  import pytest
  import numpy
  import nnabla
  import nnabla.functions
  from nbla_test_utils import list_context
  from nnabla.testing import assert_allclose
label_desc: Use image node_id 6 for calling a global function with example usage: test_dropout_grad_dependency(p, seed, ctx, func_name) without return types