MCPcopy Create free account
hub / github.com/THUDM/GLM / BertLayerNorm

Class BertLayerNorm

model/modeling_bert.py:271–284  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

269
270
271 class BertLayerNorm(nn.Module):
272 def __init__(self, hidden_size, eps=1e-12):
273 """Construct a layernorm module in the TF style (epsilon inside the square root).
274 """
275 super(BertLayerNorm, self).__init__()
276 self.weight = nn.Parameter(torch.ones(hidden_size))
277 self.bias = nn.Parameter(torch.zeros(hidden_size))
278 self.variance_epsilon = eps
279
280 def forward(self, x):
281 u = x.mean(-1, keepdim=True)
282 s = (x - u).pow(2).mean(-1, keepdim=True)
283 x = (x - u) / torch.sqrt(s + self.variance_epsilon)
284 return self.weight * x + self.bias
285
286
287class BertEmbeddings(nn.Module):

Callers 4

__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85
__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected