def __init__(self, args, dictionary, embed_tokens):
    super().__init__(dictionary)
    self.register_buffer('version', torch.Tensor([3]))
    self.dropout = args.dropout
    embed_dim = embed_tokens.embedding_dim
    self.padding_idx = embed_tokens.padding_idx
    self.max_source_positions = args.max_source_positions
    self.embed_tokens = embed_tokens
    self.embed_scale = math.sqrt(embed_dim)
    self.embed_positions = (PositionalEmbedding(args.max_source_positions, embed_dim, self.padding_idx, learned=args.encoder_learned_pos) if (not args.no_token_positional_embeddings) else None)
    self.layers = nn.ModuleList([])
    self.layers.extend([TransformerEncoderLayer(args) for i in range(args.encoder_layers)])
    if args.encoder_normalize_before:
        self.layer_norm = LayerNorm(embed_dim)
    else:
        self.layer_norm = None
def __init__(self, args, dictionary, embed_tokens):
    super().__init__(dictionary)
    self.register_buffer('version', torch.Tensor([3]))
    self.dropout = args.dropout
    embed_dim = embed_tokens.embedding_dim
    self.padding_idx = embed_tokens.padding_idx
    self.max_source_positions = args.max_source_positions
    self.embed_tokens = embed_tokens
    self.embed_scale = math.sqrt(embed_dim)
    self.embed_positions = (PositionalEmbedding(args.max_source_positions, embed_dim, self.padding_idx, learned=args.encoder_learned_pos) if (not args.no_token_positional_embeddings) else None)
    self.layers = nn.ModuleList([])
    self.layers.extend([TransformerEncoderLayer(args) for i in range(args.encoder_layers)])
    if args.encoder_normalize_before:
        self.layer_norm = LayerNorm(embed_dim)
    else:
        self.layer_norm = None