MCPcopy Create free account
hub / github.com/cure-lab/LTSF-Linear / Encoder

Class Encoder

layers/Transformer_EncDec.py:53–78  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51
52
53class Encoder(nn.Module):
54 def __init__(self, attn_layers, conv_layers=None, norm_layer=None):
55 super(Encoder, self).__init__()
56 self.attn_layers = nn.ModuleList(attn_layers)
57 self.conv_layers = nn.ModuleList(conv_layers) if conv_layers is not None else None
58 self.norm = norm_layer
59
60 def forward(self, x, attn_mask=None):
61 # x [B, L, D]
62 attns = []
63 if self.conv_layers is not None:
64 for attn_layer, conv_layer in zip(self.attn_layers, self.conv_layers):
65 x, attn = attn_layer(x, attn_mask=attn_mask)
66 x = conv_layer(x)
67 attns.append(attn)
68 x, attn = self.attn_layers[-1](x)
69 attns.append(attn)
70 else:
71 for attn_layer in self.attn_layers:
72 x, attn = attn_layer(x, attn_mask=attn_mask)
73 attns.append(attn)
74
75 if self.norm is not None:
76 x = self.norm(x)
77
78 return x, attns
79
80
81class DecoderLayer(nn.Module):

Callers 2

__init__Method · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected