MCPcopy Create free account
hub / github.com/pytorch/pytorch / _draw_steps

Function _draw_steps

caffe2/python/net_drawer.py:205–255  ·  view source on GitHub ↗
(steps, g, skip_step_edges=False)

Source from the content-addressed store, hash-verified

203
204
205def _draw_steps(steps, g, skip_step_edges=False): # noqa
206 kMaxParallelSteps = 3
207
208 def get_label():
209 label = [step.name + '\n']
210 if step.report_net:
211 label.append('Reporter: {}'.format(step.report_net))
212 if step.should_stop_blob:
213 label.append('Stopper: {}'.format(step.should_stop_blob))
214 if step.concurrent_substeps:
215 label.append('Concurrent')
216 if step.only_once:
217 label.append('Once')
218 return '\n'.join(label)
219
220 def substep_edge(start, end):
221 return pydot.Edge(start, end, arrowhead='dot', style='dashed')
222
223 nodes = []
224 for i, step in enumerate(steps):
225 parallel = step.concurrent_substeps
226
227 nodes.append(pydot.Node(_escape_label(get_label()), **OP_STYLE))
228 g.add_node(nodes[-1])
229
230 if i > 0 and not skip_step_edges:
231 g.add_edge(pydot.Edge(nodes[-2], nodes[-1]))
232
233 if step.network:
234 sub_nodes = _draw_nets(step.network, g)
235 elif step.substep:
236 if parallel:
237 sub_nodes = _draw_steps(
238 step.substep[:kMaxParallelSteps], g, skip_step_edges=True)
239 else:
240 sub_nodes = _draw_steps(step.substep, g)
241 else:
242 raise ValueError('invalid step')
243
244 if parallel:
245 for sn in sub_nodes:
246 g.add_edge(substep_edge(nodes[-1], sn))
247 if len(step.substep) > kMaxParallelSteps:
248 ellipsis = pydot.Node('{} more steps'.format(
249 len(step.substep) - kMaxParallelSteps), **OP_STYLE)
250 g.add_node(ellipsis)
251 g.add_edge(substep_edge(nodes[-1], ellipsis))
252 else:
253 g.add_edge(substep_edge(nodes[-1], sub_nodes[0]))
254
255 return nodes
256
257
258def GetPlanGraph(plan_def, name=None, rankdir='TB'):

Callers 1

GetPlanGraphFunction · 0.85

Calls 8

_escape_labelFunction · 0.85
get_labelFunction · 0.85
_draw_netsFunction · 0.85
substep_edgeFunction · 0.85
add_edgeMethod · 0.80
appendMethod · 0.45
add_nodeMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…