code: def update_regroup(extended, updates, group):
      """Regroup for an update, with dependencies to ensure all updates execute."""
      if not group:
          regrouped = regroup(updates, values_lib.Mirrored)
          return nest.map_structure(
              extended._local_results, regrouped
          )  # pylint: disable=protected-access
  
      def _make_grouped_mirrored(values):
          """Convert per-replica list `values` into Mirrored type with grouping."""
          if len(values) == 1:
              return values_lib.Mirrored(values)
  
          # Make sure we run all updates. Without this, something like
          # session.run(extended.update(...)) may only update one replica.
          g = control_flow_ops.group(values)
  
          # If values is just ops, the grouping is enough. Everything in values
          # should have the same type, since we expect every replica to be performing
          # the same computation.
          if not all(tensor_util.is_tf_type(v) for v in values):
              return g
  
          # Otherwise we need tensors with the same values as `values`, but
          # that have a dependency on `g`.
          with_dep = []
          for v in values:
              with ops.device(v.device), ops.control_dependencies([g]):
                  with_dep.append(array_ops.identity(v))
  
          return values_lib.Mirrored(with_dep)
  
      return regroup(updates, _make_grouped_mirrored)
  
imports: from collections import abc
  import contextlib
  import threading
  from tensorflow.python.distribute import distribute_lib
  from tensorflow.python.distribute import tpu_values
  from tensorflow.python.distribute import values
  from tensorflow.python.distribute.reduce_util import ReduceOp
  from tensorflow.python.eager import context
  from tensorflow.python.eager import record
  from tensorflow.python.framework import composite_tensor
  from tensorflow.python.framework import ops
  from tensorflow.python.framework import tensor_util
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import control_flow_ops
  from tensorflow.python.ops import resource_variable_ops
  from tensorflow.python.ops import variable_scope
  from tensorflow.python.ops.losses import losses_impl
  from tensorflow.python.util import nest
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 6 for calling a global function with example usage: update_regroup(extended, updates, group) and returns: regroup, nest, values_lib, values_lib, g