MCPcopy Create free account
hub / github.com/MotrixLab/ViMoGen / T5Encoder

Class T5Encoder

models/transformer/wan/modules/t5.py:267–312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

265
266
267class T5Encoder(nn.Module):
268
269 def __init__(self,
270 vocab,
271 dim,
272 dim_attn,
273 dim_ffn,
274 num_heads,
275 num_layers,
276 num_buckets,
277 shared_pos=True,
278 dropout=0.1):
279 super(T5Encoder, self).__init__()
280 self.dim = dim
281 self.dim_attn = dim_attn
282 self.dim_ffn = dim_ffn
283 self.num_heads = num_heads
284 self.num_layers = num_layers
285 self.num_buckets = num_buckets
286 self.shared_pos = shared_pos
287
288 # layers
289 self.token_embedding = vocab if isinstance(vocab, nn.Embedding) \
290 else nn.Embedding(vocab, dim)
291 self.pos_embedding = T5RelativeEmbedding(
292 num_buckets, num_heads, bidirectional=True) if shared_pos else None
293 self.dropout = nn.Dropout(dropout)
294 self.blocks = nn.ModuleList([
295 T5SelfAttention(dim, dim_attn, dim_ffn, num_heads, num_buckets,
296 shared_pos, dropout) for _ in range(num_layers)
297 ])
298 self.norm = T5LayerNorm(dim)
299
300 # initialize weights
301 self.apply(init_weights)
302
303 def forward(self, ids, mask=None):
304 x = self.token_embedding(ids)
305 x = self.dropout(x)
306 e = self.pos_embedding(x.size(1),
307 x.size(1)) if self.shared_pos else None
308 for block in self.blocks:
309 x = block(x, mask, pos_bias=e)
310 x = self.norm(x)
311 x = self.dropout(x)
312 return x
313
314
315class T5Decoder(nn.Module):

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected