def forward(self, x, encoder_padding_mask):
    '\n        Args:\n            x (Tensor): input to the layer of shape `(seq_len, batch, embed_dim)`\n            encoder_padding_mask (ByteTensor): binary ByteTensor of shape\n                `(batch, src_len)` where padding elements are indicated by ``1``.\n\n        Returns:\n            encoded output of shape `(batch, src_len, embed_dim)`\n        '
    residual = x
    x = self.maybe_layer_norm(self.self_attn_layer_norm, x, before=True)
    (x, attn_weight) = self.self_attn(query=x, key=x, value=x, key_padding_mask=encoder_padding_mask)
    x = F.dropout(x, p=self.dropout, training=self.training)
    x = (residual + x)
    x = self.maybe_layer_norm(self.self_attn_layer_norm, x, after=True)
    self.attn_weight = attn_weight
    residual = x
    x = self.maybe_layer_norm(self.final_layer_norm, x, before=True)
    x = self.activation_fn(self.fc1(x))
    x = F.dropout(x, p=self.activation_dropout, training=self.training)
    x = self.fc2(x)
    x = F.dropout(x, p=self.dropout, training=self.training)
    x = (residual + x)
    x = self.maybe_layer_norm(self.final_layer_norm, x, after=True)
    return x
Args:
    x (Tensor): input to the layer of shape `(seq_len, batch, embed_dim)`
    encoder_padding_mask (ByteTensor): binary ByteTensor of shape
        `(batch, src_len)` where padding elements are indicated by ``1``.

Returns:
    encoded output of shape `(batch, src_len, embed_dim)`
def forward(self, x, encoder_padding_mask):
    '\n        Args:\n            x (Tensor): input to the layer of shape `(seq_len, batch, embed_dim)`\n            encoder_padding_mask (ByteTensor): binary ByteTensor of shape\n                `(batch, src_len)` where padding elements are indicated by ``1``.\n\n        Returns:\n            encoded output of shape `(batch, src_len, embed_dim)`\n        '
    residual = x
    x = self.maybe_layer_norm(self.self_attn_layer_norm, x, before=True)
    (x, attn_weight) = self.self_attn(query=x, key=x, value=x, key_padding_mask=encoder_padding_mask)
    x = F.dropout(x, p=self.dropout, training=self.training)
    x = (residual + x)
    x = self.maybe_layer_norm(self.self_attn_layer_norm, x, after=True)
    self.attn_weight = attn_weight
    residual = x
    x = self.maybe_layer_norm(self.final_layer_norm, x, before=True)
    x = self.activation_fn(self.fc1(x))
    x = F.dropout(x, p=self.activation_dropout, training=self.training)
    x = self.fc2(x)
    x = F.dropout(x, p=self.dropout, training=self.training)
    x = (residual + x)
    x = self.maybe_layer_norm(self.final_layer_norm, x, after=True)
    return x