class_docstr: A `ControlFlowContext` for nodes inside a TPU computation.
  
  The primary role of `TPUReplicateContext` is to mark operators inside a
  tpu.replicate() computation with the attribute "_tpu_replicate=XYZ", where XYZ
  is a unique name.
  
  We use a `ControlFlowContext` to perform the annotation since it integrates
  with Tensorflow constructs like ResourceVariables. For example, if a
  `ResourceVariable` is constructed inside a tpu.replicate() block, the
  `ResourceVariable` implementation can use
  `with ops.control_dependencies(None)` to build the variable's definition
  outside the replicated computation.
class_docstr_tok: ["A","`","ControlFlowContext","`","for","nodes","inside","a","TPU","computation",".","The","primary","role","of","`","TPUReplicateContext","`","is","to","mark","operators","inside","a","tpu.replicate","(",")","computation","with","the","attribute","``","_tpu_replicate=XYZ","''",",","where","XYZ","is","a","unique","name",".","We","use","a","`","ControlFlowContext","`","to","perform","the","annotation","since","it","integrates","with","Tensorflow","constructs","like","ResourceVariables",".","For","example",",","if","a","`","ResourceVariable","`","is","constructed","inside","a","tpu.replicate","(",")","block",",","the","`","ResourceVariable","`","implementation","can","use","`","with","ops.control_dependencies","(","None",")","`","to","build","the","variable","'s","definition","outside","the","replicated","computation","."]
docstr: Remove any external control dependency on this op.
docstr_tok: ["Remove","any","external","control","dependency","on","this","op","."]
code: def _RemoveExternalControlEdges(
      self, op: ops.Operation
  ) -> Tuple[List[ops.Operation], List[ops.Operation]]:
      """Remove any external control dependency on this op."""
      internal_control_inputs = []
      external_control_inputs = []
      for x in op.control_inputs:
          # pylint: disable=protected-access
          is_internal_op = False
          ctxt = x._get_control_flow_context()
          while ctxt is not None:
              if ctxt == self:
                  is_internal_op = True
                  break
              ctxt = ctxt._outer_context
          if is_internal_op:
              internal_control_inputs.append(x)
          else:
              external_control_inputs.append(x)
          # pylint: enable=protected-access
      # pylint: disable=protected-access
      op._remove_all_control_inputs()
      op._add_control_inputs(internal_control_inputs)
      # pylint: enable=protected-access
      return internal_control_inputs, external_control_inputs
  
imports: from typing import Any, Callable, List, Optional, Text, Tuple, Union
  from absl import logging
  from tensorflow.core.framework import attr_value_pb2
  from tensorflow.python.distribute import device_util
  from tensorflow.python.distribute import distribute_lib
  from tensorflow.python.framework import device
  from tensorflow.python.framework import errors
  from tensorflow.python.framework import func_graph
  from tensorflow.python.framework import ops
  from tensorflow.python.ops import array_ops
  from tensorflow.python.ops import control_flow_ops
  from tensorflow.python.ops import variables
  from tensorflow.python.tpu import device_assignment
  from tensorflow.python.tpu.ops import tpu_ops
  from tensorflow.python.types import core
  from tensorflow.python.util import compat
  from tensorflow.python.util.tf_export import tf_export
label_desc: Use image node_id 10 for calling the TPUReplicateContext obj's underlying member method code with example usage: obj._RemoveExternalControlEdges(op) and returns: internal_control_inputs,  external_control_inputs