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

Function GetPydotGraph

caffe2/python/net_drawer.py:86–131  ·  view source on GitHub ↗
(
    operators_or_net,
    name=None,
    rankdir='LR',
    op_node_producer=None,
    blob_node_producer=None
)

Source from the content-addressed store, hash-verified

84 return ReallyGetBlobNode
85
86def GetPydotGraph(
87 operators_or_net,
88 name=None,
89 rankdir='LR',
90 op_node_producer=None,
91 blob_node_producer=None
92):
93 if op_node_producer is None:
94 op_node_producer = GetOpNodeProducer(False, **OP_STYLE)
95 if blob_node_producer is None:
96 blob_node_producer = GetBlobNodeProducer(**BLOB_STYLE)
97 operators, name = _rectify_operator_and_name(operators_or_net, name)
98 graph = pydot.Dot(name, rankdir=rankdir)
99 pydot_nodes = {}
100 pydot_node_counts = defaultdict(int)
101 for op_id, op in enumerate(operators):
102 op_node = op_node_producer(op, op_id)
103 graph.add_node(op_node)
104 # print 'Op: %s' % op.name
105 # print 'inputs: %s' % str(op.input)
106 # print 'outputs: %s' % str(op.output)
107 for input_name in op.input:
108 if input_name not in pydot_nodes:
109 input_node = blob_node_producer(
110 _escape_label(
111 input_name + str(pydot_node_counts[input_name])),
112 label=_escape_label(input_name),
113 )
114 pydot_nodes[input_name] = input_node
115 else:
116 input_node = pydot_nodes[input_name]
117 graph.add_node(input_node)
118 graph.add_edge(pydot.Edge(input_node, op_node))
119 for output_name in op.output:
120 if output_name in pydot_nodes:
121 # we are overwriting an existing blob. need to update the count.
122 pydot_node_counts[output_name] += 1
123 output_node = blob_node_producer(
124 _escape_label(
125 output_name + str(pydot_node_counts[output_name])),
126 label=_escape_label(output_name),
127 )
128 pydot_nodes[output_name] = output_node
129 graph.add_node(output_node)
130 graph.add_edge(pydot.Edge(op_node, output_node))
131 return graph
132
133
134def GetPydotGraphMinimal(

Callers 1

mainFunction · 0.85

Calls 6

GetOpNodeProducerFunction · 0.85
GetBlobNodeProducerFunction · 0.85
_escape_labelFunction · 0.85
add_edgeMethod · 0.80
add_nodeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…