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

Method CheckSimple

caffe2/python/device_checker.py:20–73  ·  view source on GitHub ↗

Checks the operator with different device implementations. Inputs: op: the operator to be checked. inputs: the input data in numpy arrays. outputs_to_check: the outputs to check between devices. input_device_options: a mapping from input name to a dev

(self, op, inputs, outputs_to_check,
                    input_device_options=None)

Source from the content-addressed store, hash-verified

18 self._device_options = device_options
19
20 def CheckSimple(self, op, inputs, outputs_to_check,
21 input_device_options=None):
22 """Checks the operator with different device implementations.
23
24 Inputs:
25 op: the operator to be checked.
26 inputs: the input data in numpy arrays.
27 outputs_to_check: the outputs to check between devices.
28 input_device_options: a mapping from input name to a device to use
29 (instead of self._device_options)
30 Outputs:
31 boolean: True if it passes, False if it does not pass.
32 """
33 op = copy.deepcopy(op)
34 # Entering the checker workspace
35 old_ws_name = workspace.CurrentWorkspace()
36 results = []
37 workspace.SwitchWorkspace("_device_check_", True)
38 for i, device_option in enumerate(self._device_options):
39 op.device_option.CopyFrom(device_option)
40 _input_device_options = input_device_options or \
41 InferOpBlobDevicesAsDict(op)[0]
42 print(_input_device_options)
43 for i, arr in enumerate(inputs):
44 workspace.FeedBlob(
45 op.input[i], np.array(arr),
46 _input_device_options.get(op.input[i], device_option)
47 )
48 workspace.RunOperatorOnce(op)
49 results.append(
50 [workspace.FetchBlob(op.output[idx])
51 for idx in outputs_to_check])
52 # Everything is done, reset the workspace.
53 workspace.ResetWorkspace()
54 # After running on all devices, check correctness
55 success = True
56 for i in range(1, len(self._device_options)):
57 for j in range(len(outputs_to_check)):
58 x = results[i][j]
59 y = results[0][j]
60 if not np.allclose(x, y,
61 atol=self._threshold, rtol=self._threshold):
62 print('Failure in checking device option {}'
63 ' and output {}. The outputs are:'
64 .format(i, op.output[outputs_to_check[j]]))
65 print(x.flatten())
66 print(y.flatten())
67 print(np.max(np.abs(x - y)))
68 success = False
69 # else:
70 # print ('Passed device pair (0, %d), %s %s' %
71 # (i, outputs_to_check[j], y.shape))
72 workspace.SwitchWorkspace(old_ws_name)
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

Callers 14

assertDeviceChecksMethod · 0.95
testLRNMethod · 0.45
testFlattenMethod · 0.45
testConcatNHWCMethod · 0.45
testConcatNCHWMethod · 0.45
testReluMethod · 0.45
testTanhMethod · 0.45
testAbsMethod · 0.45
testExpMethod · 0.45
testCosMethod · 0.45
testSinMethod · 0.45
testSigmoidMethod · 0.45

Calls 8

InferOpBlobDevicesAsDictFunction · 0.90
maxMethod · 0.80
rangeFunction · 0.50
getMethod · 0.45
appendMethod · 0.45
formatMethod · 0.45
flattenMethod · 0.45
absMethod · 0.45

Tested by 14

assertDeviceChecksMethod · 0.76
testLRNMethod · 0.36
testFlattenMethod · 0.36
testConcatNHWCMethod · 0.36
testConcatNCHWMethod · 0.36
testReluMethod · 0.36
testTanhMethod · 0.36
testAbsMethod · 0.36
testExpMethod · 0.36
testCosMethod · 0.36
testSinMethod · 0.36
testSigmoidMethod · 0.36