MCPcopy Create free account
hub / github.com/KimMeen/Time-LLM / DecoderLayer

Class DecoderLayer

layers/Transformer_EncDec.py:83–116  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

81
82
83class DecoderLayer(nn.Module):
84 def __init__(self, self_attention, cross_attention, d_model, d_ff=None,
85 dropout=0.1, activation="relu"):
86 super(DecoderLayer, self).__init__()
87 d_ff = d_ff or 4 * d_model
88 self.self_attention = self_attention
89 self.cross_attention = cross_attention
90 self.conv1 = nn.Conv1d(in_channels=d_model, out_channels=d_ff, kernel_size=1)
91 self.conv2 = nn.Conv1d(in_channels=d_ff, out_channels=d_model, kernel_size=1)
92 self.norm1 = nn.LayerNorm(d_model)
93 self.norm2 = nn.LayerNorm(d_model)
94 self.norm3 = nn.LayerNorm(d_model)
95 self.dropout = nn.Dropout(dropout)
96 self.activation = F.relu if activation == "relu" else F.gelu
97
98 def forward(self, x, cross, x_mask=None, cross_mask=None, tau=None, delta=None):
99 x = x + self.dropout(self.self_attention(
100 x, x, x,
101 attn_mask=x_mask,
102 tau=tau, delta=None
103 )[0])
104 x = self.norm1(x)
105
106 x = x + self.dropout(self.cross_attention(
107 x, cross, cross,
108 attn_mask=cross_mask,
109 tau=tau, delta=delta
110 )[0])
111
112 y = x = self.norm2(x)
113 y = self.dropout(self.activation(self.conv1(y.transpose(-1, 1))))
114 y = self.dropout(self.conv2(y).transpose(-1, 1))
115
116 return self.norm3(x + y)
117
118
119class Decoder(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected