MCPcopy Create free account
hub / github.com/Little-Podi/AdaWorld / __init__

Method __init__

lam/lam/modules/blocks.py:27–35  ·  view source on GitHub ↗
(self, model_dim: int, max_len: int = 5000)

Source from the content-addressed store, hash-verified

25
26class PositionalEncoding(nn.Module):
27 def __init__(self, model_dim: int, max_len: int = 5000) -> None:
28 super(PositionalEncoding, self).__init__()
29 pe = torch.zeros(max_len, model_dim)
30 position = torch.arange(0, max_len).float().unsqueeze(1)
31 exponent = torch.arange(0, model_dim, 2).float() * -(math.log(10000.0) / model_dim)
32 div_term = torch.exp(exponent)
33 pe[:, 0::2] = torch.sin(position * div_term)
34 pe[:, 1::2] = torch.cos(position * div_term)
35 self.pos_enc = pe
36
37 def forward(self, x: Tensor) -> Tensor:
38 return x + self.pos_enc[:x.shape[2]].cuda()

Callers

nothing calls this directly

Calls 1

__init__Method · 0.45

Tested by

no test coverage detected