MCPcopy Create free account
hub / github.com/BorealisAI/scaleformer / Encoder

Class Encoder

layers/Transformer_EncDec.py:74–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72
73
74class Encoder(nn.Module):
75 def __init__(self, attn_layers, conv_layers=None, norm_layer=None):
76 super(Encoder, self).__init__()
77 self.attn_layers = nn.ModuleList(attn_layers)
78 self.conv_layers = nn.ModuleList(conv_layers) if conv_layers is not None else None
79 self.norm = norm_layer
80
81 def forward(self, x, attn_mask=None):
82 # x [B, L, D]
83 attns = []
84 if self.conv_layers is not None:
85 for attn_layer, conv_layer in zip(self.attn_layers, self.conv_layers):
86 x, attn = attn_layer(x, attn_mask=attn_mask)
87 x = conv_layer(x)
88 attns.append(attn)
89 x, attn = self.attn_layers[-1](x)
90 attns.append(attn)
91 else:
92 for attn_layer in self.attn_layers:
93 x, attn = attn_layer(x, attn_mask=attn_mask)
94 attns.append(attn)
95
96 if self.norm is not None:
97 x = self.norm(x)
98
99 return x, attns
100
101
102class DecoderLayer(nn.Module):

Callers 7

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected