MCPcopy Create free account
hub / github.com/dome272/Diffusion-Models-pytorch / pos_encoding

Method pos_encoding

modules.py:217–225  ·  view source on GitHub ↗
(self, t, channels)

Source from the content-addressed store, hash-verified

215 self.label_emb = nn.Embedding(num_classes, time_dim)
216
217 def pos_encoding(self, t, channels):
218 inv_freq = 1.0 / (
219 10000
220 ** (torch.arange(0, channels, 2, device=self.device).float() / channels)
221 )
222 pos_enc_a = torch.sin(t.repeat(1, channels // 2) * inv_freq)
223 pos_enc_b = torch.cos(t.repeat(1, channels // 2) * inv_freq)
224 pos_enc = torch.cat([pos_enc_a, pos_enc_b], dim=-1)
225 return pos_enc
226
227 def forward(self, x, t, y):
228 t = t.unsqueeze(-1).type(torch.float)

Callers 1

forwardMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected