Tries to optimize the provided graph using grappler. Args: graph: A `tf.Graph` instance containing the graph to optimize. fetches: An optional list of `Tensor`s to fetch (i.e. not optimize away). Grappler uses the 'train_op' collection to look for fetches, so if not provided t
(graph, fetches=None, config_proto=None)
| 24 | |
| 25 | |
| 26 | def grappler_optimize(graph, fetches=None, config_proto=None): |
| 27 | """Tries to optimize the provided graph using grappler. |
| 28 | |
| 29 | Args: |
| 30 | graph: A `tf.Graph` instance containing the graph to optimize. |
| 31 | fetches: An optional list of `Tensor`s to fetch (i.e. not optimize away). |
| 32 | Grappler uses the 'train_op' collection to look for fetches, so if not |
| 33 | provided this collection should be non-empty. |
| 34 | config_proto: An optional `tf.compat.v1.ConfigProto` to use when rewriting |
| 35 | the graph. |
| 36 | |
| 37 | Returns: |
| 38 | A `tf.compat.v1.GraphDef` containing the rewritten graph. |
| 39 | """ |
| 40 | if config_proto is None: |
| 41 | config_proto = config_pb2.ConfigProto() |
| 42 | config_proto.graph_options.rewrite_options.min_graph_nodes = -1 |
| 43 | if fetches is not None: |
| 44 | for fetch in fetches: |
| 45 | graph.add_to_collection('train_op', fetch) |
| 46 | metagraph = saver.export_meta_graph(graph_def=graph.as_graph_def()) |
| 47 | return tf_optimizer.OptimizeGraph(config_proto, metagraph) |
nothing calls this directly
no test coverage detected