code: def test_grad_resnet(
      seed, ctx, auto_forward, flag_grad_outputs, act, inplace, shared
  ):
      backend = ctx.backend[0].split(":")[0]
      if backend == "cuda":
          pytest.skip(
              "CUDA Convolution N-D is only supported in CUDNN extension"
          )
  
      if (
          sys.version_info[1] >= 9
          and auto_forward == True
          and backend == "cudnn"
      ):
          pytest.skip(
              "Skip to avoid random KeyError with _ModuleLock. Referred to nnabla-ext-cuda issue #481."
          )
  
      nn.clear_parameters()
  
      # Settings
      nn.set_default_context(ctx)
      nn.set_auto_forward(auto_forward)
      b, c, h, w = 4, 3, 32, 32
      n_cls = 10
      rng = np.random.RandomState(seed)
  
      # Network
      x = nn.Variable.from_numpy_array(rng.randn(b, c, h, w))
      y = nn.Variable.from_numpy_array(
          rng.randint(0, n_cls, b).reshape(b, 1)
      )
      p = SmallResNet(x, act=act, inplace=inplace, shared=shared)
      loss = F.mean(F.softmax_cross_entropy(p, y))
  
      # Zerograd, Forward, Backward on the forward graph
      inputs = nn.get_parameters().values()
      [inp.grad.zero() for inp in inputs]
      grad = (
          nn.NdArray.from_numpy_array(np.asarray(rng.randn()))
          if flag_grad_outputs
          else 1
      )
      if not auto_forward:
          loss.forward()
      loss.backward(grad)
  
      # Grad
      grad_outputs = grad if flag_grad_outputs else None
      grads = nn.grad([loss], inputs, [grad_outputs])
      if not auto_forward:
          F.sink(*grads, one_input_grad=1).forward()
  
      # Check between results of var.backward and nn.grad
      for inp, grad in zip(inputs, grads):
          assert_allclose(inp.g, grad.d, atol=1e-6)
  
imports: import sys
  import pytest
  import numpy
  import nnabla
  import nnabla.functions
  import nnabla.parametric_functions
  import nnabla.initializer
  from nnabla.ext_utils import get_extension_context
  from nbla_test_utils import list_context
  from nnabla.testing import assert_allclose
  from nnabla.function import PythonFunction
  from nnabla.backward_functions import registry, register
label_desc: Use image node_id 2 for calling a global function with example usage: test_grad_resnet(seed, ctx, auto_forward, flag_grad_outputs, act, inplace, shared) without return types