Add Conv + BiasAdd + Elu fusion UT
@@ -296,6 +296,38 @@ class TestConvRequantizedFusionNewAPI(unittest.TestCase):
break
self.assertEqual(found_conv_fusion, True)
+ @disable_random()
+ def test_conv2d_biasadd_elu_fusion(self):
+ input = tf.compat.v1.placeholder(tf.float32, shape=(1,3,3,1), name='input')
+ weight = tf.compat.v1.constant(np.random.random((2,2,1,1)).astype(np.float32), name='weight')
+ bias = tf.constant(np.random.random((1)), name='bias', dtype = tf.float32)
+ conv = tf.nn.conv2d(input=input, filters=weight, strides=[1,1,1,1], padding='VALID', name='conv')
+ bias_add = tf.nn.bias_add(conv, bias, name = 'bias_add')
+ res = tf.nn.elu(bias_add, name = 'res')
+ output = tf.nn.softmax(res, name = 'op_to_store')
+
+ out_name = output.name.split(':')[0]
+ with tf.compat.v1.Session() as sess:
+ sess.run(tf.compat.v1.global_variables_initializer())
+ output_graph_def = graph_util.convert_variables_to_constants(
+ sess=sess,
+ input_graph_def=sess.graph_def,
+ output_node_names=[out_name])
+ from neural_compressor.experimental import Quantization, common
+ quantizer = Quantization('inteltensorflow_yaml.yaml')
+ dataset = quantizer.dataset('dummy', shape=(100, 3, 3, 1), label=True)
+ quantizer.eval_dataloader = common.DataLoader(dataset)
+ quantizer.calib_dataloader = common.DataLoader(dataset)
+ quantizer.model = output_graph_def
+ output_graph = quantizer.fit()
+ self.assertNotEqual(output_graph, None)
+ elu_fused = False
+ for node in output_graph.graph_def.node:
+ if node.name == 'conv_eightbit_requantize':
+ if b'Elu' in node.attr['fused_ops'].list.s:
+ elu_fused = True
+ self.assertEqual(elu_fused, True)
+
@disable_random()
def test_conv3d_add_const_fusion(self):
x = tf.compat.v1.placeholder(tf.float32, [1,64,64,64,1], name="input")
