MCPcopy Index your code
hub / github.com/Turing-Project/WriteGPT / layer_norm

Function layer_norm

LanguageNetwork/GPT2/train/utils.py:116–127  ·  view source on GitHub ↗

Run layer normalization on the last dimension of the tensor.

(input_tensor, name=None, epsilon=1e-5)

Source from the content-addressed store, hash-verified

114
115
116def layer_norm(input_tensor, name=None, epsilon=1e-5):
117 """Run layer normalization on the last dimension of the tensor."""
118 name2use = f'LayerNorm_{name}' if name is not None else name
119 with tf.variable_scope(name2use, default_name='LayerNorm'):
120 dim = input_tensor.shape[-1].value
121 gamma = tf.get_variable('gamma', [dim], initializer=tf.constant_initializer(1))
122 beta = tf.get_variable('beta', [dim], initializer=tf.constant_initializer(0))
123 mean = tf.reduce_mean(input_tensor, axis=-1, keepdims=True)
124 std = tf.reduce_mean(tf.square(input_tensor - mean), axis=-1, keepdims=True)
125 input_tensor = (input_tensor - mean) * tf.rsqrt(std + epsilon)
126 input_tensor = input_tensor * gamma + beta
127 return input_tensor
128
129
130def dropout(input_tensor, dropout_prob):

Callers 2

residual_mlp_layerFunction · 0.90
embedFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected