3
$\begingroup$

Currently the transformer blocks are of this structure (ignore all norm's, masks, dropout ...):

x
y1 = x  + attention(x)
y2 = y1 + linear(y1)

Why not adding to x one change, not two different ?

x
y1 = x  + attention(x)
y2 = x + linear(y1)

not seen this alternative.

Is it obvious that is bad ?

$\endgroup$
1
  • $\begingroup$ my proposition : x + linear(x+attention(x)) $\endgroup$ Commented Aug 10 at 16:19

1 Answer 1

4
$\begingroup$

The transformer's consistent use of residual connections helps maintain the flow of information and gradients throughout the network which is crucial for training deep models. By always adding the output of a sub-layer back to its input the network can learn to refine its representations layer by layer without losing the original input information.

Your proposed structure modifies this pattern by adding the result of the feed-forward network directly to the original input rather than the output of the attention layer. This breaks the consistency seen in traditional transformers because it bypasses the residual connection's typical role of accumulating modifications in a sequential manner. Instead it resets the baseline to the original input before applying the feed-forward output which disrupts gradients flow through the network during backpropagation possibly making optimization more difficult or unstable.

Of course this isn't necessarily to prevent you from exploring this alternative structure empirically with some experiments to see how it impacts training stability and model performance. This might require different tuning to be effective and could potentially learn different kinds of representations if successful.

$\endgroup$
4
  • $\begingroup$ is this chat gpt ? Because I don't see why my alternative is good or bad $\endgroup$ Commented Aug 10 at 16:27
  • $\begingroup$ Is there any specific confusion you have about my answer? If it doesn't help which is normally distributed roughly on this site across all answers, you can wait for other answers if there will be. $\endgroup$
    – cinch
    Commented Aug 10 at 16:41
  • $\begingroup$ I don't see where you compare my two versions of the code. What is better really ? $\endgroup$ Commented Aug 11 at 7:09
  • $\begingroup$ My first paragraph is for the transformer version, my 2nd paragraph starting from 'Your proposed structure modifies this pattern by adding the result of the feed-forward network directly to the original input rather than the output of the attention layer' is analyzing your own version. I don't sincerely believe this is not comparison as evidenced by some upvotes for my answer in a Bayesian fashion. $\endgroup$
    – cinch
    Commented Aug 11 at 7:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.