def __init__(self, model_dim, nheads, ff_dim, num_layers, dropout=0.1, mem_att_dropout=0.1, mem_att=True, mem_dim=None, prop_dim=None): super(TransformerStack, self).__init__() layer = TransformerDecoderLayer(model_dim=model_dim, nheads=nheads, ff_dim=ff_dim, dropout=dropout, mem_att=mem_att, mem_dim=mem_dim, mem_att_dropout=mem_att_dropout) self.layers = _get_clones(layer, num_layers) self.num_layers = num_layers self.norm = LayerNorm(model_dim) self.tgt_mask = None self.prop_dim = prop_dim if prop_dim is not None and prop_dim > 0 else None if self.prop_dim is not None: self.inp_proj = Sequential() self.inp_proj.add_module( "lin", Linear(model_dim + self.prop_dim, model_dim))
def __init__(self, d_model, N, heads, height, width, device): super().__init__() self.N = N self.pe = LearnedPositionalEncoder(d_model, height, width, device) self.layers = transformer._get_clones( transformer.TransformerEncoderLayer(d_model, heads, dim_feedforward=d_model), N, )
def __init__(self, decoder_layer, decoder_final_layer, num_layers, norm=None): super(TransformerDecoder, self).__init__() self.layers = _get_clones(decoder_layer, num_layers - 1) self.final_layer = decoder_final_layer self.num_layers = num_layers self.norm = norm
def __init__(self, decoder_layer, num_layers, norm=None): super(TransformerDecoderCustom, self).__init__() self.layers = _get_clones(decoder_layer, num_layers) self.num_layers = num_layers self.norm = norm
def __init__(self, encoder_layer, num_layers, norm=None): super(TransformerEncoder, self).__init__() self.layers = _get_clones(encoder_layer, num_layers) self.num_layers = num_layers self.norm = norm
def __init__(self, decoder_layer, num_layers, norm=None): super().__init__() self.layers = _get_clones(decoder_layer, num_layers) self.num_layers = num_layers self.norm = norm