MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / outside_compilation

Function outside_compilation

tensorflow/python/tpu/tpu.py:536–575  ·  view source on GitHub ↗

Builds part of a computation outside any current TPU replicate scope. Args: computation: A Python function that builds the computation to place on the host. *args: the positional arguments for the computation. **kwargs: the keyword arguments for the computation. Returns:

(computation, *args, **kwargs)

Source from the content-addressed store, hash-verified

534
535@tf_export(v1=["tpu.outside_compilation"])
536def outside_compilation(computation, *args, **kwargs):
537 """Builds part of a computation outside any current TPU replicate scope.
538
539 Args:
540 computation: A Python function that builds the computation to
541 place on the host.
542 *args: the positional arguments for the computation.
543 **kwargs: the keyword arguments for the computation.
544
545 Returns:
546 The Tensors returned by computation.
547 """
548 args = [] if args is None else args
549 graph = ops.get_default_graph()
550
551 # If we are in a TPUReplicateContext, signal that we are now
552 # outside_compilation
553 initial_context = graph._get_control_flow_context() # pylint: disable=protected-access
554 context = initial_context
555 while context:
556 if isinstance(context, TPUReplicateContext):
557 context._EnterOutsideCompilationScope() # pylint: disable=protected-access
558 context = context.outer_context
559
560 retval = computation(*args, **kwargs)
561
562 # If we are in a TPUReplicateContext, signal that we are no longer
563 # outside_compilation
564 final_context = graph._get_control_flow_context() # pylint: disable=protected-access
565 if initial_context is not final_context:
566 raise NotImplementedError(
567 "Control-flow context cannot be different at start and end of an "
568 "outside_compilation scope")
569 context = initial_context
570 while context:
571 if isinstance(context, TPUReplicateContext):
572 context._ExitOutsideCompilationScope() # pylint: disable=protected-access
573 context = context.outer_context
574
575 return retval
576
577
578@tf_export(v1=["tpu.replicate"])

Callers

nothing calls this directly

Calls 4

computationFunction · 0.85

Tested by

no test coverage detected