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

Function netbuilder

caffe2/experiments/python/SparseTransformer.py:175–206  ·  view source on GitHub ↗
(model)

Source from the content-addressed store, hash-verified

173
174
175def netbuilder(model):
176 print("Welcome to model checker")
177 proto = model.net.Proto()
178 net_name2id = {}
179 net_id2node = {}
180 net_root = NetDefNode("net_root", "root", None)
181
182 for op_id, op in enumerate(proto.op):
183 if op.type == "Print":
184 continue
185 op_name = '%s/%s (op#%d)' % (op.name, op.type, op_id) \
186 if op.name else '%s (op#%d)' % (op.type, op_id)
187 # print(op_name)
188 op_node = NetDefNode(op_name, op.type, op=op)
189 net_id2node[op_id] = op_node
190
191 if_has_layer_input = False
192 for input_name in op.input:
193 if input_name not in net_name2id:
194 # assume that un_occured name are non_layers
195 # TODO: write a non-layer checker and log it
196 continue
197 op_node.insertInput(net_id2node[net_name2id[input_name]])
198 if_has_layer_input = True
199
200 if not if_has_layer_input:
201 op_node.insertInput(net_root)
202
203 for output_name in op.output:
204 net_name2id[output_name] = op_id
205
206 return net_root, net_name2id, net_id2node

Callers

nothing calls this directly

Calls 3

insertInputMethod · 0.95
NetDefNodeClass · 0.85
ProtoMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…