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

Function compile

tensorflow/python/compiler/xla/xla.py:66–110  ·  view source on GitHub ↗

Builds an operator that compiles and runs `computation` with XLA. NOTE: In eager mode, `computation` will have `@tf.function` semantics. Args: computation: A Python function that builds a computation to apply to the input. If the function takes n inputs, 'inputs' should be a list of

(computation, inputs=None)

Source from the content-addressed store, hash-verified

64
65@tf_export('xla.experimental.compile')
66def compile(computation, inputs=None): # pylint: disable=redefined-builtin
67 """Builds an operator that compiles and runs `computation` with XLA.
68
69 NOTE: In eager mode, `computation` will have `@tf.function` semantics.
70
71 Args:
72 computation: A Python function that builds a computation to apply to the
73 input. If the function takes n inputs, 'inputs' should be a list of n
74 tensors.
75
76 `computation` may return a list of operations and tensors. Tensors must
77 come before operations in the returned list. The return value of
78 `compile` is a list of tensors corresponding to the tensors from the
79 output of `computation`.
80
81 All `Operation`s returned from `computation` will be executed when
82 evaluating any of the returned output tensors.
83 inputs: A list of inputs or `None` (equivalent to an empty list). Each input
84 can be a nested structure containing values that are convertible to
85 tensors. Note that passing an N-dimension list of compatible values will
86 result in a N-dimension list of scalar tensors rather than a single Rank-N
87 tensors. If you need different behavior, convert part of inputs to tensors
88 with `tf.convert_to_tensor`.
89
90 Returns:
91 Same data structure as if computation(*inputs) is called directly with some
92 exceptions for correctness. Exceptions include:
93 1) None output: a NoOp would be returned which control-depends on
94 computation.
95 2) Single value output: A tuple containing the value would be returned.
96 3) Operation-only outputs: a NoOp would be returned which
97 control-depends on computation.
98 TODO(b/121383831): Investigate into removing these special cases.
99
100 Raises:
101 RuntimeError: if called when eager execution is enabled.
102 """
103 if context.executing_eagerly():
104 @def_function.function
105 def xla_compile_wrapper():
106 return _compile_internal(computation, inputs)
107
108 return xla_compile_wrapper()
109
110 return _compile_internal(computation, inputs)
111
112
113class XLACompileContext(control_flow_ops.XLAControlFlowContext):

Callers 1

__call__Method · 0.85

Calls 3

xla_compile_wrapperFunction · 0.85
_compile_internalFunction · 0.85
executing_eagerlyMethod · 0.80

Tested by

no test coverage detected