code: def process_grad(grad):
      from tensorflow.python.framework import ops
      import tensorflow as tf
  
      if grad is not None:
          grad = ops.convert_to_tensor_or_indexed_slices(grad)
          if isinstance(grad, ops.IndexedSlices):
              # In IndexedSlices is not supported in java api, we have to convert it to
              # a dense tensor. This operation is potentially expensive, but there seems
              # no work around
              grad = tf.unsorted_segment_sum(
                  grad.values, grad.indices, grad.dense_shape[0]
              )
      return grad
  
file_path: BigDL/python/dllib/src/bigdl/dllib/utils/tf.py
imports: import os
  import json
  import copy
  import tempfile
  import re
  import shutil
  from bigdl.dllib.utils.file_utils import put_local_file_to_remote, get_remote_file_to_local, get_file_list, is_local_path
  from bigdl.dllib.utils.log4Error import *
label_desc: Use image node_id 1 for calling a global function with example usage: process_grad(grad) and returns: grad