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

Function PlaceGraph

tensorflow/python/grappler/graph_placer.py:33–115  ·  view source on GitHub ↗

Place the provided metagraph. Args: metagraph: the metagraph to place. cluster: an optional set of hardware resource to optimize the placement for. If none is specified, we'll optimize the placement for the hardware available on the local machine. allotted_time: the maximu

(metagraph,
               cluster=None,
               allotted_time=3600,
               hparams=None,
               verbose=False)

Source from the content-addressed store, hash-verified

31
32
33def PlaceGraph(metagraph,
34 cluster=None,
35 allotted_time=3600,
36 hparams=None,
37 verbose=False):
38 """Place the provided metagraph.
39
40 Args:
41 metagraph: the metagraph to place.
42 cluster: an optional set of hardware resource to optimize the placement for.
43 If none is specified, we'll optimize the placement for the hardware
44 available on the local machine.
45 allotted_time: the maximum amount to time in seconds to spend optimizing
46 the placement.
47 hparams: hyperparameters used to fine tune the placer.
48 verbose: prints debug information if True.
49
50 Returns:
51 The placed metagraph.
52 """
53 if cluster is None:
54 cluster = gcluster.Cluster()
55
56 # Optimize the metagraph to speedup the placement
57 config = config_pb2.ConfigProto()
58 optimized_graph = tf_optimizer.OptimizeGraph(
59 config, metagraph, verbose=verbose, cluster=cluster)
60 optimized_metagraph = meta_graph_pb2.MetaGraphDef()
61 optimized_metagraph.CopyFrom(metagraph)
62 optimized_metagraph.graph_def.CopyFrom(optimized_graph)
63
64 item = gitem.Item(optimized_metagraph)
65
66 # Measure the runtime achievable with the original placement.
67 try:
68 _, original_run_time, _ = cluster.MeasureCosts(item)
69 if verbose:
70 print("Runtime for original placement: " + str(original_run_time))
71 except errors.OpError as e:
72 if verbose:
73 print("Original placement isn't feasible: " + str(e))
74 original_run_time = hparams.failing_signal
75
76 if hparams is None:
77 hparams = hierarchical_controller.hierarchical_controller_hparams()
78 # We run with a single child
79 hparams.num_children = 1
80
81 with tf_ops.Graph().as_default():
82 # Place all the nodes of the controller on the CPU. We don't want them to
83 # fight for accelerator memory with the model to optimize.
84 with tf_ops.device("/device:CPU:0"):
85 model = hierarchical_controller.HierarchicalController(
86 hparams, item, cluster)
87 ops = model.build_controller()
88 session_creator = training.ChiefSessionCreator()
89 with training.MonitoredSession(session_creator=session_creator) as sess:
90 start_time = time.time()

Callers

nothing calls this directly

Calls 15

MeasureCostsMethod · 0.95
build_controllerMethod · 0.95
generate_groupingMethod · 0.95
generate_placementMethod · 0.95
eval_placementMethod · 0.95
update_rewardMethod · 0.95
process_rewardMethod · 0.95
ItemMethod · 0.80
timeMethod · 0.80
export_placementMethod · 0.80
ClusterMethod · 0.45

Tested by

no test coverage detected