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

Function lift_to_graph

tensorflow/python/eager/lift_to_graph.py:205–359  ·  view source on GitHub ↗

Copies the tensor and all its inputs recursively to the outer graph. Args: tensors: The Tensors to lift. graph: The graph to lift to. sources: Optional sequence of nodes to start from. If omitted the whole subgraph which feeds into `init_tensor` is lifted. disallowed_placeho

(tensors,
                  graph,
                  sources=None,
                  disallowed_placeholders=None,
                  add_sources=False,
                  handle_captures=False,
                  base_graph=None,
                  op_map=None)

Source from the content-addressed store, hash-verified

203
204
205def lift_to_graph(tensors,
206 graph,
207 sources=None,
208 disallowed_placeholders=None,
209 add_sources=False,
210 handle_captures=False,
211 base_graph=None,
212 op_map=None):
213 """Copies the tensor and all its inputs recursively to the outer graph.
214
215 Args:
216 tensors: The Tensors to lift.
217 graph: The graph to lift to.
218 sources: Optional sequence of nodes to start from. If omitted the whole
219 subgraph which feeds into `init_tensor` is lifted.
220 disallowed_placeholders: An optional set of ops which may not appear in the
221 lifted graph. Defaults to all placeholders.
222 add_sources: A boolean indicating whether placeholders which are not in
223 sources should be allowed.
224 handle_captures: A boolean indicating whether to re-capture s in the new
225 graph or simply create a vanilla placeholder.
226 base_graph: The graph from which to lift ops. This will be inferred if not
227 specified.
228 op_map: A map contains all the existing nodes that have been lifted to the
229 destination graph, so they won't be lifted and copied again.
230
231 Returns:
232 A mapping from ops in the current default graph to ops in `graph`.
233
234 Raises:
235 UnliftableError: If a placeholder blocks lifting.
236 """
237 variable_init_tensors = []
238 init_tensors = []
239 for tensor in tensors:
240 if isinstance(tensor, resource_variable_ops.ResourceVariable):
241 variable_init_tensors.append(tensor)
242 else:
243 init_tensors.append(tensor)
244 base_graph = base_graph or init_tensors[0].graph
245 op_map = op_map or object_identity.ObjectIdentityDictionary()
246
247 # Check that the initializer does not depend on any placeholders.
248 sources = object_identity.ObjectIdentitySet(sources or [])
249 visited_ops = set([x.op for x in sources])
250 op_outputs = collections.defaultdict(set)
251
252 # First we extract the subgraph between init_tensors and sources.
253 for init_tensor in init_tensors:
254 sources.update(op_selector.map_subgraph(
255 init_tensor=init_tensor,
256 sources=sources,
257 disallowed_placeholders=disallowed_placeholders,
258 visited_ops=visited_ops,
259 op_outputs=op_outputs,
260 add_sources=add_sources))
261
262 # Try to topologically sort the nodes we've extracted. Now we know how many of

Callers

nothing calls this directly

Calls 14

updateMethod · 0.95
allFunction · 0.85
_copy_sourceFunction · 0.85
_copy_non_sourceFunction · 0.85
_mutation_lockMethod · 0.80
_update_inputMethod · 0.80
_add_control_inputMethod · 0.80
_as_operationFunction · 0.70
appendMethod · 0.45
popMethod · 0.45
addMethod · 0.45
as_defaultMethod · 0.45

Tested by

no test coverage detected