MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _compare

Method _compare

tensorflow/compiler/tests/jit_test.py:100–137  ·  view source on GitHub ↗
(self,
               fn,
               args,
               require_kernel_launch=True,
               name=None,
               noinline=None)

Source from the content-addressed store, hash-verified

98 # node actually ran. However, it is sometimes possible for XlaCompile/XlaRun
99 # ops to be constant-folded away, so the check is optional.
100 def _compare(self,
101 fn,
102 args,
103 require_kernel_launch=True,
104 name=None,
105 noinline=None):
106 with session_lib.Session(config=NoRewriteSessionConfig()) as sess:
107 placeholders = []
108 feeds = {}
109 for arg in args:
110 placeholder = array_ops.placeholder(
111 dtypes.as_dtype(arg.dtype), list(arg.shape))
112 placeholders.append(placeholder)
113 feeds[placeholder] = arg
114
115 compiled_op = CompiledKernel(
116 fn, *placeholders, name=name, noinline=noinline)
117 direct_op = fn(*placeholders)
118
119 run_metadata = config_pb2.RunMetadata()
120 compiled = test_utils.RunWithWarmup(
121 sess, compiled_op, feeds,
122 config_pb2.RunOptions(trace_level=config_pb2.RunOptions.FULL_TRACE),
123 run_metadata)
124 print("Compiled Result {}".format(compiled))
125
126 if require_kernel_launch:
127 self.assert_(MetadataHasXlaRunOp(run_metadata))
128
129 direct = sess.run(direct_op, feeds)
130 print("Direct Result {}".format(direct))
131
132 if (isinstance(compiled, (tuple, list)) and
133 (isinstance(direct, (tuple, list)))):
134 for (x, y) in zip(compiled, direct):
135 self.assertAllClose(x, y, rtol=1e-1)
136 else:
137 self.assertAllClose(compiled, direct, rtol=1e-2)
138
139 def testNoOutputs(self):
140 with session_lib.Session() as sess:

Callers 7

testAliasingMethod · 0.95
testOneConstOutputMethod · 0.95
testSomeConstOutputsMethod · 0.95
testInt32InputMethod · 0.95
testMnistForwardFuncMethod · 0.95

Calls 11

NoRewriteSessionConfigFunction · 0.85
CompiledKernelFunction · 0.85
MetadataHasXlaRunOpFunction · 0.85
RunMetadataMethod · 0.80
fnFunction · 0.50
SessionMethod · 0.45
placeholderMethod · 0.45
appendMethod · 0.45
formatMethod · 0.45
runMethod · 0.45
assertAllCloseMethod · 0.45

Tested by

no test coverage detected