code: def _grad_func(y, xs, xs_required, tape):
      """Gradient calculation function."""
      # Creating a zero gradient nest for the case where no gradients are computed
      grads_ = ivy.nested_map(
          lambda x: ivy.to_native(ivy.zeros_like(x)),
          xs_required,
          include_derived=True,
          shallow=False,
      )
  
      # Gradient calculation
      grads = tape.gradient(y, xs_required)
  
      # Returning zeros if no gradients are computed for consistent results
      if isinstance(xs, ivy.NativeArray):
          grads = grads_ if grads is None else grads
      else:
          grads = ivy.nested_map(
              lambda x: 0 if x is None else x,
              grads,
              include_derived=True,
          )
          if isinstance(grads, ivy.Container):
              grads += grads_
          else:
              grads = ivy.nested_multi_map(
                  lambda x, _: (x[0] + x[1]), [grads, grads_]
              )
      return grads
  
file_path: ivy/ivy/functional/backends/tensorflow/gradients.py
imports: import tensorflow
  from typing import Sequence, Union, Optional, Callable
  import ivy
  from ivy.func_wrapper import outputs_to_ivy_arrays, inputs_to_native_arrays
  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 4 for calling a global function with example usage: _grad_func(y, xs, xs_required, tape) and returns: grads