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

Class Encoder

layers/Transformer_EncDec.py:54–80  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected