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

Curious Question: Is LayerNorm in the wrong position or is that deliberate? #33

Closed
turner-rovco opened this issue Aug 26, 2020 · 2 comments

Comments

@turner-rovco
Copy link

turner-rovco commented Aug 26, 2020

Code:

def forward(self, x):
x = x + self.attn(self.ln1(x))
x = x + self.mlp(self.ln2(x))
return x

Paper says: Output of each sub-layer is LayerNorm(x + Sublayer(x))

I changed the code to the following and the results seem (slightly) better on play_char, albeit it's a qualitative assessment...

def forward(self, x):
x = self.ln1(x + self.attn(x))
x = self.ln2(x + self.feed_forward(x))
return x

@fpgaminer
Copy link
Contributor

GPT-2 changed it:

Layer normalization (Ba et al., 2016) was moved to the input of each sub-block, similar to a pre-activation residual network (He et al., 2016) and an additional layer normalization was added after the final self-attention block.

Source: https://cdn.openai.com/better-language-models/language_models_are_unsupervised_multitask_learners.pdf

(NOTE: I'm not the repo owner, just trying to help)

@turner-rovco
Copy link
Author

Ah perfect, thanks!

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