code: def test_random_erase_backward(
      ctx,
      func_name,
      seed,
      prob,
      area_ratios,
      aspect_ratios,
      replacements,
      n,
      share,
      inplace,
      base_axis,
      func_seed,
      channel_last,
      ste_fine_grained,
  ):
      if channel_last and func_name == "RandomErase":
          pytest.skip(
              "RandomErase with channel_last is only supported in CUDA."
          )
  
      lb = replacements[0]
      rng = np.random.RandomState(seed)
      b, c, h, w = 4, 3, 32, 32
      ishape = [b, c, h, w]
  
      # Backward check for accum
      x = nn.Variable.from_numpy_array(rng.rand(*ishape) + 1.0).apply(
          need_grad=True
      )
      xg = rng.randn(*x.shape)
      x.g = xg
      with nn.context_scope(ctx):
          y = F.random_erase(
              x,
              prob=prob,
              area_ratios=area_ratios,
              aspect_ratios=aspect_ratios,
              replacements=replacements,
              n=n,
              share=share,
              inplace=inplace,
              base_axis=base_axis,
              seed=func_seed,
              channel_last=channel_last,
              ste_fine_grained=ste_fine_grained,
          )
      y.forward()
      y.backward(clear_buffer=True)
      if ste_fine_grained:
          xg[np.where(y.d < lb)] += 1.0
          assert_allclose(x.g, xg)
      else:
          assert_allclose(x.g, xg + 1.0)
  
      # Backward check for not accum
      x = nn.Variable.from_numpy_array(rng.rand(*ishape) + 1.0).apply(
          need_grad=True
      )
      y = F.identity(x)
      with nn.context_scope(ctx):
          z = F.random_erase(
              y,
              prob=prob,
              area_ratios=area_ratios,
              aspect_ratios=aspect_ratios,
              replacements=replacements,
              n=n,
              share=share,
              inplace=inplace,
              base_axis=base_axis,
              seed=func_seed,
              channel_last=channel_last,
              ste_fine_grained=ste_fine_grained,
          )
      z.forward()
      z.backward(clear_buffer=False)
      if ste_fine_grained:
          assert_allclose(y.g[np.where(z.d >= lb)], 0.0)
          assert_allclose(y.g[np.where(z.d < lb)], 1.0)
      else:
          assert_allclose(y.g, 1.0)
  
file_path: nnabla/python/test/function/test_random_erase.py
imports: import pytest
  import numpy
  import nnabla
  import nnabla.functions
  from test_flip import ref_flip
  from nbla_test_utils import list_context
  from nnabla.testing import assert_allclose
label_desc: Use image node_id 2 for calling a global function with example usage: test_random_erase_backward(ctx, func_name, seed, prob, area_ratios, aspect_ratios, replacements, n, share, inplace, base_axis, func_seed, channel_last, ste_fine_grained) without return types