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

Method CheckNet

caffe2/python/device_checker.py:75–119  ·  view source on GitHub ↗

Checks a network by inspecting all of its intermediate results, and see if things match.

(self, net, inputs=None, blobs_to_check=None, ignore=None)

Source from the content-addressed store, hash-verified

73 return success
74
75 def CheckNet(self, net, inputs=None, blobs_to_check=None, ignore=None):
76 """Checks a network by inspecting all of its intermediate results, and
77 see if things match.
78 """
79 if inputs is None:
80 inputs = {}
81 if ignore is None:
82 ignore = set()
83 old_ws_name = workspace.CurrentWorkspace()
84 results = []
85 if blobs_to_check is None:
86 blobs_to_check = sum([list(op.output) for op in net.op], [])
87 blobs_to_check = [b for b in blobs_to_check if b not in ignore]
88 workspace.SwitchWorkspace("_device_check_", True)
89 for device_option in self._device_options:
90 for name, arr in inputs.items():
91 # print 'feeding', name
92 workspace.FeedBlob(name, arr, device_option)
93 for op in net.op:
94 op.device_option.CopyFrom(device_option)
95 workspace.RunNetOnce(net)
96 results.append(
97 [workspace.FetchBlob(name) for name in blobs_to_check]
98 )
99 # After running on all devices, check correctness
100 success = True
101 for i in range(1, len(results)):
102 for j in range(len(blobs_to_check)):
103 x = results[i][j]
104 y = results[0][j]
105 if not np.allclose(x, y,
106 atol=self._threshold, rtol=self._threshold):
107 print('Failure in checking device option {}'
108 ' and output {}. The outputs are:'
109 .format(i, blobs_to_check[j]))
110 print(x.flatten())
111 print(y.flatten())
112 print(np.max(np.abs(x - y)))
113 success = False
114 # else:
115 # print ('Passed device pair (%d, %d), %s %s: %s' %
116 # (i, j, blobs_to_check[j], y.shape,
117 # str(y.flatten())))
118 workspace.SwitchWorkspace(old_ws_name)
119 return success

Callers 1

_testMiniAlexNetMethod · 0.95

Calls 9

listFunction · 0.85
maxMethod · 0.80
sumFunction · 0.50
rangeFunction · 0.50
itemsMethod · 0.45
appendMethod · 0.45
formatMethod · 0.45
flattenMethod · 0.45
absMethod · 0.45

Tested by 1

_testMiniAlexNetMethod · 0.76