예제 #1
0
    def verify_funcs_are_equivalent(self, dtype):
        x_np = np.random.uniform(-10, 10, size=(4, 4)).astype(dtype)
        x = tf.convert_to_tensor(x_np)

        with tf.GradientTape(persistent=True) as t:
            t.watch(x)
            y_native = mish(x)
            y_py = _mish_py(x)

        self.assertAllCloseAccordingToType(y_native, y_py)

        grad_native = t.gradient(y_native, x)
        grad_py = t.gradient(y_py, x)

        self.assertAllCloseAccordingToType(grad_native, grad_py)
예제 #2
0
def verify_funcs_are_equivalent(dtype):
    x_np = np.random.uniform(-10, 10, size=(4, 4)).astype(dtype)
    x = tf.convert_to_tensor(x_np)

    with tf.GradientTape(persistent=True) as t:
        t.watch(x)
        y_native = mish(x)
        y_py = _mish_py(x)

    test_utils.assert_allclose_according_to_type(y_native, y_py)

    grad_native = t.gradient(y_native, x)
    grad_py = t.gradient(y_py, x)

    test_utils.assert_allclose_according_to_type(grad_native,
                                                 grad_py,
                                                 atol=1e-5)