code: def grad(f, argnums=0):
      if grad.nth == 0:
          grad.f_original = f
  
      # ToDo: Return grads on nth chained calls rather than None. issue with paddle.grad.
      def _nth_derivative(n):
          def _inner(x):
              x = ivy.to_native(x)
              if n == 0:
                  x.stop_gradient = False
                  ret = (
                      grad.f_original(x)
                      if grad.f_original is not None
                      else f(x)
                  )
                  grad.nth = 0
                  return ret
              else:
                  x.stop_gradient = False
                  y = _nth_derivative(n - 1)(x)
                  y = ivy.to_native(y)
                  y_ones = paddle.ones_like(y)
                  y_ones.stop_gradient = False
                  y.stop_gradient = False
                  dy_dx = paddle.grad(
                      outputs=[y],
                      inputs=[x],
                      create_graph=True,
                      grad_outputs=y_ones,
                      retain_graph=True,
                      allow_unused=True,
                  )[0]
              return dy_dx
  
          return _inner
  
      grad.nth += 1
  
      return _nth_derivative(grad.nth)
  
file_path: ivy/ivy/functional/backends/paddle/gradients.py
imports: from typing import Optional, Callable
  import paddle
  import ivy.functional.backends.paddle
  from itertools import chain
  import ivy
  from ivy.func_wrapper import with_unsupported_device_and_dtypes
  from .None import backend_version
  from ivy.functional.ivy.gradients import _get_required_float_variables, _get_y_and_ret_idxs, _get_native_y, _set_duplicates, _process_func_ret_and_grads
label_desc: Use image node_id 12 for calling a global function with example usage: grad(f, argnums) and returns: _nth_derivative, _inner, dy_dx, ret