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

Method pos_encoding

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

Source from the content-addressed store, hash-verified

151 self.outc = nn.Conv2d(64, c_out, kernel_size=1)
152
153 def pos_encoding(self, t, channels):
154 inv_freq = 1.0 / (
155 10000
156 ** (torch.arange(0, channels, 2, device=self.device).float() / channels)
157 )
158 pos_enc_a = torch.sin(t.repeat(1, channels // 2) * inv_freq)
159 pos_enc_b = torch.cos(t.repeat(1, channels // 2) * inv_freq)
160 pos_enc = torch.cat([pos_enc_a, pos_enc_b], dim=-1)
161 return pos_enc
162
163 def forward(self, x, t):
164 t = t.unsqueeze(-1).type(torch.float)

Callers 1

forwardMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected