code: def tree_reduce(objs, func=sum):
      """
      Performs a binary tree reduce on an associative
      and commutative function in parallel across
      Dask workers. Since this supports dask.delayed
      objects, which have yet been scheduled on workers,
      it does not take locality into account. As a result,
      any local reductions should be performed before
      this function is called.
  
      Parameters
      ----------
      func : Python function or dask.delayed function
          Function to use for reduction. The reduction function
          acceps a list of objects to reduce as an argument and
          produces a single reduced object
      objs : array-like of dask.delayed or future
             objects to reduce.
  
      Returns
      -------
      reduced_result : dask.delayed or future
          if func is delayed, the result will be delayed
          if func is a future, the result will be a future
      """
  
      func = (
          dask.delayed(func) if not isinstance(func, Delayed) else func
      )
  
      while len(objs) > 1:
          new_objs = []
          n_objs = len(objs)
          for i in range(0, n_objs, 2):
              inputs = dask.delayed(objs[i : i + 2], pure=False)
              obj = func(inputs)
              new_objs.append(obj)
          wait(new_objs)
          objs = new_objs
  
      logger.debug(str(objs))
  
      return first(objs)
  
file_path: cuml/python/cuml/dask/common/func.py
imports: import cuml.internals.logger
  import dask
  from cuml.dask.common.utils import get_client
  from cuml.dask.common.part_utils import hosts_to_parts
  from cuml.dask.common.part_utils import workers_to_parts
  from dask.delayed import Delayed
  from dask.distributed import wait
  from toolz import first
label_desc: Use image node_id 2 for calling a global function with example usage: tree_reduce(objs, func) and returns: first