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)
| 203 | |
| 204 | |
| 205 | def 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 |
nothing calls this directly
no test coverage detected