code: def auto_forward_backward_tester(
      ctx, vinputs, func, func_args, func_kwargs, backward
  ):
      """Check if auto-forward and static mode give the same (close) gradients.
  
      It mainly tests clear buffer mechanism in auto-forward mode.
  
      """
      from contextlib import contextmanager
  
      def zero_grads():
          for v, b in zip(vinputs, backward):
              if v is not None and b:
                  v.grad.zero()
  
      def build_function():
          zero_grads()
          vinputs2 = [
              ((F.identity(v) if b else v) if v is not None else None)
              for v, b in zip(vinputs, backward)
          ]
          outputs = func(*(vinputs2 + func_args), **func_kwargs)
          outputs = force_tuple(outputs)
          if len(outputs) == 1:
              return outputs[0]
          return F.add_n(
              *[(F.sum(o) if o.ndim != 0 else o) for o in outputs]
          )
  
      def copy_grads():
          return [
              i.g.copy() if i is not None and b else None
              for i, b in zip(vinputs, backward)
          ]
  
      @contextmanager
      def backup_inputs():
          bak_inputs = [
              None if v is None else v.data.get_data("r").copy()
              for v in vinputs
          ]
          try:
              yield
          finally:
              for v, bak in zip(vinputs, bak_inputs):
                  if v is not None:
                      v.d = bak
  
      # Static reference.
      with backup_inputs():
          with nn.context_scope(ctx):
              out = build_function()
          out.forward()
          out.backward()
          ref_grads = copy_grads()
  
      # Auto-forward.
      with nn.context_scope(ctx), nn.auto_forward():
          out = build_function()
      out.backward(clear_buffer=True)
      act_grads = copy_grads()
      for i, (v, b) in enumerate(zip(vinputs, backward)):
          if v is None or not b:
              continue
          err_msg = f"Error in {i}-th input in auto-forward. It suggests that any member function of grad_depends_* or auto_grad_depends_* in nbla::Function is not properly defined."
          assert_allclose(ref_grads[i], act_grads[i], err_msg=err_msg)
  
imports: from nnabla.utils import nnabla_pb2
  from six.moves import filter
  import copy
  import nnabla
  import nnabla.ext_utils
  import nnabla.functions
  import nnabla.utils.converter
  import nnabla.dtypes
  from nnabla.testing import assert_allclose
  import numpy
  import numpy
  import platform
label_desc: Use image node_id 17 for calling a global function with example usage: auto_forward_backward_tester(ctx, vinputs, func, func_args, func_kwargs, backward) and returns: F, unknown, outputs