Beispiel #1
0
    def test_gelu_10(self):
        x = tf.constant([-100, -1.0, -0.1, 0, 0.1, 1.0, 100.0])
        gelu = get_tf_activation("gelu")
        gelu10 = get_tf_activation("gelu_10")

        y_gelu = gelu(x)
        y_gelu_10 = gelu10(x)

        clipped_mask = tf.where(y_gelu_10 < 10.0, 1.0, 0.0)

        self.assertEqual(tf.math.reduce_max(y_gelu_10).numpy().item(), 10.0)
        self.assertTrue(
            np.allclose(y_gelu * clipped_mask, y_gelu_10 * clipped_mask))
Beispiel #2
0
    def __init__(self, in_dim, dim_hidden, out_dim, config, **kwargs):
        super().__init__(**kwargs)

        self.lin1 = tf.keras.layers.Dense(dim_hidden,
                                          kernel_initializer=get_initializer(
                                              config.init_std),
                                          name="lin1")
        self.lin2 = tf.keras.layers.Dense(out_dim,
                                          kernel_initializer=get_initializer(
                                              config.init_std),
                                          name="lin2")
        self.act = get_tf_activation(
            "gelu") if config.gelu_activation else get_tf_activation("relu")
        self.dropout = tf.keras.layers.Dropout(config.dropout)
Beispiel #3
0
 def test_get_activation(self):
     get_tf_activation("gelu")
     get_tf_activation("gelu_10")
     get_tf_activation("gelu_fast")
     get_tf_activation("gelu_new")
     get_tf_activation("glu")
     get_tf_activation("mish")
     get_tf_activation("quick_gelu")
     get_tf_activation("relu")
     get_tf_activation("sigmoid")
     get_tf_activation("silu")
     get_tf_activation("swish")
     get_tf_activation("tanh")
     with self.assertRaises(KeyError):
         get_tf_activation("bogus")
     with self.assertRaises(KeyError):
         get_tf_activation(None)