(self,
vocab,
dim,
dim_attn,
dim_ffn,
num_heads,
num_layers,
num_buckets,
shared_pos=True,
dropout=0.1)
| 255 | |
| 256 | class WanT5EncoderModel(ModelMixin, ConfigMixin, FromOriginalModelMixin): |
| 257 | def __init__(self, |
| 258 | vocab, |
| 259 | dim, |
| 260 | dim_attn, |
| 261 | dim_ffn, |
| 262 | num_heads, |
| 263 | num_layers, |
| 264 | num_buckets, |
| 265 | shared_pos=True, |
| 266 | dropout=0.1): |
| 267 | super(WanT5EncoderModel, self).__init__() |
| 268 | self.dim = dim |
| 269 | self.dim_attn = dim_attn |
| 270 | self.dim_ffn = dim_ffn |
| 271 | self.num_heads = num_heads |
| 272 | self.num_layers = num_layers |
| 273 | self.num_buckets = num_buckets |
| 274 | self.shared_pos = shared_pos |
| 275 | |
| 276 | # layers |
| 277 | self.token_embedding = vocab if isinstance(vocab, nn.Embedding) \ |
| 278 | else nn.Embedding(vocab, dim) |
| 279 | self.pos_embedding = T5RelativeEmbedding( |
| 280 | num_buckets, num_heads, bidirectional=True) if shared_pos else None |
| 281 | self.dropout = nn.Dropout(dropout) |
| 282 | self.blocks = nn.ModuleList([ |
| 283 | T5SelfAttention(dim, dim_attn, dim_ffn, num_heads, num_buckets, |
| 284 | shared_pos, dropout) for _ in range(num_layers) |
| 285 | ]) |
| 286 | self.norm = T5LayerNorm(dim) |
| 287 | |
| 288 | # initialize weights |
| 289 | self.apply(init_weights) |
| 290 | |
| 291 | def forward( |
| 292 | self, |
nothing calls this directly
no test coverage detected