Skip to content

Question about why the add&norm structure of the tranformer network differ from the typical transformer one #24

Open

Description

@Liaoqing-up

if pos_embedding is not None:
x_att = self_attn(x + center_pos_embedding)
x = x_att + x
x_att = cross_attn(
x + center_pos_embedding, y + neighbor_pos_embedding
)
else:
x_att = self_attn(x)
x = x_att + x
x_att = cross_attn(x, y)
x = x_att + x
x = ff(x) + x

In the code, the residual in transformer is only the input after add and does not pass through the norm layer. add and norm are not taken as a whole, which is different from the typical transformer structure (the result of add and norm in series as a new level of input). Is there any special consideration for the design here?

Activity

  1. edwardzhou130 commented on Feb 19, 2023

    @edwardzhou130
    Collaborator

    I used prenorm inside each layer.

    PreNorm(
    dim,
    Attention(
    dim,
    heads=heads,
    dim_head=dim_head,
    dropout=dropout,
    out_attention=self.out_attention,
    ),
    ),
    PreNorm_CA(
    dim,
    Cross_attention(
    dim,
    heads=heads,
    dim_head=dim_head,
    dropout=dropout,
    out_attention=self.out_attention,
    ),
    ),
    PreNorm(dim, FeedForward(dim, mlp_dim, dropout=dropout)),

  2. Liaoqing-up commented on Feb 20, 2023

    @Liaoqing-up
    Author

    I used prenorm inside each layer.

    PreNorm(
    dim,
    Attention(
    dim,
    heads=heads,
    dim_head=dim_head,
    dropout=dropout,
    out_attention=self.out_attention,
    ),
    ),
    PreNorm_CA(
    dim,
    Cross_attention(
    dim,
    heads=heads,
    dim_head=dim_head,
    dropout=dropout,
    out_attention=self.out_attention,
    ),
    ),
    PreNorm(dim, FeedForward(dim, mlp_dim, dropout=dropout)),

    I see, but I wonder if you have tried Add&Norm after each layer, which means the residual skip connect input are the features already passed through the Norm. Is it possible that the results of these two structures do not differ much?

  3. edwardzhou130 commented on Feb 22, 2023

    @edwardzhou130
    Collaborator

    Sorry, I haven't tried Add&Norm after each layer. Do you have experience with this before and would the results be better if you used this implementation?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions