code: def _grad_fn(func_graph, grads):
      """The gradient function for each conditional branch.
  
      This function builds the gradient graph of the corresponding forward-pass
      conditional branch in `func_graph`. This is done by differentiating
      func_graph's outputs w.r.t. its inputs.
  
      Args:
        func_graph: FuncGraph. The corresponding forward-pass function.
        grads: The list of input gradient Tensors.
  
      Returns:
        The output gradient Tensors.
      """
      # Filter out untrainable function outputs.
      # NOTE(skyewm): If we don't do this, the untrainable tensors can sometimes
      # cause _GradientsHelper to raise an exception (e.g. the implementation
      # doesn't expect 'ys' to contain boolean tensors).
      assert len(func_graph.outputs) == len(grads)
      ys = []
      grad_ys = []
      for y, grad_y in zip(func_graph.outputs, grads):
          if not backprop_util.IsTrainable(y):
              continue
          ys.append(y)
          grad_ys.append(grad_y)
  
      # Build the gradient graph. Note that this builds the gradient computation of
      # func_graph in the current graph, which requires capturing tensors from
      # func_graph. The captured func_graph tensors are resolved to external tensors
      # in _resolve_grad_inputs.
      result = gradients_util._GradientsHelper(
          ys, func_graph.inputs, grad_ys=grad_ys, src_graph=func_graph
      )
  
      return result
  
imports: import collections
  from tensorflow.core.framework import types_pb2
  from tensorflow.python.eager import backprop_util
  from tensorflow.python.framework import auto_control_deps
  from tensorflow.python.framework import auto_control_deps_utils
  from tensorflow.python.framework import constant_op
  from tensorflow.python.framework import dtypes
  from tensorflow.python.framework import errors_impl
  from tensorflow.python.framework import func_graph
  from tensorflow.python.framework import indexed_slices
  from tensorflow.python.framework import none_tensor
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor
  from tensorflow.python.framework import tensor_shape
  from tensorflow.python.framework import tensor_util
  from tensorflow.python.framework import type_spec
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import control_flow_util
  from tensorflow.python.ops import control_flow_util_v2
  from tensorflow.python.ops import default_gradient
  from tensorflow.python.ops import gen_functional_ops
  from tensorflow.python.ops import gen_optional_ops
  from tensorflow.python.ops import gradients_util
  from tensorflow.python.ops import handle_data_util
  from tensorflow.python.ops import math_ops
  from tensorflow.python.util import nest
label_desc: Use image node_id 9 for calling a global function with example usage: _grad_fn(func_graph, grads) and returns: result