Prunes unconnected ops as listed in _UNCONNECTED_OPS_TO_PRUNE. Args: prune_graph: A tensorflow graph from which we wish to prune unconnected ops as listed in _UNCONNECTED_OPS_TO_PRUNE. In general, these ops should have no inputs and no consumers. These can often be left behind du
(prune_graph)
| 1680 | |
| 1681 | |
| 1682 | def prune_unconnected_ops_from_xla(prune_graph): |
| 1683 | """Prunes unconnected ops as listed in _UNCONNECTED_OPS_TO_PRUNE. |
| 1684 | |
| 1685 | Args: |
| 1686 | prune_graph: A tensorflow graph from which we wish to prune unconnected ops |
| 1687 | as listed in _UNCONNECTED_OPS_TO_PRUNE. In general, these ops should have |
| 1688 | no inputs and no consumers. These can often be left behind due to graph |
| 1689 | construction rewiring (for instance TF-Hub). While they never execute, |
| 1690 | they will cause XLA compile to fail so we strip them from XLA compile by |
| 1691 | removing the tpu_replicate attribute. |
| 1692 | """ |
| 1693 | # Scan over the top level graph and all function graphs. |
| 1694 | for graph in [prune_graph] + [ |
| 1695 | f for f in prune_graph._functions.values() # pylint: disable=protected-access |
| 1696 | ]: |
| 1697 | if not isinstance(graph, ops.Graph): |
| 1698 | continue |
| 1699 | for op in graph.get_operations(): |
| 1700 | if op.type not in _UNCONNECTED_OPS_TO_PRUNE: |
| 1701 | continue |
| 1702 | outputs_consumed = False |
| 1703 | for output in op.outputs: |
| 1704 | if output.consumers(): |
| 1705 | outputs_consumed = True |
| 1706 | break |
| 1707 | if not outputs_consumed: |
| 1708 | logging.info( |
| 1709 | "Pruning OP %s of type %s from XLA Compile due to " |
| 1710 | "it being disconnected.", op.name, op.type) |
| 1711 | op._clear_attr(_TPU_REPLICATE_ATTR) # pylint: disable=protected-access |
nothing calls this directly
no test coverage detected