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

Method __init__

layers/Embed.py:71–84  ·  view source on GitHub ↗
(self, c_in, d_model)

Source from the content-addressed store, hash-verified

69
70class FixedEmbedding(nn.Module):
71 def __init__(self, c_in, d_model):
72 super(FixedEmbedding, self).__init__()
73
74 w = torch.zeros(c_in, d_model).float()
75 w.require_grad = False
76
77 position = torch.arange(0, c_in).float().unsqueeze(1)
78 div_term = (torch.arange(0, d_model, 2).float() * -(math.log(10000.0) / d_model)).exp()
79
80 w[:, 0::2] = torch.sin(position * div_term)
81 w[:, 1::2] = torch.cos(position * div_term)
82
83 self.emb = nn.Embedding(c_in, d_model)
84 self.emb.weight = nn.Parameter(w, requires_grad=False)
85
86 def forward(self, x):
87 return self.emb(x).detach()

Callers

nothing calls this directly

Calls 1

__init__Method · 0.45

Tested by

no test coverage detected