code: def gradient_test(
      *,
      fn,
      all_as_kwargs_np,
      args_np,
      kwargs_np,
      input_dtypes,
      test_flags,
      test_trace: bool = False,
      rtol_: Optional[float] = None,
      atol_: float = 1e-06,
      tolerance_dict=None,
      xs_grad_idxs=None,
      ret_grad_idxs=None,
      backend_to_test: str,
      ground_truth_backend: str,
      on_device: str,
  ):
      # extract all arrays from the arguments and keyword arguments
      arg_np_vals, args_idxs, _ = _get_nested_np_arrays(args_np)
      kwarg_np_vals, kwargs_idxs, _ = _get_nested_np_arrays(kwargs_np)
  
      if mod_backend[backend_to_test]:
          # do this using multiprocessing
          proc, input_queue, output_queue = mod_backend[backend_to_test]
          input_queue.put(
              (
                  "gradient_backend_computation",
                  backend_to_test,
                  args_np,
                  arg_np_vals,
                  args_idxs,
                  kwargs_np,
                  kwarg_np_vals,
                  kwargs_idxs,
                  input_dtypes,
                  test_flags,
                  on_device,
                  fn,
                  test_trace,
                  xs_grad_idxs,
                  ret_grad_idxs,
              )
          )
          grads_np_flat = output_queue.get()
  
      else:
          grads_np_flat = test_gradient_backend_computation(
              backend_to_test,
              args_np,
              arg_np_vals,
              args_idxs,
              kwargs_np,
              kwarg_np_vals,
              kwargs_idxs,
              input_dtypes,
              test_flags,
              on_device,
              fn,
              test_trace,
              xs_grad_idxs,
              ret_grad_idxs,
          )
  
      if mod_backend[ground_truth_backend]:
          # do this using multiprocessing
          proc, input_queue, output_queue = mod_backend[
              ground_truth_backend
          ]
          input_queue.put(
              (
                  "gradient_ground_truth_computation",
                  ground_truth_backend,
                  on_device,
                  fn,
                  input_dtypes,
                  all_as_kwargs_np,
                  args_np,
                  arg_np_vals,
                  args_idxs,
                  kwargs_np,
                  kwarg_np_vals,
                  test_flags,
                  kwargs_idxs,
                  test_trace,
                  xs_grad_idxs,
                  ret_grad_idxs,
              )
          )
          grads_np_from_gt_flat = output_queue.get()
      else:
          grads_np_from_gt_flat = (
              test_gradient_ground_truth_computation(
                  ground_truth_backend,
                  on_device,
                  fn,
                  input_dtypes,
                  all_as_kwargs_np,
                  args_np,
                  arg_np_vals,
                  args_idxs,
                  kwargs_np,
                  kwarg_np_vals,
                  test_flags,
                  kwargs_idxs,
                  test_trace,
                  xs_grad_idxs,
                  ret_grad_idxs,
              )
          )
  
      assert len(grads_np_flat) == len(grads_np_from_gt_flat), (
          f"result length mismatch: {grads_np_flat} ({len(grads_np_flat)}) !="
          f" {grads_np_from_gt_flat} ({len(grads_np_from_gt_flat)})"
      )
  
      value_test(
          ret_np_flat=grads_np_flat,
          ret_np_from_gt_flat=grads_np_from_gt_flat,
          rtol=rtol_,
          atol=atol_,
          specific_tolerance_dict=tolerance_dict,
          backend=backend_to_test,
          ground_truth_backend=ground_truth_backend,
      )
  
imports: import copy
  import time
  from typing import Union, List, Optional
  import numpy
  import types
  import importlib
  import inspect
  from collections import OrderedDict
  from .globals import mod_backend
  from .pipeline_helper import BackendHandler, BackendHandlerMode, get_frontend_config
  import ivy
  from ivy_tests.test_ivy.helpers.test_parameter_flags import FunctionTestFlags
  import ivy_tests.test_ivy.helpers.test_parameter_flags
  import ivy_tests.test_ivy.helpers.globals
  from ivy.functional.ivy.data_type import _get_function_list, _get_functions_from_string
  from ivy_tests.test_ivy.test_frontends import NativeClass
  from ivy_tests.test_ivy.helpers.structs import FrontendMethodData
  from ivy_tests.test_ivy.helpers.testing_helpers import _create_transpile_report
  from .assertions import value_test, assert_same_type, check_unsupported_dtype
label_desc: Use image node_id 12 for calling a global function with example usage: gradient_test() without return types