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

Function grappler_optimize

tensorflow/python/kernel_tests/signal/test_util.py:26–47  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

24
25
26def 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)

Callers

nothing calls this directly

Calls 4

add_to_collectionMethod · 0.80
as_graph_defMethod · 0.80
export_meta_graphMethod · 0.45
OptimizeGraphMethod · 0.45

Tested by

no test coverage detected