MCPcopy Create free account
hub / github.com/Anoise/WTFlib / EncoderLayer

Class EncoderLayer

LDPS_Graph/layers/Autoformer_EncDec.py:72–98  ·  view source on GitHub ↗

Autoformer encoder layer with the progressive decomposition architecture

Source from the content-addressed store, hash-verified

70
71
72class EncoderLayer(nn.Module):
73 """
74 Autoformer encoder layer with the progressive decomposition architecture
75 """
76 def __init__(self, attention, d_model, d_ff=None, moving_avg=25, dropout=0.1, activation="relu"):
77 super(EncoderLayer, self).__init__()
78 d_ff = d_ff or 4 * d_model
79 self.attention = attention
80 self.conv1 = nn.Conv1d(in_channels=d_model, out_channels=d_ff, kernel_size=1, bias=False)
81 self.conv2 = nn.Conv1d(in_channels=d_ff, out_channels=d_model, kernel_size=1, bias=False)
82 self.decomp1 = series_decomp(moving_avg)
83 self.decomp2 = series_decomp(moving_avg)
84 self.dropout = nn.Dropout(dropout)
85 self.activation = F.relu if activation == "relu" else F.gelu
86
87 def forward(self, x, attn_mask=None):
88 new_x, attn = self.attention(
89 x, x, x,
90 attn_mask=attn_mask
91 )
92 x = x + self.dropout(new_x)
93 x, _ = self.decomp1(x)
94 y = x
95 y = self.dropout(self.activation(self.conv1(y.transpose(-1, 1))))
96 y = self.dropout(self.conv2(y).transpose(-1, 1))
97 res, _ = self.decomp2(x + y)
98 return res, attn
99
100
101class Encoder(nn.Module):

Callers 3

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected