Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is there any reason we used a different LayerNorm implementation? #122

Open
dpheap2222 opened this issue Apr 3, 2024 · 1 comment
Open

Comments

@dpheap2222
Copy link

We have a custom defined LayerNorm

class LayerNorm(nn.Module):
"Construct a layernorm module (See citation for details)."
def __init__(self, features, eps=1e-6):
super(LayerNorm, self).__init__()
self.a_2 = nn.Parameter(torch.ones(features))
self.b_2 = nn.Parameter(torch.zeros(features))
self.eps = eps
def forward(self, x):
mean = x.mean(-1, keepdim=True)
std = x.std(-1, keepdim=True)
return self.a_2 * (x - mean) / (std + self.eps) + self.b_2

From the look of line 326, there is no specification of 'correction=0'. By default, this means 'correction=1', which applies a Bessel’s correction. Had we removed this correction, we could easily implement with PyTorch's native LayerNorm class. Is there any reason we opted for the custom route? Thank you.

@kuraga
Copy link

kuraga commented Sep 14, 2024

Because everything is from scratch here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants