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

Class OpHint

tensorflow/lite/python/op_hint.py:93–462  ·  view source on GitHub ↗

A class that helps build tflite function invocations. It allows you to take a bunch of TensorFlow ops and annotate the construction such that toco knows how to convert it to tflite. This embeds a pseudo function in a TensorFlow graph. This allows embedding high-level API usage information i

Source from the content-addressed store, hash-verified

91
92@_tf_export(v1=["lite.OpHint"])
93class OpHint(object):
94 """A class that helps build tflite function invocations.
95
96 It allows you to take a bunch of TensorFlow ops and annotate the construction
97 such that toco knows how to convert it to tflite. This embeds a pseudo
98 function in a TensorFlow graph. This allows embedding high-level API usage
99 information in a lower level TensorFlow implementation so that an alternative
100 implementation can be substituted later.
101
102 Essentially, any "input" into this pseudo op is fed into an identity, and
103 attributes are added to that input before being used by the constituent ops
104 that make up the pseudo op. A similar process is done to any output that
105 is to be exported from the current op.
106
107 """
108 # TODO(aselle): When TensorFlow functions functionality works for arbitrary
109 # constructs, this mechanism can be retired and changed to use python defun's.
110
111 # Attr constants that are used for representation in the GraphDef. These
112 # will be used on every Identity op that is involved in a total OpHint.
113
114 # Name of the OpHint function (cosmetic).
115 FUNCTION_NAME_ATTR = "_tflite_function_name"
116 # UUID of the function (each OpHint gets a new uuid).
117 FUNCTION_UUID_ATTR = "_tflite_function_uuid"
118 # The input index of the input (or nothing if it is an output).
119 FUNCTION_INPUT_INDEX_ATTR = "_tflite_function_input_index"
120 # The output index of the output (or nothing if it is an input).
121 FUNCTION_OUTPUT_INDEX_ATTR = "_tflite_function_output_index"
122 # An index that orders aggregate arguments. Aggregate arguments are ones
123 # that are separate but will be fused horizontally. For example a static LSTM
124 # has a lstm cell for each time step. Each one has a separate opHint, but a
125 # fused SequentialLSTM will treat this as a single tensor.
126 FUNCTION_SORT_INDEX_ATTR = "_tflite_function_sort_index"
127 # The way in which multiple parts of the aggregate argument will be joined
128 # into a fused operand. Valid options are OpHint.AGGREGATE_FIRST,
129 # OpHint.AGGREGATE_LAST, OpHint.AGGREGATE_STACK.
130 FUNCTION_AGGREGATE_ATTR = "_tflite_function_aggregate"
131 # On fused OpHint stub, the order of inputs that the final LSTM call will
132 # have. What this means is that the TensorFlow order might be
133 # "foo", "bar", "stuff" and you might want the TF lite op order to be
134 # "stuff", "foo", "bar", -1 (where -1 is unused). So you would set this
135 # attribute to [2, 0, 1, -1].
136 TFLITE_INPUT_INDICES = "_tflite_input_indices"
137 # OpHint level.
138 FUNCTION_LEVEL_ATTR = "_tflite_ophint_level"
139 # Ophint internal mapping, this is for high level Ophint only.
140 # This basically contains three kinds of mapping:
141 # 1) How parental ophinted inputs map to the first child ophinted inputs;
142 # 2) How internal children nodes are connected;
143 # 3) How parental ophinted outputs map to the last child ophinted outputs.
144 CHILDREN_INPUTS_MAPPINGS = "_tflite_children_ophint_inputs_mapping"
145
146 # Types of aggregations
147 # stack: stacks all ophints with matching tags. i.e. for a static rnn.
148 # specifically, this is good for an input or output to a static rnn cell.
149 AGGREGATE_STACK = "stack"
150 # first: only takes the first output (one with lowest sort index)

Callers 3

__init__Method · 0.90
__init__Method · 0.90
dynamic_rnnFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected