|
5 | 5 | import os |
6 | 6 | import shutil |
7 | 7 | import yaml |
| 8 | +import platform |
8 | 9 | import numpy as np |
9 | 10 | from neural_compressor.adaptor.tf_utils.quantize_graph.quantize_graph_for_intel_cpu import QuantizeGraphForIntel |
10 | 11 | from neural_compressor.adaptor.tf_utils.graph_rewriter.generic.strip_unused_nodes import StripUnusedNodesOptimizer |
11 | 12 | from neural_compressor.adaptor.tf_utils.graph_rewriter.generic.fold_batch_norm import FoldBatchNormNodesOptimizer |
12 | 13 | from neural_compressor.adaptor.tensorflow import TensorflowQuery |
13 | 14 | from neural_compressor.adaptor.tf_utils.util import disable_random |
14 | | -from neural_compressor.experimental import Quantization, common |
| 15 | +from neural_compressor.experimental import Quantization, Benchmark, common |
15 | 16 | from neural_compressor.utils.utility import CpuInfo |
16 | 17 | from neural_compressor.adaptor.tf_utils.util import version1_lt_version2, version1_gte_version2 |
17 | 18 |
|
@@ -217,5 +218,53 @@ def test_depthwiseconv2d_case(self): |
217 | 218 | reshape_counter += 1 |
218 | 219 | self.assertEqual(reshape_counter, 2) |
219 | 220 |
|
| 221 | + @disable_random() |
| 222 | + @unittest.skipIf(version1_lt_version2(tf.version.VERSION, '2.8.0') or \ |
| 223 | + platform.system().lower() == "windows", "Only supports tf greater 2.7.0 and Linux") |
| 224 | + def test_itex_benchmark_gpu(self): |
| 225 | + x = tf.compat.v1.placeholder(tf.float32, [1, 56, 56, 16], name="input") |
| 226 | + top_relu = tf.nn.relu(x) |
| 227 | + paddings = tf.constant([[0, 0], [1, 1], [1, 1], [0, 0]]) |
| 228 | + x_pad = tf.pad(top_relu, paddings, "CONSTANT") |
| 229 | + conv_weights = tf.compat.v1.get_variable("weight", [3, 3, 16, 16], |
| 230 | + initializer=tf.compat.v1.random_normal_initializer()) |
| 231 | + conv = tf.nn.conv2d(x_pad, conv_weights, strides=[1, 2, 2, 1], padding="VALID") |
| 232 | + normed = tf.compat.v1.layers.batch_normalization(conv) |
| 233 | + conv_weights2 = tf.compat.v1.get_variable("weight2", [3, 3, 16, 16], |
| 234 | + initializer=tf.compat.v1.random_normal_initializer()) |
| 235 | + conv2 = tf.nn.conv2d(top_relu, conv_weights2, strides=[1, 2, 2, 1], padding="SAME") |
| 236 | + normed2 = tf.compat.v1.layers.batch_normalization(conv2) |
| 237 | + add = tf.raw_ops.Add(x=normed, y=normed2, name='addv2') |
| 238 | + relu = tf.nn.relu(add) |
| 239 | + relu6 = tf.nn.relu6(relu, name='op_to_store') |
| 240 | + out_name = relu6.name.split(':')[0] |
| 241 | + with tf.compat.v1.Session() as sess: |
| 242 | + sess.run(tf.compat.v1.global_variables_initializer()) |
| 243 | + output_graph_def = graph_util.convert_variables_to_constants( |
| 244 | + sess=sess, |
| 245 | + input_graph_def=sess.graph_def, |
| 246 | + output_node_names=[out_name]) |
| 247 | + |
| 248 | + quantizer = Quantization('fake_yaml_2.yaml') |
| 249 | + dataset = quantizer.dataset('dummy', shape=(100, 56, 56, 16), label=True) |
| 250 | + quantizer.eval_dataloader = common.DataLoader(dataset) |
| 251 | + quantizer.calib_dataloader = common.DataLoader(dataset) |
| 252 | + quantizer.model = output_graph_def |
| 253 | + output_graph = quantizer.fit() |
| 254 | + |
| 255 | + evaluator = Benchmark('fake_yaml_2.yaml') |
| 256 | + evaluator.b_dataloader = common.DataLoader(dataset) |
| 257 | + evaluator.model = output_graph |
| 258 | + evaluator('performance') |
| 259 | + |
| 260 | + found_multi_instance_log = False |
| 261 | + for file_name in os.listdir(os.getcwd()): |
| 262 | + if file_name.endswith(".log"): |
| 263 | + found_multi_instance_log = True |
| 264 | + break |
| 265 | + |
| 266 | + self.assertEqual(found_multi_instance_log, False) |
| 267 | + |
| 268 | + |
220 | 269 | if __name__ == '__main__': |
221 | 270 | unittest.main() |
0 commit comments