示例#1
0
    def testBatchNormalizeFused(self):
        with self.session() as sess:
            a = array_ops.placeholder(np.float32, [4, 64, 64, 4],
                                      name="input_a")

            def my_graph(a):
                with ops.device("/device:IPU:0"):
                    with variable_scope.variable_scope("", use_resource=True):

                        beta = variable_scope.get_variable(
                            "x",
                            dtype=np.float32,
                            shape=[4],
                            initializer=init_ops.constant_initializer(0.0))
                        gamma = variable_scope.get_variable(
                            "y",
                            dtype=np.float32,
                            shape=[4],
                            initializer=init_ops.constant_initializer(1.0))

                        b_mean, b_var = nn.moments(a, [0, 1, 2],
                                                   name='moments')

                        normed = nn.fused_batch_norm(a,
                                                     gamma,
                                                     beta,
                                                     b_mean,
                                                     b_var,
                                                     is_training=False)
                        return normed

            report = ReportJSON(self, sess)
            out = ipu.ipu_compiler.compile(my_graph, [a])
            sess.run(variables.global_variables_initializer())

            report.reset()
            result, _, _ = sess.run(out, {a: np.zeros([4, 64, 64, 4])})
            self.assertAllClose(result, np.zeros([4, 64, 64, 4]))
            report.parse_log()

            bl = ['*convert*/Cast*']
            report.assert_compute_sets_not_in_blacklist(bl)

            report.assert_tensor_input_names("input_a", "x", "y")
示例#2
0
    def testBatchNormalizeLayerFusedFp16(self):
        with self.session() as sess:
            with ops.device("/device:IPU:0"):
                with variable_scope.variable_scope("", use_resource=True):
                    a = array_ops.placeholder(np.float16, [4, 64, 64, 4],
                                              name="input_a")

                    normed = layers_norm.batch_normalization(a, fused=True)

            report = ReportJSON(self, sess)
            sess.run(variables.global_variables_initializer())

            report.reset()
            result = sess.run(normed, {a: np.zeros([4, 64, 64, 4])})
            self.assertAllClose(result, np.zeros([4, 64, 64, 4]))

            report.parse_log()

            bl = ['*convert*/Cast*']
            report.assert_compute_sets_not_in_blacklist(bl)
            report.assert_tensor_input_names("input_a")