MCPcopy Create free account
hub / github.com/kwuking/TimeMixer / DecoderLayer

Class DecoderLayer

layers/Autoformer_EncDec.py:140–179  ·  view source on GitHub ↗

Autoformer decoder layer with the progressive decomposition architecture

Source from the content-addressed store, hash-verified

138
139
140class DecoderLayer(nn.Module):
141 """
142 Autoformer decoder layer with the progressive decomposition architecture
143 """
144
145 def __init__(self, self_attention, cross_attention, d_model, c_out, d_ff=None,
146 moving_avg=25, dropout=0.1, activation="relu"):
147 super(DecoderLayer, self).__init__()
148 d_ff = d_ff or 4 * d_model
149 self.self_attention = self_attention
150 self.cross_attention = cross_attention
151 self.conv1 = nn.Conv1d(in_channels=d_model, out_channels=d_ff, kernel_size=1, bias=False)
152 self.conv2 = nn.Conv1d(in_channels=d_ff, out_channels=d_model, kernel_size=1, bias=False)
153 self.decomp1 = series_decomp(moving_avg)
154 self.decomp2 = series_decomp(moving_avg)
155 self.decomp3 = series_decomp(moving_avg)
156 self.dropout = nn.Dropout(dropout)
157 self.projection = nn.Conv1d(in_channels=d_model, out_channels=c_out, kernel_size=3, stride=1, padding=1,
158 padding_mode='circular', bias=False)
159 self.activation = F.relu if activation == "relu" else F.gelu
160
161 def forward(self, x, cross, x_mask=None, cross_mask=None):
162 x = x + self.dropout(self.self_attention(
163 x, x, x,
164 attn_mask=x_mask
165 )[0])
166 x, trend1 = self.decomp1(x)
167 x = x + self.dropout(self.cross_attention(
168 x, cross, cross,
169 attn_mask=cross_mask
170 )[0])
171 x, trend2 = self.decomp2(x)
172 y = x
173 y = self.dropout(self.activation(self.conv1(y.transpose(-1, 1))))
174 y = self.dropout(self.conv2(y).transpose(-1, 1))
175 x, trend3 = self.decomp3(x + y)
176
177 residual_trend = trend1 + trend2 + trend3
178 residual_trend = self.projection(residual_trend.permute(0, 2, 1)).transpose(1, 2)
179 return x, residual_trend
180
181
182class Decoder(nn.Module):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected