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

Class PositionalEncoding

models/transformer/wan/modules/t2m_model.py:493–511  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

491 return clip_extra_context_tokens
492
493class PositionalEncoding(nn.Module):
494 def __init__(self, d_model, max_len=5000):
495 super(PositionalEncoding, self).__init__()
496
497 pe = torch.zeros(max_len, d_model)
498 position = torch.arange(0, max_len, dtype=torch.float).unsqueeze(1)
499 div_term = torch.exp(torch.arange(0, d_model, 2).float() * (-np.log(10000.0) / d_model))
500 pe[:, 0::2] = torch.sin(position * div_term)
501 pe[:, 1::2] = torch.cos(position * div_term)
502 pe = pe.unsqueeze(0).transpose(0, 1)
503
504 self.register_buffer('pe', pe)
505
506 def forward(self, x):
507 # x: [B, T, C]
508 x = x.permute(1, 0, 2)
509 x = x + self.pe[:x.size(0), :]
510 x = x.permute(1, 0, 2)
511 return x
512
513class WanModelT2M(nn.Module):
514

Callers 1

__init__Method · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected