Add&Norm layer is missing after each attention layer
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 1.3k
- Forks
- 379
- Avg merge
- 3h 30m
- Merged PRs (30d)
- 8
Description
Hi,
According to the transformer architecture, there should be a add&norm layer after each attention layer. However for code in /docs/tutorials/transformer.ipynb, those Add&Norm layers are missing.

Take decoder layer for example, the original code is:
def call(self, x, context):
x = self.causal_self_attention(x=x)
x = self.cross_attention(x=x, context=context)
\# Cache the last attention scores for plotting later
self.last_attn_scores = self.cross_attention.last_attn_scores
x = self.ffn(x) # Shape `(batch_size, seq_len, d_model)`.
return x
If we add Add&Norm layers, it should be:
def call(self, x, context):
x = self.add([x, self.causal_self_attention(x=x)])
x = self.layer_norm1(x)
x = self.add([x, self.cross_attention(x=x, context=context)])
x = self.layer_norm2(x)
\# Cache the last attention scores for plotting later
self.last_attn_scores = self.cross_attention.last_attn_scores
x = self.ffn(x) # Shape `(batch_size, seq_len, d_model)`.
return x
I wonder if those add&norm layers are ignored on purpose.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Open /docs/tutorials/transformer.ipynb and inspect the encoder and decoder layer call methods around the attention operations. Compare the tutorial with the transformer architecture shown in the issue and determine whether the missing Add&Norm steps are intentional. Done means the tutorial reflects the intended architecture and the notebook still runs successfully.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation, machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100